Skip to content

Commit

Permalink
always move cursor to end of editor when switching nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
socketteer committed Nov 6, 2023
1 parent c36dd13 commit 4b0c9eb
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,32 +701,38 @@ export default class LoomPlugin extends Plugin {
);

// update the editor's text
const cursor = this.editor.getCursor();
const linesBefore = this.editor.getValue().split("\n");
// const cursor = this.editor.getCursor();
// const linesBefore = this.editor.getValue().split("\n");
this.editor.setValue(this.fullText(file, id));

// if the cursor is at the beginning of the editor, move it to the end
if(cursor.line === 0 && cursor.ch === 0) {
// always move cursor to the end of the editor
const line = this.editor.lineCount() - 1;
const ch = this.editor.getLine(line).length;
this.editor.setCursor({ line, ch });
return;
}

// if the text preceding the cursor has changed, move the cursor to the end of the text
// otherwise, restore the cursor position
const linesAfter = this.editor
.getValue()
.split("\n")
.slice(0, cursor.line + 1);
for (let i = 0; i < cursor.line; i++)
if (linesBefore[i] !== linesAfter[i]) {
const line = this.editor.lineCount() - 1;
const ch = this.editor.getLine(line).length;
this.editor.setCursor({ line, ch });
return;
}
this.editor.setCursor(cursor);
// return;

// // if the cursor is at the beginning of the editor, move it to the end
// if(cursor.line === 0 && cursor.ch === 0) {
// const line = this.editor.lineCount() - 1;
// const ch = this.editor.getLine(line).length;
// this.editor.setCursor({ line, ch });
// return;
// }

// // if the text preceding the cursor has changed, move the cursor to the end of the text
// // otherwise, restore the cursor position
// const linesAfter = this.editor
// .getValue()
// .split("\n")
// .slice(0, cursor.line + 1);
// for (let i = 0; i < cursor.line; i++)
// if (linesBefore[i] !== linesAfter[i]) {
// const line = this.editor.lineCount() - 1;
// const ch = this.editor.getLine(line).length;
// this.editor.setCursor({ line, ch });
// return;
// }
// this.editor.setCursor(cursor);
})
)
);
Expand Down

0 comments on commit 4b0c9eb

Please sign in to comment.