Skip to content

Commit

Permalink
Remove keymaps when viewport switched to non-canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunhurryup committed Jun 20, 2024
1 parent 482aa98 commit 5e765ac
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 4
tab_width = 4
indent_size = 2
tab_width = 2
61 changes: 42 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {App, Plugin, PluginManifest, PluginSettingTab, Setting as ObsidianSetting } from 'obsidian'
import {Keymap, Layout, Node, Setting, View} from './module'
import { App, Plugin, PluginManifest } from 'obsidian'
import { Keymap, Layout, Node, Setting, View } from './module'


export default class LovelyMindmap extends Plugin{
Expand Down Expand Up @@ -29,32 +29,55 @@ export default class LovelyMindmap extends Plugin{
if (!!this.canvas) {
clearInterval(this.intervalTimer.get('canvas'))
}
}, 1000)
}, 100)

if (!this.intervalTimer.get('canvas')) {
this.intervalTimer.set('canvas', timer)
}
}

onActiveLeafChange() {
this.app.workspace.on('active-leaf-change', async (leaf) => {
// @ts-ignore
const extension = leaf?.view?.file?.extension
if (extension === 'canvas') {
this.onKeymap()
return
}
this.onunload()
})
}

/**
* A series of events for canvas initialization
*
* - When switching away from the canvas viewport, remove the keyboard shortcuts and canvas instance.
* - When switching back to the canvas viewport, re-register the keyboard shortcuts and canvas instance.
*/
onKeymap() {
this.createCanvasInstance()
this.keymap.registerAll()

// fixed: blur node doesn't work
// @see https://github.com/xincan1949/lovely-mindmap/issues/1#issue-1868166056
this.addCommand({
id: 'blurNode',
name: 'Blur node',
hotkeys: [
{
modifiers: ['Mod'],
key: 'Escape',
},
],
checkCallback: () => this.keymap.blurNode(),
});
}

async onload() {
await this.setting.loadSettings()
this.addSettingTab(new Setting(this))
this.keymap.registerAll()
this.createCanvasInstance()

// fixed: blur node doesn't work
// @see https://github.com/xincan1949/lovely-mindmap/issues/1#issue-1868166056
this.addCommand({
id: 'blurNode',
name: 'Blur node',
hotkeys: [
{
modifiers: ['Mod'],
key: 'Escape',
},
],
checkCallback: () => this.keymap.blurNode(),
});
this.onActiveLeafChange()
this.onKeymap()
}

onunload() {
Expand Down

0 comments on commit 5e765ac

Please sign in to comment.