Skip to content

Commit c3bcd1f

Browse files
committed
fixed cursor issue
1 parent c971ee9 commit c3bcd1f

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/extensions/codemirror/toolbars/commands/markdown.command.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,17 @@ export default class MarkdownCommand {
173173
const state = view.state;
174174

175175
const flags = "#".repeat(level) + " ";
176-
let line = new Line();
176+
177+
let lastCursorPosition = 0;
177178

178179
view.dispatch(
179180
state.changeByRange((range) => {
180-
line = state.doc.lineAt(range.from);
181+
const line = state.doc.lineAt(range.from);
181182

182183
const content = line.text.replace(/^((#+) )?/, flags);
183184

184185
const diffLength = content.length - line.length;
185-
186+
lastCursorPosition = line.to + diffLength;
186187
return {
187188
changes: {
188189
from: line.from,
@@ -193,7 +194,8 @@ export default class MarkdownCommand {
193194
};
194195
})
195196
);
196-
this.enforceCursorFocus(line.length + level + 1); //captures the length of the text plus the added # tags
197+
198+
this.enforceCursorFocus(lastCursorPosition);
197199
};
198200

199201
private applyFormatting = ({

0 commit comments

Comments
 (0)