File tree Expand file tree Collapse file tree
src/extensions/codemirror/toolbars/commands Expand file tree Collapse file tree Original file line number Diff line number Diff 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 = ( {
You can’t perform that action at this time.
0 commit comments