feat(web): add text dictated with the iOS keyboard after 3 seconds

The installed iOS app has no speech recognition, so people dictate with the
keyboard's microphone, which only writes text into the input and never
ended it. Text that arrives without key presses (words or phrases at once,
or replacements) is now treated as a dictation: 3 seconds after the last
change it goes through the voice flow (AI split, "Deshacer"). Typing a key
cancels it; pastes and deletions never trigger it.

The form field is no longer called `name`, which made iOS offer to
autofill a contact into the add field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-10-28 19:41:39 -03:00
parent 48c0c83424
commit 9d4388ed8c
3 changed files with 157 additions and 18 deletions

View File

@@ -0,0 +1,29 @@
import { describe, expect, it } from 'vitest'
import { isDictatedInput } from './use-keyboard-dictation'
describe('isDictatedInput', () => {
it('takes words or phrases written without a key press as dictation', () => {
expect(isDictatedInput({ inputType: 'insertText', data: 'Yogur', msSinceKeydown: 5000 })).toBe(
true,
)
expect(
isDictatedInput({ inputType: 'insertReplacementText', data: null, msSinceKeydown: 5000 }),
).toBe(true)
})
it('does not take typing as dictation', () => {
expect(isDictatedInput({ inputType: 'insertText', data: 'Yogur', msSinceKeydown: 10 })).toBe(
false,
)
expect(isDictatedInput({ inputType: 'insertText', data: 'y', msSinceKeydown: 5000 })).toBe(
false,
)
})
it('never takes pastes, drops or deletions as dictation', () => {
for (const inputType of ['insertFromPaste', 'insertFromDrop', 'deleteContentBackward']) {
expect(isDictatedInput({ inputType, data: 'leche y pan', msSinceKeydown: 5000 })).toBe(false)
}
})
})