From 414dd51eb2101cba6368a574d623dc83303763f9 Mon Sep 17 00:00:00 2001 From: Hadrien Kerlero <199662351+HadrienKerlero@users.noreply.github.com> Date: Sat, 21 Nov 2026 16:09:24 +0100 Subject: [PATCH] fix(web): send a typed combining mark as a plain append (#830) Both editBetween() functions return a pure append as-is before the grapheme split, so a mark typed onto the last letter is not a DEL plus the retyped cluster (zsh would double the base letter). Drop a redundant setFlushed() in the Tab-completion fallback; detectBufferText() already stores it. --- src/web/public/terminal-ios-native-input.js | 4 ++++ .../public/terminal-keycode229-recovery.js | 4 ++++ src/web/public/terminal-ui.js | 1 - test/terminal-ios-native-input.test.ts | 21 +++++++++++++++++++ test/terminal-keycode229-recovery.test.ts | 15 +++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/web/public/terminal-ios-native-input.js b/src/web/public/terminal-ios-native-input.js index 147b1b52..f4bd5c17 100644 --- a/src/web/public/terminal-ios-native-input.js +++ b/src/web/public/terminal-ios-native-input.js @@ -34,6 +34,10 @@ } function editBetween(previous, next) { + // A pure append (including a combining mark or tone typed onto the last letter) + // is sent as-is, as on master: re-typing the extended cluster would make a + // code-point line editor (zsh) double the base letter. + if (next.startsWith(previous)) return { deleted: 0, inserted: next.slice(previous.length) }; const a = graphemes(previous); const b = graphemes(next); let prefix = 0; diff --git a/src/web/public/terminal-keycode229-recovery.js b/src/web/public/terminal-keycode229-recovery.js index 0e86ad90..223d8cd4 100644 --- a/src/web/public/terminal-keycode229-recovery.js +++ b/src/web/public/terminal-keycode229-recovery.js @@ -84,6 +84,10 @@ * red heart, a skin-tone emoji, a flag or a ZWJ family is one DEL, as it is one backspace. */ function editBetween(previous, next) { + // A pure append (including a combining mark or tone typed onto the last letter) + // is sent as-is: re-typing the extended cluster would make a code-point line + // editor (zsh) double the base letter. + if (next.startsWith(previous)) return { deleted: 0, inserted: next.slice(previous.length) }; const a = graphemes(previous); const b = graphemes(next); let prefix = 0; diff --git a/src/web/public/terminal-ui.js b/src/web/public/terminal-ui.js index 3e085bb8..0984e13e 100644 --- a/src/web/public/terminal-ui.js +++ b/src/web/public/terminal-ui.js @@ -1101,7 +1101,6 @@ Object.assign(CodemanApp.prototype, { this._tabCompletionSessionId = null; this._tabCompletionRetries = 0; this._tabCompletionBaseText = null; - ov.setFlushed(detected.length, detected); ov.rerender(); } }); diff --git a/test/terminal-ios-native-input.test.ts b/test/terminal-ios-native-input.test.ts index 7e2735ee..2a986baa 100644 --- a/test/terminal-ios-native-input.test.ts +++ b/test/terminal-ios-native-input.test.ts @@ -568,6 +568,9 @@ const replayCases: Array<[string, (h: Harness) => void]> = [ expect(h.api.editBetween(`ok${emoji}`, 'ok')).toEqual({ deleted: 1, inserted: '' }); expect(h.api.editBetween(`a${emoji}b`, 'aX')).toEqual({ deleted: 2, inserted: 'X' }); } + // A combining mark or tone typed onto the last letter is a plain append, as on master. + expect(h.api.editBetween('\u0E01', '\u0E01\u0E34')).toEqual({ deleted: 0, inserted: '\u0E34' }); + expect(h.api.editBetween('\u0915\u094D', '\u0915\u094D\u0937')).toEqual({ deleted: 0, inserted: '\u0937' }); for (const ch of 'hel') h.type(ch); h.type('lo'); h.tick(); @@ -959,6 +962,24 @@ const replayCases: Array<[string, (h: Harness) => void]> = [ } }, ], + [ + '20c combining marks typed one key at a time are plain appends', + (h) => { + // Thai กิ่ and Hindi क्ष: each keystroke extends the last grapheme cluster. + // Re-typing that cluster would make a code-point line editor (zsh) double the base letter. + for (const word of ['\u0E01\u0E34\u0E48', '\u0915\u094D\u0937']) { + for (const ch of word) h.edit(ch); + h.tick(); + h.bytes(Array.from(word)); + expect(h.value()).toBe(word); + h.invariant(); + while (h.textarea.value) h.backspace(); + expect(h.value()).toBe(''); + h.tick(); + h.clearSent(); + } + }, + ], [ '21 destroy restoration and stock behavior', (h) => { diff --git a/test/terminal-keycode229-recovery.test.ts b/test/terminal-keycode229-recovery.test.ts index 2e0f1f3c..7f66db40 100644 --- a/test/terminal-keycode229-recovery.test.ts +++ b/test/terminal-keycode229-recovery.test.ts @@ -763,6 +763,19 @@ describe('edit-based sync of the helper textarea (autocorrect replacements)', () expect(e.sent.slice(before)).toEqual(['\x7f']); }); + it.each([ + ['Thai', '\u0E01\u0E34\u0E48'], + ['Hindi', '\u0915\u094D\u0937'], + ])('types %s combining marks one field state at a time as plain appends', (_name, word) => { + // Each keystroke extends the last grapheme cluster; re-typing that cluster would + // make a code-point line editor (zsh) double the base letter. + const e = editSyncHarness(); + e.create(true); + typeKeys(e, word); + expect(e.sent).toEqual(Array.from(word)); + expect(e.line()).toBe(word); + }); + it.each(MULTI_CODE_POINT_EMOJI)( 'keeps the local-echo draft at ok when the %s is deleted (real overlay)', (_name, emoji) => { @@ -825,5 +838,7 @@ describe('edit-based sync of the helper textarea (autocorrect replacements)', () expect(editBetween('x😀', 'x')).toEqual({ deleted: 1, inserted: '' }); expect(editBetween('x\u{1F44D}\u{1F3FD}', 'x')).toEqual({ deleted: 1, inserted: '' }); expect(editBetween('', '')).toEqual({ deleted: 0, inserted: '' }); + // A mark typed onto the last letter is a plain append, not a DEL and a re-typed cluster. + expect(editBetween('\u0E01', '\u0E01\u0E34')).toEqual({ deleted: 0, inserted: '\u0E34' }); }); });