Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (agy): erase one DEL per code point, not per UTF-16 unit

[._.]/ Adam Eivy8d26d6db393b
diff --git a/client/src/lib/terminalDictation.js b/client/src/lib/terminalDictation.js
index 2145707b80..70895669dc 100644
--- a/client/src/lib/terminalDictation.js
+++ b/client/src/lib/terminalDictation.js
@@ -78,9 +78,13 @@ const commonPrefixLength = (a, b) => {
export const planFieldEdit = (mirror, next, floor = 0) => {
const rewindTo = Math.min(mirror.length, Math.max(commonPrefixLength(mirror, next), floor));
const tail = next.slice(rewindTo);
+ // One DEL erases one CODE POINT at the far end, but JS string length counts
+ // UTF-16 code units — so an emoji is one erase, not two. Counting units would
+ // send a second DEL that eats the character before it.
+ const erased = [...mirror.slice(rewindTo)].length;
return {
// Pure append is the common case — skip building an empty DEL run for it.
- data: rewindTo === mirror.length ? tail : TERMINAL_DEL.repeat(mirror.length - rewindTo) + tail,
+ data: rewindTo === mirror.length ? tail : TERMINAL_DEL.repeat(erased) + tail,
committed: mirror.slice(0, rewindTo) + tail,
};
};
diff --git a/client/src/lib/terminalDictation.test.js b/client/src/lib/terminalDictation.test.js
index 317548f38e..6d3f68b168 100644
--- a/client/src/lib/terminalDictation.test.js
+++ b/client/src/lib/terminalDictation.test.js
@@ -52,10 +52,17 @@ describe('planFieldEdit', () => {
// 😀 and 😂 share a high surrogate; cutting between the halves would send a
// lone surrogate, which serializes to U+FFFD instead of the emoji.
const plan = planFieldEdit('hi 😀', 'hi 😂');
- expect(plan.data).toBe(`${DEL.repeat(2)}😂`);
expect(plan.committed).toBe('hi 😂');
expect([...plan.data].every((ch) => ch.charCodeAt(0) < 0xd800 || ch.codePointAt(0) > 0xffff)).toBe(true);
});
+
+ it('erases one DEL per code point, not per UTF-16 unit', () => {
+ // The far end erases a whole character per DEL. Counting JS string length
+ // would send two for one emoji and eat the space before it.
+ expect(planFieldEdit('hi 😀', 'hi ').data).toBe(DEL);
+ expect(planFieldEdit('hi 😀', 'hi 😂').data).toBe(`${DEL}😂`);
+ expect(planFieldEdit('a😀b😀', 'a').data).toBe(DEL.repeat(3));
+ });
});
describe('attachDictationBridge', () => {