Skip to content

Commit 1a2e63f

Browse files
committed
fix(user-input): read selection direction at apply time, document edge heuristic
1 parent d1b3562 commit 1a2e63f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/home/components/user-input

apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,11 @@ export const UserInput = forwardRef<UserInputHandle, UserInputProps>(function Us
10661066
const endRange = mentionTokensWithContext.findRangeContaining(end)
10671067
// A lone moved edge (keyboard extend/shrink, drag) snaps in its direction
10681068
// of travel: growing absorbs the chip, shrinking releases it. Fresh
1069-
// selections (double-click, select-all) expand outward.
1069+
// selections (double-click, select-all) expand outward. A fresh selection
1070+
// sharing one edge with `prev` (e.g. select-all from a caret at 0) takes
1071+
// the single-edge path, but a grown edge snaps outward there too — the
1072+
// two paths only differ for a shrinking edge, which implies a real
1073+
// single-edge gesture.
10701074
const singleEdgeMoved = (start !== prev.start) !== (end !== prev.end)
10711075
newStart = startRange
10721076
? singleEdgeMoved && start > prev.start
@@ -1091,10 +1095,10 @@ export const UserInput = forwardRef<UserInputHandle, UserInputProps>(function Us
10911095
// Deferred so in-flight click/drag processing can't override the write;
10921096
// bails if the selection moved again first (a newer event supersedes it).
10931097
// The write re-fires this handler, which then syncs the menus below.
1094-
const direction = textarea.selectionDirection ?? undefined
1098+
// Direction is read at apply time so it's never stale.
10951099
setTimeout(() => {
10961100
if (textarea.selectionStart !== start || textarea.selectionEnd !== end) return
1097-
textarea.setSelectionRange(newStart, newEnd, direction)
1101+
textarea.setSelectionRange(newStart, newEnd, textarea.selectionDirection ?? undefined)
10981102
}, 0)
10991103
return
11001104
}

0 commit comments

Comments
 (0)