Skip to content

Commit

Permalink
Fix cursor behavior for deleteLine
Browse files Browse the repository at this point in the history
FIX: Fix an issue where `deleteLine` sometimes leaves the cursor on the wrong line.

See https://discuss.codemirror.net/t/inconsistent-behaviour-when-deleting-wrapped-lines/8119
  • Loading branch information
marijnh committed Apr 12, 2024
1 parent 4361eb4 commit 19491af
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,14 @@ export const deleteLine: Command = view => {
else if (to < state.doc.length) to++
return {from, to}
}))
let selection = updateSel(state.selection, range => view.moveVertically(range, true)).map(changes)
let selection = updateSel(state.selection, range => {
let dist: number | undefined = undefined
if (view.lineWrapping) {
let block = view.lineBlockAt(range.head), pos = view.coordsAtPos(range.head, range.assoc || 1)
if (pos) dist = (block.bottom + view.documentTop) - pos.bottom + view.defaultLineHeight / 2
}
return view.moveVertically(range, true, dist)
}).map(changes)
view.dispatch({changes, selection, scrollIntoView: true, userEvent: "delete.line"})
return true
}
Expand Down

0 comments on commit 19491af

Please sign in to comment.