File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -193,6 +193,30 @@ export function useTerminalInput(
193193 return ;
194194 }
195195 const handleData = ( data : Buffer | string ) => {
196+ const raw = String ( data ) ;
197+
198+ // Fix CJK composition bug on iOS terminals (Moshi, Blink, etc.).
199+ // iOS keyboards send composed characters as a single packet like:
200+ // "가\x7f나" (character + backspace + new character)
201+ // Without splitting, parseTerminalInput treats the whole packet as
202+ // one input and drops the composition backspaces, corrupting the text.
203+ if ( raw . includes ( "\x7f" ) && raw . length > 1 ) {
204+ const parts = raw . split ( "\x7f" ) ;
205+ if ( parts [ 0 ] ) {
206+ const { input, key } = parseTerminalInput ( parts [ 0 ] ) ;
207+ handlerRef . current ( input , key ) ;
208+ }
209+ for ( let i = 1 ; i < parts . length ; i ++ ) {
210+ const bs = parseTerminalInput ( "\x7f" ) ;
211+ handlerRef . current ( bs . input , bs . key ) ;
212+ if ( parts [ i ] ) {
213+ const { input, key } = parseTerminalInput ( parts [ i ] ) ;
214+ handlerRef . current ( input , key ) ;
215+ }
216+ }
217+ return ;
218+ }
219+
196220 const { input, key } = parseTerminalInput ( data ) ;
197221 handlerRef . current ( input , key ) ;
198222 } ;
You can’t perform that action at this time.
0 commit comments