mirror of
https://github.com/esm7/obsidian-vimrc-support.git
synced 2026-07-22 05:00:25 +00:00
fix: guard against uninitialized codemirror instance (#246)
In obsidian (>=v1.7.2?) the codemirror instance is often not unitialized at times, triggering some uncaught exceptions. This is particularly noticable when: - (w/ "Vim chord display" enabled) opening the vault w/o a note opened - closing all tabs and opening a note Add some null guards to avoid these errors
This commit is contained in:
parent
ba94e13835
commit
a5fdaec56c
1 changed files with 6 additions and 1 deletions
7
main.ts
7
main.ts
|
|
@ -153,6 +153,7 @@ export default class VimrcPlugin extends Plugin {
|
|||
if (!view) return;
|
||||
|
||||
let cm = this.getCodeMirror(view);
|
||||
if (!cm) return;
|
||||
if (
|
||||
this.getCursorActivityHandlers(cm).some(
|
||||
(e: { name: string }) => e.name === "updateSelection")
|
||||
|
|
@ -180,6 +181,8 @@ export default class VimrcPlugin extends Plugin {
|
|||
this.currentVimStatus = vimStatus.normal;
|
||||
if (this.settings.displayVimMode)
|
||||
this.updateVimStatusBar();
|
||||
|
||||
if (!cmEditor) return;
|
||||
cmEditor.off('vim-mode-change', this.logVimModeChange);
|
||||
cmEditor.on('vim-mode-change', this.logVimModeChange);
|
||||
|
||||
|
|
@ -580,7 +583,9 @@ export default class VimrcPlugin extends Plugin {
|
|||
this.vimChordStatusBar.parentElement.insertBefore(this.vimChordStatusBar, parent.firstChild);
|
||||
this.vimChordStatusBar.style.marginRight = "auto";
|
||||
|
||||
let cmEditor = this.getCodeMirror(this.getActiveView());
|
||||
const view = this.getActiveView();
|
||||
if (!view) return;
|
||||
let cmEditor = this.getCodeMirror(view);
|
||||
// See https://codemirror.net/doc/manual.html#vimapi_events for events.
|
||||
cmEditor.off('vim-keypress', this.onVimKeypress);
|
||||
cmEditor.on('vim-keypress', this.onVimKeypress);
|
||||
|
|
|
|||
Loading…
Reference in a new issue