Skip to content

Commit c2624ad

Browse files
committed
docs(user-input): trim verbose comments in selection logic
1 parent d505023 commit c2624ad

2 files changed

Lines changed: 10 additions & 17 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/user-input/chip-selection.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@ export interface Selection {
2323
/**
2424
* Snaps a selection so no edge sits inside a chip.
2525
*
26-
* - **Collapsed caret inside a chip** → nearest chip edge (so the caret can't
27-
* rest mid-chip).
28-
* - **Ranged selection** → each edge inside a chip snaps to a chip boundary,
29-
* never collapsing the range. Which boundary depends on the gesture:
30-
* - A *lone moved edge* (keyboard extend/shrink, drag) snaps in its direction
31-
* of travel — growing absorbs the chip, shrinking releases it.
32-
* - A *fresh selection* (double-click, select-all) expands outward to include
33-
* touched chips whole. A fresh selection that happens to share one edge with
34-
* `prev` (e.g. select-all from a caret already at 0) takes the single-edge
35-
* path, but a grown edge expands outward there too — the paths differ only
36-
* for a *shrinking* edge, which implies a genuine single-edge gesture.
26+
* - **Collapsed caret inside a chip** → nearest chip edge.
27+
* - **Ranged selection** → each edge inside a chip snaps to a boundary without
28+
* collapsing the range. A lone moved edge (keyboard extend/shrink, drag) snaps
29+
* in its direction of travel — growing absorbs the chip, shrinking releases
30+
* it; a fresh selection (double-click, select-all) expands outward. The two
31+
* paths differ only for a shrinking edge, so the gesture inference is safe
32+
* even when a fresh selection happens to share an edge with `prev`.
3733
*
3834
* @param sel - The observed selection.
3935
* @param prev - The previously observed selection, used to infer which edge moved.

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,8 +1068,6 @@ export const UserInput = forwardRef<UserInputHandle, UserInputProps>(function Us
10681068
if (!textarea) return
10691069
const start = textarea.selectionStart ?? 0
10701070
const end = textarea.selectionEnd ?? 0
1071-
// `selectionchange` fires before this `select` handler, so prevSelectionRef
1072-
// already holds the selection from just before this change.
10731071
const prev = prevSelectionRef.current
10741072

10751073
// Adopt value changes that bypassed React's change tracking (browser
@@ -1086,10 +1084,9 @@ export const UserInput = forwardRef<UserInputHandle, UserInputProps>(function Us
10861084
const snapped = snapSelectionToChips({ start, end }, prev, startChip, endChip)
10871085

10881086
if (snapped.start !== start || snapped.end !== end) {
1089-
// Deferred so in-flight click/drag processing can't override the write;
1090-
// bails if the selection moved again first (a newer event supersedes it).
1091-
// The write re-fires this handler, which then syncs the menus below.
1092-
// Direction is read at apply time so it's never stale.
1087+
// Deferred so in-flight click/drag processing can't override the write,
1088+
// and bailed if the selection moved again first. The write re-fires this
1089+
// handler, which then syncs the menus.
10931090
setTimeout(() => {
10941091
if (textarea.selectionStart !== start || textarea.selectionEnd !== end) return
10951092
textarea.setSelectionRange(

0 commit comments

Comments
 (0)