Skip to content

Commit 1ed52b3

Browse files
committed
refactor(cli): use OpenTUI's built-in onPaste prop instead of custom hook
- Replace useOpentuiPaste hook with onPaste prop on scrollbox component - Remove custom cli/src/hooks/use-opentui-paste.ts file - Use more idiomatic OpenTUI pattern for paste handling
1 parent 55ff21a commit 1ed52b3

File tree

2 files changed

+15
-50
lines changed

2 files changed

+15
-50
lines changed

cli/src/components/multiline-input.tsx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
} from 'react'
1111

1212
import { InputCursor } from './input-cursor'
13-
import { useOpentuiPaste } from '../hooks/use-opentui-paste'
1413
import { useTheme } from '../hooks/use-theme'
1514
import { clamp } from '../utils/math'
1615
import { calculateNewCursorPosition } from '../utils/word-wrap-utils'
@@ -157,24 +156,22 @@ export const MultilineInput = forwardRef<
157156
[],
158157
)
159158

160-
useOpentuiPaste(
161-
useCallback(
162-
(event: PasteEvent) => {
163-
if (!focused) return
159+
const handlePaste = useCallback(
160+
(event: PasteEvent) => {
161+
if (!focused) return
164162

165-
const text = event.text ?? ''
166-
if (!text) return
163+
const text = event.text ?? ''
164+
if (!text) return
167165

168-
const newValue =
169-
value.slice(0, cursorPosition) + text + value.slice(cursorPosition)
170-
onChange({
171-
text: newValue,
172-
cursorPosition: cursorPosition + text.length,
173-
lastEditDueToNav: false,
174-
})
175-
},
176-
[focused, value, cursorPosition, onChange],
177-
),
166+
const newValue =
167+
value.slice(0, cursorPosition) + text + value.slice(cursorPosition)
168+
onChange({
169+
text: newValue,
170+
cursorPosition: cursorPosition + text.length,
171+
lastEditDueToNav: false,
172+
})
173+
},
174+
[focused, value, cursorPosition, onChange],
178175
)
179176

180177
const cursorRow = lineInfo
@@ -785,6 +782,7 @@ export const MultilineInput = forwardRef<
785782
stickyScroll={true}
786783
stickyStart="bottom"
787784
scrollbarOptions={{ visible: false }}
785+
onPaste={handlePaste}
788786
style={{
789787
flexGrow: 0,
790788
flexShrink: 0,

cli/src/hooks/use-opentui-paste.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)