mirror of
https://github.com/aidantilgner/AutogenObsidianPlugin.git
synced 2026-07-22 09:20:32 +00:00
fix: cursor jumping
This commit is contained in:
parent
1dd9dec5fe
commit
2affc5b943
1 changed files with 13 additions and 0 deletions
13
main.ts
13
main.ts
|
|
@ -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() {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue