Skip to content

Commit

Permalink
feat: add keybinding to settings file
Browse files Browse the repository at this point in the history
  • Loading branch information
vipzhicheng committed Feb 15, 2022
1 parent 1f4271b commit b02b73e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
25 changes: 15 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# CHANGELOG

## 0.1.5

* fix: remove shortcut `m m` but keep `ctrl+m ctrl+m`.
* feat: make the shortcut configurable.

## 0.1.4

feat: support open page or block markmap in markmap.
feat: support trigger backward on markmap.
feat: support block page markmap trigger by shortcut.
feat: add `cmd+[` and `cmd+]` shortcuts on markmap to traverse.
* feat: support open page or block markmap in markmap.
* feat: support trigger backward on markmap.
* feat: support block page markmap trigger by shortcut.
* feat: add `cmd+[` and `cmd+]` shortcuts on markmap to traverse.

## 0.1.3

feat: `m m`, Trigger Markmap for non-editing mode.
feat: `ctrl+m ctrl+m`, Trigger Markmap for editing mode.
feat: `Markmap` slash command.
feat: `Markmap` contextual menu.
feat: Editing block or highlighting block will be the central node of the Markmap, otherwise it will use the whole page blocks.
fix: Local images can not popup after changing graph.
* feat: `m m`, Trigger Markmap for non-editing mode.
* feat: `ctrl+m ctrl+m`, Trigger Markmap for editing mode.
* feat: `Markmap` slash command.
* feat: `Markmap` contextual menu.
* feat: Editing block or highlighting block will be the central node of the Markmap, otherwise it will use the whole page blocks.
* fix: Local images can not popup after changing graph.

## 0.1.2

Expand Down
48 changes: 38 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,39 @@ import replaceAsync from 'string-replace-async';
import ellipsis from 'text-ellipsis';
import { BlockEntity, BlockUUIDTuple } from '@logseq/libs/dist/LSPlugin';


const settingsVersion = 'v1';
export const defaultSettings = {
keyBindings: {
openMarkmap: 'ctrl+m ctrl+m'
},
settingsVersion,
disabled: false,
};

export type DefaultSettingsType = typeof defaultSettings;

const initSettings = () => {
let settings = logseq.settings;

const shouldUpdateSettings = !settings || settings.settingsVersion != defaultSettings.settingsVersion;

if (shouldUpdateSettings) {
settings = defaultSettings;
logseq.updateSettings(settings);
}
};

const getSettings = (key: string | undefined, defaultValue: any = undefined) => {
let settings = logseq.settings;
const merged = Object.assign(defaultSettings, settings);
return key
? merged[key]
? merged[key]
: defaultValue
: merged;
};

function eventFire(el: any, etype: string){
if (el.fireEvent) {
el.fireEvent('on' + etype);
Expand Down Expand Up @@ -102,26 +135,21 @@ function createModel() {
}

async function main() {
initSettings();
const keyBindings = getSettings('keyBindings');

// Set Model Style
logseq.setMainUIInlineStyle({
position: 'fixed',
zIndex: 12,
});

logseq.App.registerCommandPalette({
key: 'mark-map-open-editing',
label: 'Open Markmap in editing',
keybinding: {
mode: 'global',
binding: 'ctrl+m ctrl+m'
}
}, triggerMarkmap);
logseq.App.registerCommandPalette({
key: 'mark-map-open',
label: 'Open Markmap',
keybinding: {
mode: 'non-editing',
binding: 'm m'
mode: 'global',
binding: keyBindings.openMarkmap,
}
}, triggerMarkmap);
logseq.Editor.registerSlashCommand('Markmap', triggerMarkmapForceBlock);
Expand Down

0 comments on commit b02b73e

Please sign in to comment.