Skip to content

Commit 7c3e298

Browse files
committed
fix(user-input): record observed selection before reconcile early-return
1 parent 35a2591 commit 7c3e298

1 file changed

Lines changed: 7 additions & 6 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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,13 @@ export const UserInput = forwardRef<UserInputHandle, UserInputProps>(function Us
10531053
const handleSelectAdjust = useCallback(() => {
10541054
const textarea = textareaRef.current
10551055
if (!textarea) return
1056+
const start = textarea.selectionStart ?? 0
1057+
const end = textarea.selectionEnd ?? 0
1058+
const prev = lastSelectionRef.current
1059+
// Always track the raw observed selection — never an intended write that
1060+
// may get superseded — so edge-movement inference stays true to the DOM.
1061+
lastSelectionRef.current = { start, end }
1062+
10561063
// Controlled-value reconciliation: state and DOM can only drift when an
10571064
// edit's change event is lost (programmatic edits pair setValue
10581065
// synchronously). The DOM is the user's intent — adopt it and let the
@@ -1062,12 +1069,6 @@ export const UserInput = forwardRef<UserInputHandle, UserInputProps>(function Us
10621069
setValue(textarea.value)
10631070
return
10641071
}
1065-
const start = textarea.selectionStart ?? 0
1066-
const end = textarea.selectionEnd ?? 0
1067-
const prev = lastSelectionRef.current
1068-
// Always track the raw observed selection — never an intended write that
1069-
// may get superseded — so edge-movement inference stays true to the DOM.
1070-
lastSelectionRef.current = { start, end }
10711072

10721073
let newStart = start
10731074
let newEnd = end

0 commit comments

Comments
 (0)