Skip to content

Commit fb68eea

Browse files
authored
Merge pull request #94 from liante0904/fix-ios-cjk-composition
fix: resolve CJK composition bug on iOS terminals (backspace packet splitting)
2 parents f611c94 + bbf810d commit fb68eea

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/ui/prompt/useTerminalInput.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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
};

0 commit comments

Comments
 (0)