fix(desktop): prevent fast correction input races

This commit is contained in:
Yun Chan 2026-11-04 07:06:10 +09:00
parent 5ec063c744
commit 21a684d572
12 changed files with 134 additions and 18 deletions

View file

@ -100,6 +100,25 @@ describe('TypoCorrectionService', () => {
expect(corrected).toHaveBeenCalledTimes(1)
})
it('빠른 연속 입력의 부분 교정은 미루고 멈춘 뒤 현재 영역 전체를 한 번에 교정한다', async () => {
const fake = deps()
const service = new TypoCorrectionService(fake.deps)
const prefix = 'dkssudgktpdy rkatkgkqslek qksrkqtmqslek '.repeat(3)
const expected = '안녕하세요 감사합니다 반갑습니다 '.repeat(3)
expect(
service.handleTypingContext(typingContext({ prefix, idleMs: 380 }), { trailingWordOnly: true })
).toBe('pass')
expect(fake.replaceBeforeCaret).not.toHaveBeenCalled()
expect(
service.handleTypingContext(typingContext({ prefix, idleMs: 650 }), { trailingWordOnly: true })
).toBe('correcting')
await flush()
expect(fake.replaceBeforeCaret).toHaveBeenCalledTimes(1)
expect(fake.replaceBeforeCaret).toHaveBeenCalledWith(prefix.length, expected)
})
it('아직 치는 중이면(유휴 부족) 고치지 않는다', () => {
const fake = deps()
const service = new TypoCorrectionService(fake.deps)

View file

@ -25,6 +25,8 @@ import {
interface Internal {
_handleKeyDown(event: { keycode: number; ctrlKey: boolean; altKey: boolean; metaKey: boolean; shiftKey: boolean }): void
_scheduleTextSnapshot(keyClass?: 'letter' | 'space'): void
_captureTextSnapshot: () => Promise<null>
_lastTypedAt: number
}
@ -53,4 +55,25 @@ describe('IME 글자 키', () => {
service._handleKeyDown(key(0))
expect(service._lastTypedAt).toBe(0)
})
it('단어 경계 교정 스냅샷은 140ms 동안 추가 입력이 없을 때만 실행한다', () => {
vi.useFakeTimers()
try {
const service = getInputTelemetryService() as unknown as Internal
const capture = vi.fn(async () => null)
service._captureTextSnapshot = capture
service._scheduleTextSnapshot('space')
vi.advanceTimersByTime(139)
service._scheduleTextSnapshot('letter')
vi.advanceTimersByTime(1)
expect(capture).not.toHaveBeenCalled()
service._scheduleTextSnapshot('space')
vi.advanceTimersByTime(140)
expect(capture).toHaveBeenCalledTimes(1)
} finally {
vi.useRealTimers()
}
})
})