glacambre/editor-adapter

CodeMirror unable to set cursor position.

Closed this issue · 2 comments

I'm looking into why firenvim failed to move the cursor after saving on jupyter notebook.

Haven't really look deep into it, but it seems to me that line 67 in CodeMirrorEditor.ts should be "setCursor" instead of "getCursor"?

Update: I can confirm this change will fix the problem for jupyter notebook on Firefox. I tested this by download the extension on Firefox store and modify that part.

@snippins Ahah, indeed! The fix is as simple as:

diff --git a/CodeMirrorEditor.ts b/CodeMirrorEditor.ts
index e57f30e..36bc78b 100644
--- a/CodeMirrorEditor.ts
+++ b/CodeMirrorEditor.ts
@@ -64,7 +64,7 @@ export class CodeMirrorEditor extends AbstractEditor {
     setCursor (line: number, column: number) {
         return executeInPage(`(${/* istanbul ignore next */ (selec: string, l: number, c: number) => {
             const elem = document.querySelector(selec) as any;
-            return elem.CodeMirror.getCursor(l - 1, c);
+            return elem.CodeMirror.setCursor({line: l - 1, ch: c });
         }})(${JSON.stringify(computeSelector(this.elem))}, ${line}, ${column})`);
     }
 }
diff --git a/index.js b/index.js
index fc7d70f..6231756 100644
--- a/index.js
+++ b/index.js
@@ -132,7 +132,7 @@ export class CodeMirrorEditor extends AbstractEditor {
     setCursor(line, column) {
         return executeInPage(`(${ /* istanbul ignore next */(selec, l, c) => {
             const elem = document.querySelector(selec);
-            return elem.CodeMirror.getCursor(l - 1, c);
+            return elem.CodeMirror.setCursor({ line: l - 1, ch: c });
         }})(${JSON.stringify(computeSelector(this.elem))}, ${line}, ${column})`);
     }
 }

I want to credit you as the author of this patch - is that fine with you? If yes, what email should I use? (Or would you prefer to submit this patch as a pull request that I would then merge?)

@glacambre Nah, as a proud member of the Emacs's cult, I can't leave any trace of involvement in a vim-related project.

Jokes aside, you don't need to credit me for this. Also thanks for the awesome firenvim project. 😊