@@ -6,6 +6,7 @@ import { NativeHeaderToolbar, NativeStackScreenOptions } from "../../native/Stac
66import { StackActions , useNavigation , type StaticScreenProps } from "@react-navigation/native" ;
77import { useCallback , useEffect , useMemo , useRef , useState } from "react" ;
88import { Platform , Pressable , View } from "react-native" ;
9+ import * as Clipboard from "expo-clipboard" ;
910import {
1011 KeyboardController ,
1112 KeyboardEvents ,
@@ -66,6 +67,7 @@ import {
6667 type TerminalMenuSession ,
6768} from "./terminalMenu" ;
6869import { cacheTerminalGridSize , getCachedTerminalGridSize } from "./terminalUiState" ;
70+ import { encodeTerminalPaste } from "./encodeTerminalPaste" ;
6971
7072const DEFAULT_TERMINAL_COLS = 80 ;
7173const DEFAULT_TERMINAL_ROWS = 24 ;
@@ -78,6 +80,7 @@ type HostPlatform = "mac" | "linux" | "windows" | "unknown";
7880type TerminalToolbarAction =
7981 | { readonly kind : "send" ; readonly key : string ; readonly label : string ; readonly data : string }
8082 | { readonly kind : "clear" ; readonly key : string ; readonly label : string }
83+ | { readonly kind : "paste" ; readonly key : string ; readonly label : string }
8184 | {
8285 readonly kind : "modifier" ;
8386 readonly key : string ;
@@ -488,6 +491,7 @@ export function ThreadTerminalRouteScreen(props: ThreadTerminalRouteScreenProps)
488491 { kind : "send" , key : "esc" , label : "esc" , data : "\u001b" } ,
489492 ...modifierActions ,
490493 { kind : "send" , key : "tab" , label : "tab" , data : "\t" } ,
494+ { kind : "paste" , key : "paste" , label : "paste" } ,
491495 { kind : "clear" , key : "clear" , label : "clear" } ,
492496 { kind : "send" , key : "up" , label : "↑" , data : "\u001b[A" } ,
493497 { kind : "send" , key : "down" , label : "↓" , data : "\u001b[B" } ,
@@ -1003,6 +1007,29 @@ export function ThreadTerminalRouteScreen(props: ThreadTerminalRouteScreenProps)
10031007 } ) ;
10041008 } , [ clearTerminal , selectedThread , terminalId ] ) ;
10051009
1010+ const handlePasteFromClipboard = useCallback ( ( ) => {
1011+ setPendingModifierState ( { terminalId, value : null } ) ;
1012+ void ( async ( ) => {
1013+ let text : string ;
1014+ try {
1015+ text = await Clipboard . getStringAsync ( ) ;
1016+ } catch {
1017+ return ;
1018+ }
1019+ if ( text . length === 0 ) {
1020+ return ;
1021+ }
1022+ // Bracketed paste (DECSET 2004) is not exposed from the mobile native
1023+ // surface yet, so encode like Ghostty with bracketed=false: sanitize and
1024+ // map newlines to CR without wrapping ESC[200~/ESC[201~.
1025+ const encoded = encodeTerminalPaste ( text ) ;
1026+ if ( encoded . length === 0 ) {
1027+ return ;
1028+ }
1029+ writeInput ( encoded ) ;
1030+ } ) ( ) ;
1031+ } , [ terminalId , writeInput ] ) ;
1032+
10061033 const handleToolbarActionPress = useCallback (
10071034 ( action : TerminalToolbarAction ) => {
10081035 if ( action . kind === "modifier" ) {
@@ -1021,6 +1048,11 @@ export function ThreadTerminalRouteScreen(props: ThreadTerminalRouteScreenProps)
10211048 return ;
10221049 }
10231050
1051+ if ( action . kind === "paste" ) {
1052+ handlePasteFromClipboard ( ) ;
1053+ return ;
1054+ }
1055+
10241056 setPendingModifierState ( { terminalId, value : null } ) ;
10251057 if ( pendingModifier === "ctrl" ) {
10261058 writeInput ( applyCtrlModifier ( action . data ) ) ;
@@ -1030,7 +1062,7 @@ export function ThreadTerminalRouteScreen(props: ThreadTerminalRouteScreenProps)
10301062 writeInput ( action . data ) ;
10311063 }
10321064 } ,
1033- [ handleClearTerminal , pendingModifier , terminalId , writeInput ] ,
1065+ [ handleClearTerminal , handlePasteFromClipboard , pendingModifier , terminalId , writeInput ] ,
10341066 ) ;
10351067
10361068 const handleDismissKeyboard = useCallback ( ( ) => {
0 commit comments