Skip to content

Commit 2793b54

Browse files
Snap and fix selections around list markers
Collapse accidental small selections inside the hidden indent/marker area and change the cursor affinity when collapsing (use -1). Additionally, detect real drag selections that enter the marker/widget zone and snap the head to a consistent boundary (range to item.markerFrom) to prevent jitter from CodeMirror alternating between widget boundaries during mouse moves.
1 parent f44dd7f commit 2793b54

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

  • app/src/features/editor/extensions/markdown-decorations

app/src/features/editor/extensions/markdown-decorations/lists.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,15 +593,26 @@ function normalizeSelectionToListMarkers(state: EditorState) {
593593
const item = getListItemForLine(state, range.head);
594594

595595
if (!range.empty) {
596-
// Collapse small selections entirely within the hidden indent +
597-
// marker area. These are accidental selections from slight mouse
598-
// movement during a click inside a replace decoration.
599596
if (item) {
600597
const selFrom = Math.min(range.anchor, range.head);
601598
const selTo = Math.max(range.anchor, range.head);
599+
// Collapse small selections entirely within the hidden indent +
600+
// marker area. These are accidental selections from slight mouse
601+
// movement during a click inside a replace decoration.
602602
if (selFrom >= item.lineFrom && selTo <= item.contentFrom) {
603603
changed = true;
604-
return EditorSelection.cursor(item.markerFrom, 1);
604+
return EditorSelection.cursor(item.markerFrom, -1);
605+
}
606+
// For real drag selections, snap the head out of the marker/widget
607+
// area to a consistent boundary. Prevents jitter from CM
608+
// alternating between widget boundaries on each mouse move.
609+
if (
610+
range.head > item.lineFrom &&
611+
range.head < item.contentFrom &&
612+
range.head !== item.markerFrom
613+
) {
614+
changed = true;
615+
return EditorSelection.range(range.anchor, item.markerFrom);
605616
}
606617
}
607618
return range;

0 commit comments

Comments
 (0)