Skip to content

Commit ffe960a

Browse files
committed
fix: pasting works
1 parent e400008 commit ffe960a

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

cli/src/chat.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -606,18 +606,6 @@ export const App = ({ initialPrompt }: { initialPrompt?: string } = {}) => {
606606
setInputRenderable(instance)
607607
if (instance) {
608608
setInputWidth(Math.max(0, instance.width))
609-
610-
instance.onPaste = (text: string) => {
611-
const currentValue = instance.value
612-
const cursorPos = instance.cursorPosition
613-
const beforeCursor = currentValue.slice(0, cursorPos)
614-
const afterCursor = currentValue.slice(cursorPos)
615-
const newValue = beforeCursor + text + afterCursor
616-
617-
instance.value = newValue
618-
instance.cursorPosition = cursorPos + text.length
619-
setInputValue(newValue)
620-
}
621609
}
622610
}, [])
623611

cli/src/multiline-input.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useCallback, useState, useEffect, useMemo, useRef } from 'react'
2-
import { useKeyboard } from '@opentui/react'
2+
import { useKeyboard, usePaste } from '@opentui/react'
33
import type { ScrollBoxRenderable } from '@opentui/core'
44
import { logger } from './logger'
55

@@ -90,6 +90,21 @@ export function MultilineInput({
9090
}
9191
}, [value.length, cursorPosition])
9292

93+
usePaste(
94+
useCallback(
95+
(event) => {
96+
if (!focused) return
97+
98+
const text = event.text
99+
const newValue =
100+
value.slice(0, cursorPosition) + text + value.slice(cursorPosition)
101+
onChange(newValue)
102+
setCursorPosition(cursorPosition + text.length)
103+
},
104+
[focused, value, cursorPosition, onChange],
105+
),
106+
)
107+
93108
// Auto-scroll to bottom when content changes
94109
useEffect(() => {
95110
const scrollBox = scrollBoxRef.current

0 commit comments

Comments
 (0)