Skip to content

Commit 19491af

Browse files
committed
Fix cursor behavior for deleteLine
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
1 parent 4361eb4 commit 19491af

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/commands.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,14 @@ export const deleteLine: Command = view => {
673673
else if (to < state.doc.length) to++
674674
return {from, to}
675675
}))
676-
let selection = updateSel(state.selection, range => view.moveVertically(range, true)).map(changes)
676+
let selection = updateSel(state.selection, range => {
677+
let dist: number | undefined = undefined
678+
if (view.lineWrapping) {
679+
let block = view.lineBlockAt(range.head), pos = view.coordsAtPos(range.head, range.assoc || 1)
680+
if (pos) dist = (block.bottom + view.documentTop) - pos.bottom + view.defaultLineHeight / 2
681+
}
682+
return view.moveVertically(range, true, dist)
683+
}).map(changes)
677684
view.dispatch({changes, selection, scrollIntoView: true, userEvent: "delete.line"})
678685
return true
679686
}

0 commit comments

Comments
 (0)