fix: cursor jumping

This commit is contained in:
AidanTilgner 2024-02-02 14:29:03 -08:00
parent 1dd9dec5fe
commit 2affc5b943

13
main.ts
View file

@ -124,6 +124,19 @@ export default class Autogen extends Plugin {
const content = editor.getValue();
const newContent = content.replace(match, replacement);
editor.setValue(newContent);
// find the line number of the replacement string
const matchIndex = newContent.indexOf(replacement);
const lineNumber = newContent.substr(0, matchIndex).split("\n").length;
// find the character position of the replacement string
const line = editor.getLine(lineNumber);
const charPosition = line.indexOf(replacement);
editor.setCursor({
line: lineNumber,
ch: charPosition,
});
}
onunload() {}