fix: selection stop working on next file opened

issues: #104, #129
This commit is contained in:
Pomroka 2022-08-05 01:56:54 +02:00
parent 361c2686da
commit ccbaaefc23

16
main.ts
View file

@ -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] != '"') {