fix(input,core): fix live punctuation typo triggers, expected insert cleanup, and ngram scan

This commit is contained in:
Yun Chan 2026-11-14 15:14:53 +09:00
parent a37dd63909
commit 2a009e421a
8 changed files with 640 additions and 53 deletions

View file

@ -734,4 +734,27 @@ describe('Araso 급 한/영 자동 전환 · 합성어 · 잔류 Shift · URL
expect(applyAll('윈도우ㅐㄴ ')).toBe('윈도우OS ')
expect(applyAll('새ㅁㅔㅑ를 ')).toBe('새API를 ')
})
it('detectTypos_한글말줄임표뒤영타_한글로복원하고코드전개와파일확장자는보존한다', () => {
expect(applyAll('상황 잘 지켜보는중...dbrlgkrhdlTwlsdksgwl?')).toBe(
'상황 잘 지켜보는중...유기하고있진않지?'
)
expect(applyAll('어떻게해..dlrj?')).toBe('어떻게해..이거?')
expect(applyAll('파일.tsx?raw')).toBe('파일.tsx?raw')
expect(applyAll('...props')).toBe('...props')
expect(applyAll('return ...opts')).toBe('return ...opts')
})
it('detectTypos_URL쿼리스트링뒤영타_변환하지않는다', () => {
expect(applyAll('상황 잘 지켜보는중?dbrlgkrhdlTwlsdksgwl?')).toBe(
'상황 잘 지켜보는중?유기하고있진않지?'
)
expect(applyAll('example.com?dbrlgkrhdlTwlsdksgwl')).toBe('example.com?dbrlgkrhdlTwlsdksgwl')
expect(applyAll('site.kr?dbrlgkrhdlTwlsdksgwl')).toBe('site.kr?dbrlgkrhdlTwlsdksgwl')
})
it('detectTypos_물결표및전각부호경계오타_영문과한글모두복원한다', () => {
expect(applyAll('상황 잘 지켜보는중~ㅗ디ㅣㅐ~')).toBe('상황 잘 지켜보는중~hello~')
expect(applyAll('지금 어디야?dbrlgkrhdlTwlsdksgwl?')).toBe('지금 어디야?유기하고있진않지?')
})
})

View file

@ -947,11 +947,11 @@ export function isUrlOrPathRun(prefix: string, tokenStart: number, tokenEnd: num
if (run.includes('://')) return true
if (/^(?:www\.|~\/|\.\/|\.\.\/|localhost:)/iu.test(run)) return true
if ((run.match(/\//gu)?.length ?? 0) >= 2) return true
if (/[A-Za-z0-9]\.[A-Za-z]{2,}\//u.test(run)) return true
if (/[A-Za-z0-9]\.[A-Za-z]{2,}[/?]/u.test(run)) return true
if (/[A-Za-z0-9._+-]@[A-Za-z0-9]/u.test(run)) return true
if (/[\\_$#`<>{}=]/u.test(run)) return true
// 토큰 바로 앞이나 뒤가 도메인 점(example.com)인 경우 (단, L.A.fh 처럼 대문자 약어 뒤 조사는 허용)
// 토큰 바로 앞이나 뒤가 도메인 점(example.com)인 경우 (단, L.A.fh 처럼 대문자 약어 뒤 조사와 한글 말줄임표(...) 뒤 한영 오타는 허용)
const before = prefix[tokenStart - 1] ?? ''
const after = prefix[tokenEnd] ?? ''
if (after === '.' && /[A-Za-z]/u.test(prefix[tokenEnd + 1] ?? '')) return true
@ -959,7 +959,8 @@ export function isUrlOrPathRun(prefix: string, tokenStart: number, tokenEnd: num
const beforeDot = prefix.slice(runStart, tokenStart)
const tokenText = prefix.slice(tokenStart, tokenEnd)
const isAbbrevWithParticle = /^(?:[A-Z]\.){2,}$/u.test(beforeDot) && PARTICLE_KEYS.has(tokenText)
if (!isAbbrevWithParticle) return true
const isHangulEllipsis = /[가-힣ㄱ-ㆎ][!?~]*\.{2,}$/u.test(beforeDot)
if (!isAbbrevWithParticle && !isHangulEllipsis) return true
}
if (before === ':' || after === ':') {
const beforeColon = prefix.slice(runStart, tokenStart)

View file

@ -169,8 +169,7 @@ export class PersonalNgramModel {
const extends_ = (word: string) => word.length > partial.length && word.startsWith(partial)
first = context.length > 0 ? this._next(context, extends_, passes) : null
if (!first) {
const unigram = new Map([...this._unigram].filter(([word]) => extends_(word)))
const pick = best(unigram, () => true)
const pick = best(this._unigram, extends_)
first = passes(pick) ? pick : null
}
joint = 'attach'

View file

@ -2024,6 +2024,8 @@ function resolveTokenAsEnglishPreview(tokenText: string): string | null {
return null
}
const WORD_BOUNDARY_AFTER_RE = /[ \t.,!?;:~…?!。]/u
/**
* 커서 앞 구간에서 결정적으로 확실한 오타를 찾는다.
*
@ -2120,7 +2122,7 @@ export function detectTypos(prefix: string, options: TypoDetectOptions = {}): Ty
afterEnglishWord,
nextIsEnglish,
nextEnglishWord,
hasWordBoundaryAfter: /[ \t.,!?;:]/u.test(after),
hasWordBoundaryAfter: WORD_BOUNDARY_AFTER_RE.test(after),
vocabulary: options.vocabulary
})
@ -2199,7 +2201,7 @@ export function detectTypos(prefix: string, options: TypoDetectOptions = {}): Ty
!options.terminalMode &&
/^(?:self|selves)$/iu.test(token.text) &&
index > 0 &&
(/[ \t.,!?;:]/u.test(after) || !options.layoutOnly)
(WORD_BOUNDARY_AFTER_RE.test(after) || !options.layoutOnly)
) {
const prevToken = tokens[index - 1]
if (