Skip to content

Commit b74a112

Browse files
committed
move cursor clamping into setter
1 parent bf30615 commit b74a112

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

cli/src/components/multiline-input.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,6 @@ export const MultilineInput = forwardRef<
140140
[],
141141
)
142142

143-
// Sync cursor when value changes externally
144-
useEffect(() => {
145-
onChange((prev) => ({
146-
...prev,
147-
cursorPosition: clamp(cursorPosition, 0, value.length),
148-
}))
149-
}, [value.length, cursorPosition])
150143

151144
useOpentuiPaste(
152145
useCallback(

cli/src/state/chat-store.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { enableMapSet } from 'immer'
22
import { create } from 'zustand'
33
import { immer } from 'zustand/middleware/immer'
44

5+
import { clamp } from '../utils/math'
6+
57
import type { ChatMessage } from '../types/chat'
68
import type { AgentMode } from '../utils/constants'
79

@@ -120,7 +122,7 @@ export const useChatStore = create<ChatStore>()(
120122
})
121123
: value
122124
state.inputValue = text
123-
state.cursorPosition = cursorPosition
125+
state.cursorPosition = clamp(cursorPosition, 0, text.length)
124126
state.lastEditDueToNav = lastEditDueToNav
125127
}),
126128

0 commit comments

Comments
 (0)