Problem
In src/plugins/multiCursor/inputHandling.ts (lines 229–246) and src/plugins/multiCursor/horizontalMovement.ts (lines 99–118), the newBackward array is computed from the pre-normalization nextRanges array. After calling normalizeRangesWithPrimary(), ranges may be merged (deduplicated), reducing the array length. However, the original-length newBackward array is passed directly to the MultiSelection constructor.
The constructor at MultiSelection.ts:38 stores it as-is when provided:
this.backward = backward ?? new Array(normalized.ranges.length).fill(false);
The ?? only triggers when backward is undefined/null — not when it has the wrong length.
Impact
When Shift+Arrow movement causes two cursors to merge to the same position, the backward flags become misaligned with the surviving ranges. This can cause the selection extend direction to flip unexpectedly on subsequent Shift+Arrow presses.
Reproduction
- Place two cursors close together (e.g., adjacent lines)
- Hold Shift+ArrowLeft/Right until the two selections overlap and merge
- Continue Shift+Arrow — the surviving selection may extend in the wrong direction
Suggested fix
After normalization, remap the newBackward array to match the normalized ranges. One approach: track which original range indices survive normalization and filter newBackward accordingly.
Files:
src/plugins/multiCursor/inputHandling.ts:229-246
src/plugins/multiCursor/horizontalMovement.ts:99-118
src/plugins/multiCursor/MultiSelection.ts:38
Problem
In
src/plugins/multiCursor/inputHandling.ts(lines 229–246) andsrc/plugins/multiCursor/horizontalMovement.ts(lines 99–118), thenewBackwardarray is computed from the pre-normalizationnextRangesarray. After callingnormalizeRangesWithPrimary(), ranges may be merged (deduplicated), reducing the array length. However, the original-lengthnewBackwardarray is passed directly to theMultiSelectionconstructor.The constructor at
MultiSelection.ts:38stores it as-is when provided:The
??only triggers whenbackwardisundefined/null— not when it has the wrong length.Impact
When Shift+Arrow movement causes two cursors to merge to the same position, the
backwardflags become misaligned with the surviving ranges. This can cause the selection extend direction to flip unexpectedly on subsequent Shift+Arrow presses.Reproduction
Suggested fix
After normalization, remap the
newBackwardarray to match the normalized ranges. One approach: track which original range indices survive normalization and filternewBackwardaccordingly.Files:
src/plugins/multiCursor/inputHandling.ts:229-246src/plugins/multiCursor/horizontalMovement.ts:99-118src/plugins/multiCursor/MultiSelection.ts:38