From ccbaaefc23aba99e4ea6f82989d9e24b27e4491c Mon Sep 17 00:00:00 2001 From: Pomroka <3210260+Pomroka@users.noreply.github.com> Date: Fri, 5 Aug 2022 01:56:54 +0200 Subject: [PATCH] fix: selection stop working on next file opened issues: #104, #129 --- main.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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] != '"') {