The best way to control Claude Code, Codex and more from any computer or phone
fix(voice): insert Unicode word boundaries for dictation (#31799)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Julius Marminge committed
Nov 5, 2026 at 22:08 UTC
bc1eb5d32afb4dca161cf24c9079bf695ae10bda
2 files changed
+35
-14
packages/client-runtime/src/voice-input/controller.test.ts
+19
@@ -234,6 +234,7 @@ describe("resolveTranscriptCommit", () => {
234
it.each([
235
["Hello", "world", "Hello world"],
236
["Hello", "世界", "Hello世界"],
237
+ ["Hello", "𝟚", "Hello 𝟚"],
238
["你好", "世界", "你好世界"],
239
])(
240
"preserves script boundaries with an autodetected language: %s + %s",
@@ -246,6 +247,24 @@ describe("resolveTranscriptCommit", () => {
247
},
248
);
249
250
+ it.each([
251
+ ["Korean", "코드를", 3, "검토해 주세요", "ko_KR", "코드를 검토해 주세요"],
252
+ ["a supplementary letter", "𞤀", 2, "𞤦", "ff-Adlm", "𞤀 𞤦"],
253
+ ["a trailing combining mark", "नमस्ते", 6, "दुनिया", "hi-IN", "नमस्ते दुनिया"],
254
+ ["a non-ASCII word after the caret", "Änderungen", 0, "Weitere", "de_DE", "Weitere Änderungen"],
255
+ ["spaceless Japanese", "修正キャッシュ", 7, "テストも", "ja-JP", "修正キャッシュテストも"],
256
+ ["spaceless Thai", "โลก", 0, "สวัสดี", "th-TH", "สวัสดีโลก"],
257
+ ])(
258
+ "inserts at a caret with the recorded language's word spacing: %s",
259
+ (_case, text, caret, spoken, locale, expected) => {
260
+ const captured = draft({ text, selection: { start: caret, end: caret } });
261
+ expect(resolveTranscriptCommit(captured, captured, spoken, locale)).toMatchObject({
262
+ kind: "commit",
263
+ text: expected,
264
+ });
265
+ },
266
+ );
267
+
268
it("replaces the recorded UTF-16 selection around emoji and composer tokens", () => {
269
const text = "Fix 🧪 then $review please";
270
const tokenStart = text.indexOf("$review");
packages/client-runtime/src/voice-input/controller.ts
+16
-14
@@ -107,6 +107,8 @@ type TranscriptCommitResult =
107
| { readonly kind: "stale" }
108
| { readonly kind: "empty" };
109
110
+const WORD_SPACELESS_LANGUAGES = new Set(["ja", "zh", "yue", "th", "lo", "km", "my"]);
111
+
112
export function resolveTranscriptCommit(
113
captured: VoiceDraftSnapshot,
114
current: VoiceDraftSnapshot | null,
@@ -128,23 +130,23 @@ export function resolveTranscriptCommit(
130
}
131
132
const isEmptySelection = captured.selection.start === captured.selection.end;
131
- const normalizedLocale = locale.replaceAll("_", "-").toLowerCase();
132
- const usesEnglishSpacing = normalizedLocale === "en" || normalizedLocale.startsWith("en-");
133
+ const language = locale.split(/[-_]/)[0]!.toLowerCase();
134
let insertion = replacement;
134
- const autoSpacing = normalizedLocale === "auto";
135
- if (isEmptySelection && (usesEnglishSpacing || autoSpacing)) {
136
- const left = captured.text[captured.selection.start - 1];
137
- const right = captured.text[captured.selection.start];
135
+ if (isEmptySelection && !WORD_SPACELESS_LANGUAGES.has(language)) {
136
+ const auto = language === "auto";
137
+ const caret = captured.selection.start;
138
+ const left = captured.text.slice(Math.max(0, caret - 2), caret);
139
+ const right = captured.text.slice(caret, caret + 2);
140
+ const leftEdge = auto ? /[A-Za-z0-9.!?,:;)\]}'"]$/ : /(?:\p{L}|\p{M}|\p{N}|[.!?,:;)\]}'"])$/u;
141
+ const rightEdge = auto ? /^[A-Za-z0-9([{'"]/ : /^[\p{L}\p{M}\p{N}([{'"]/u;
142
const leftNeedsBoundary =
139
- (!autoSpacing || /^[\p{Script=Latin}\p{N}]/u.test(replacement)) &&
140
- left !== undefined &&
141
- /[A-Za-z0-9.!?,:;)\]}'"]/.test(left) &&
142
- (right === undefined || /\s/.test(right));
143
+ (!auto || /^[\p{Script=Latin}\p{N}]/u.test(replacement)) &&
144
+ leftEdge.test(left) &&
145
+ (!right || /^\s/.test(right));
146
const rightNeedsBoundary =
144
- (!autoSpacing || /[\p{Script=Latin}\p{N}]$/u.test(replacement)) &&
145
- right !== undefined &&
146
- /[A-Za-z0-9([{'"]/.test(right) &&
147
- (left === undefined || /\s/.test(left));
147
+ (!auto || /(?:\p{Script=Latin}|\p{N})$/u.test(replacement)) &&
148
+ rightEdge.test(right) &&
149
+ (!left || /\s$/.test(left));
150
insertion = `${leftNeedsBoundary ? " " : ""}${replacement}${rightNeedsBoundary ? " " : ""}`;
151
}
152