diff --git a/main.ts b/main.ts index affd9cb..56cb4f7 100644 --- a/main.ts +++ b/main.ts @@ -85,6 +85,9 @@ export default class VimrcPlugin extends Plugin { this.app.workspace.on("window-open", (workspaceWindow, w) => { this.registerYankEvents(w); }) + this.app.workspace.on("file-open", async (cm: any) => { + this.registerFileOpenEvent(); + }) this.initialized = true; } @@ -101,6 +104,14 @@ export default class VimrcPlugin extends Plugin { }) } + registerFileOpenEvent(){ + // Record the position of selections in each file opened + let cmEditor = this.getCodeMirror(this.getActiveView()); + CodeMirror.on(cmEditor, "cursorActivity", async (cm: any) => { + this.currentSelection = cm.listSelections(); + }); + } + async onload() { await this.loadSettings(); this.addSettingTab(new SettingsTab(this.app, this)) @@ -182,11 +193,6 @@ export default class VimrcPlugin extends Plugin { this.defineJsCommand(this.codeMirrorVimObject); this.defineJsFile(this.codeMirrorVimObject); - // Record the position of selections - CodeMirror.on(cmEditor, "cursorActivity", async (cm: any) => { - this.currentSelection = cm.listSelections() - }); - vimCommands.split("\n").forEach( function (line: string, index: number, arr: [string]) { if (line.trim().length > 0 && line.trim()[0] != '"') {