fix(suggestion): keep a shown typo fix when only trailing spaces changed before accepting

The session ignores trailing whitespace but acceptance compared the raw
prefix, so typing one more space after the fix appeared made accept drop
the correction silently and leave the typo in place.
This commit is contained in:
Yun Chan 2026-10-20 16:27:40 +09:00
parent 1b39afe9ff
commit 32cf826290
3 changed files with 45 additions and 1 deletions

View file

@ -18,6 +18,7 @@ import {
latinToHangul,
parseModelTypoPairs,
planTypoReplacement,
alignCorrectionToPrefix,
validateModelCorrections,
typoRegionStart,
validateModelCorrections
@ -255,3 +256,25 @@ describe('낱자 잡음 (2026-10-17 실측 입력)', () => {
expect(planTypoReplacement(text, mergeTypoCorrections(model, detectJamoNoise(text)))?.insertText).toBe('안녕하세요.?')
})
})
describe('alignCorrectionToPrefix — 교정이 뜬 뒤 끝 공백만 달라져도 수락한다', () => {
const correction = { from: '그ㅓ런', to: '그런', edits: [] }
it('원문이 그대로면 교정을 그대로 돌려준다', () => {
expect(alignCorrectionToPrefix('그ㅓ런', correction)).toBe(correction)
})
it('공백을 더 쳤으면 그 공백까지 지우고 다시 붙인다', () => {
expect(alignCorrectionToPrefix('음 그ㅓ런 ', correction)).toEqual({ ...correction, from: '그ㅓ런 ', to: '그런 ' })
})
it('교정 뒤 공백을 지웠으면 지금 원문에 맞춘다', () => {
const spaced = { from: '그ㅓ런 ', to: '그런 ', edits: [] }
expect(alignCorrectionToPrefix('그ㅓ런', spaced)).toEqual({ ...spaced, from: '그ㅓ런', to: '그런' })
})
it('글자가 바뀌었거나 줄바꿈이 끼면 버린다', () => {
expect(alignCorrectionToPrefix('그ㅓ러', correction)).toBeNull()
expect(alignCorrectionToPrefix('그ㅓ런\n', correction)).toBeNull()
})
})