fix(mobile): drop smart-dash write-back recovery that kills iOS dictation

The longer-hyphen recovery path (#5222) reconstructed runs by writing a
value that differed from the native field text. After #7933 stores raw
field text and normalizes only on send/PTY, that recovery is unreachable
and any write-back would reintroduce dictation kill. Map each smart dash
to exactly "--" with a single-arg normalizer.
This commit is contained in:
Jinjing
2026-07-09 20:26:58 -07:00
parent 5662bf49d8
commit 341eba20b6
2 changed files with 5 additions and 20 deletions
@@ -11,10 +11,4 @@ describe('normalizeTerminalTextInput', () => {
it('keeps ASCII hyphens unchanged', () => {
expect(normalizeTerminalTextInput('git checkout -- file')).toBe('git checkout -- file')
})
it('preserves longer trailing hyphen runs when iOS re-collapses the controlled value', () => {
expect(normalizeTerminalTextInput('—', '--')).toBe('---')
expect(normalizeTerminalTextInput('—', '---')).toBe('----')
expect(normalizeTerminalTextInput('git checkout —', 'git checkout --')).toBe('git checkout ---')
})
})
@@ -1,18 +1,9 @@
// Why: iOS smart punctuation can rewrite two ASCII hyphens into a single
// Unicode dash before React Native delivers terminal text input.
// Unicode dash before React Native delivers terminal text input. Each dash maps
// to exactly "--": recovering longer runs (#5222) needed the previous controlled
// value written back into the field, and that write-back kills iOS dictation (#7925).
const IOS_SMART_DASH_REPLACEMENT_PATTERN = /[\u2013\u2014]/g
const IOS_SMART_DASH_REPLACEMENT_TEST = /[\u2013\u2014]/
export function normalizeTerminalTextInput(text: string, previousText = ''): string {
const normalizedText = text.replace(IOS_SMART_DASH_REPLACEMENT_PATTERN, '--')
const previousTrailingHyphens = /-+$/.exec(previousText)?.[0] ?? ''
const previousPrefix = previousText.slice(0, previousText.length - previousTrailingHyphens.length)
const collapsedPreviousHyphenRun =
previousTrailingHyphens.length >= 2 &&
IOS_SMART_DASH_REPLACEMENT_TEST.test(text) &&
(text === `${previousPrefix}\u2013` || text === `${previousPrefix}\u2014`)
if (collapsedPreviousHyphenRun) {
return `${previousText}-`
}
return normalizedText
export function normalizeTerminalTextInput(text: string): string {
return text.replace(IOS_SMART_DASH_REPLACEMENT_PATTERN, '--')
}