Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Commit 773a0ee

Browse files
committed
Properly track associativity for shift-click selections
FIX: Make sure the selection head associativity is properly set for mouse selections made with shift held down.
1 parent 3612d3f commit 773a0ee

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"sideEffects": false,
2727
"license": "MIT",
2828
"dependencies": {
29-
"@codemirror/state": "^6.5.0",
29+
"@codemirror/state": "^6.6.0",
3030
"crelt": "^1.0.6",
3131
"style-mod": "^4.1.0",
3232
"w3c-keyname": "^2.2.4"

src/docview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ export class DocView {
525525
}
526526

527527
let {range} = target
528-
let rect = this.coordsAt(range.head, range.empty ? range.assoc : range.head > range.anchor ? -1 : 1), other
528+
let rect = this.coordsAt(range.head, range.assoc ?? (range.empty ? 0 : range.head > range.anchor ? -1 : 1)), other
529529
if (!rect) return
530530
if (!range.empty && (other = this.coordsAt(range.anchor, range.anchor > range.head ? -1 : 1)))
531531
rect = {left: Math.min(rect.left, other.left), top: Math.min(rect.top, other.top),

src/draw-selection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const cursorLayer = layer({
7676
let prim = r == state.selection.main
7777
if (r.empty || conf.drawRangeCursor && !(prim && browser.ios && conf.iosSelectionHandles)) {
7878
let className = prim ? "cm-cursor cm-cursor-primary" : "cm-cursor cm-cursor-secondary"
79-
let cursor = r.empty ? r : EditorSelection.cursor(r.head, r.head > r.anchor ? -1 : 1)
79+
let cursor = r.empty ? r : EditorSelection.cursor(r.head, r.assoc)
8080
for (let piece of RectangleMarker.forRange(view, className, cursor)) cursors.push(piece)
8181
}
8282
}

src/input.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,10 @@ function basicMouseSelection(view: EditorView, event: MouseEvent) {
591591
if (start.pos != cur.pos && !extend) {
592592
let startRange = rangeForClick(view, start.pos, start.assoc, type)
593593
let from = Math.min(startRange.from, range.from), to = Math.max(startRange.to, range.to)
594-
range = from < range.from ? EditorSelection.range(from, to) : EditorSelection.range(to, from)
594+
range = from < range.from ? EditorSelection.range(from, to, range.assoc) : EditorSelection.range(to, from, range.assoc)
595595
}
596596
if (extend)
597-
return startSel.replaceRange(startSel.main.extend(range.from, range.to))
597+
return startSel.replaceRange(startSel.main.extend(range.from, range.to, range.assoc))
598598
else if (multiple && type == 1 && startSel.ranges.length > 1 && (removed = removeRangeAround(startSel, cur.pos)))
599599
return removed
600600
else if (multiple)

0 commit comments

Comments
 (0)