|
1 | 1 | /** @jsxImportSource @opentui/react */ |
2 | 2 | import { useState, useEffect, useRef, useCallback, type ReactNode } from "react"; |
3 | | -import { useKeyboard, useTerminalDimensions } from "@opentui/react"; |
| 3 | +import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/react"; |
4 | 4 | import { fromBase64, toBase64 } from "../utils/base64"; |
5 | 5 | import { getOrCreateBuffer, type StyledLine, type StyledSegment } from "../utils/ansi"; |
6 | 6 | import { usePrefixContext } from "./FocusContext"; |
@@ -44,6 +44,7 @@ export const WmuxTerminal = (props: WmuxTerminalProps): ReactNode => { |
44 | 44 | const { id, output, status } = props; |
45 | 45 | const sendInput = props.onInput.mutate; |
46 | 46 | const sendResize = props.onResize.mutate; |
| 47 | + const renderer = useRenderer(); |
47 | 48 | const { prefixRef, searchOpenRef, hasSelectionRef, activeTabId } = usePrefixContext(); |
48 | 49 |
|
49 | 50 | const [lines, setLines] = useState<readonly StyledLine[]>([]); |
@@ -71,6 +72,18 @@ export const WmuxTerminal = (props: WmuxTerminalProps): ReactNode => { |
71 | 72 | } |
72 | 73 | }); |
73 | 74 |
|
| 75 | + // Forward paste events to PTY |
| 76 | + useEffect(() => { |
| 77 | + const onPaste = (event: { readonly bytes: Uint8Array }) => { |
| 78 | + if (!isActiveTerminal) return; |
| 79 | + if (prefixRef.current || searchOpenRef.current) return; |
| 80 | + sendInput(toBase64(event.bytes)); |
| 81 | + }; |
| 82 | + const keyInput = renderer.keyInput as unknown as { on(e: string, fn: (event: { readonly bytes: Uint8Array }) => void): void; off(e: string, fn: (event: { readonly bytes: Uint8Array }) => void): void }; |
| 83 | + keyInput.on("paste", onPaste); |
| 84 | + return () => { keyInput.off("paste", onPaste); }; |
| 85 | + }, [renderer, isActiveTerminal, prefixRef, searchOpenRef, sendInput]); |
| 86 | + |
74 | 87 | const handleOutput = useCallback((b64: string) => { |
75 | 88 | const bytes = fromBase64(b64); |
76 | 89 | const text = new TextDecoder().decode(bytes); |
|
0 commit comments