feat(desktop): built-in Han/Eng layout auto-switching, terminal/Vim support, and Unicode input
This commit is contained in:
parent
1da04b9e46
commit
a3ac44da2b
109 changed files with 8234 additions and 242 deletions
34
packages/core/__tests__/address-input.test.ts
Normal file
34
packages/core/__tests__/address-input.test.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// packages/core/__tests__/address-input.test.ts
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { isAddressInput } from '../src/input-intelligence'
|
||||
|
||||
describe('isAddressInput', () => {
|
||||
it('주소·경로·쿼리를 치는 중이면 true', () => {
|
||||
for (const prefix of [
|
||||
'https://youtube.com/shorts/32P7',
|
||||
'여기 봐 www.naver',
|
||||
'haramlog.app/ja/beta',
|
||||
'mail.google.com/mail/u/0/#inbox',
|
||||
'D:/workspace/맛집추천',
|
||||
'./src/main',
|
||||
'd3x9Z0iqC2/?stkn=em1z',
|
||||
'page?utm_source=meta'
|
||||
]) {
|
||||
expect(isAddressInput(prefix), prefix).toBe(true)
|
||||
}
|
||||
})
|
||||
|
||||
it('문장·숫자·띄어 쓴 뒤는 false', () => {
|
||||
for (const prefix of [
|
||||
'언제쯤일까?',
|
||||
'1/2 정도만',
|
||||
'네.좋아요',
|
||||
'v1.10.1 배포',
|
||||
'오늘 회의는 내일',
|
||||
'https://youtube.com 이거 봐 ',
|
||||
'ok'
|
||||
]) {
|
||||
expect(isAddressInput(prefix), prefix).toBe(false)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
@ -49,9 +49,11 @@ describe('케어렛 신뢰도', () => {
|
|||
expect(isEditAtTextEnd('aXb', 'ab')).toBe(false)
|
||||
})
|
||||
|
||||
it('값 끝에 줄끝 문자를 붙여 주는 입력칸(RichEdit·카카오톡)에서도 끝 편집을 알아본다', () => {
|
||||
it('값 끝에 줄끝 문자를 붙여 주는 입력칸(RichEdit·카카오톡)이나 공백 끝 교체에서도 끝 편집을 알아본다', () => {
|
||||
expect(isEditAtTextEnd('안녕\r', '안녕하\r')).toBe(true)
|
||||
expect(isEditAtTextEnd('오늘 회의 자\r\n', '오늘 회의 자료\r\n')).toBe(true)
|
||||
expect(isEditAtTextEnd('dkssud ', '안녕 ')).toBe(true)
|
||||
expect(isEditAtTextEnd('아 된다. ㅗ디ㅣㅐ ', '아 된다. hello ')).toBe(true)
|
||||
// 줄끝 문자 앞의 진짜 중간 편집은 여전히 중간 편집이다
|
||||
expect(isEditAtTextEnd('첫 문장. 둘째\r', '첫 문장이. 둘째\r')).toBe(false)
|
||||
})
|
||||
|
|
|
|||
54
packages/core/__tests__/personal-ngram.test.ts
Normal file
54
packages/core/__tests__/personal-ngram.test.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// packages/core/__tests__/personal-ngram.test.ts
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { PersonalNgramModel, predictPersonalContinuation } from '../src/personal-ngram'
|
||||
|
||||
function model(...texts: string[]): PersonalNgramModel {
|
||||
const built = new PersonalNgramModel()
|
||||
for (const text of texts) built.addText(text)
|
||||
return built
|
||||
}
|
||||
|
||||
describe('PersonalNgramModel', () => {
|
||||
it('단어를 끝냈으면 자주 이어 쓴 다음 어절과 짧은 구를 낸다', () => {
|
||||
const m = model('링크에서 확인할 수 있어요.', '앱에서 확인할 수 있어요.', '여기서 확인할 수 있어요')
|
||||
expect(m.predict('설정에서 확인할 ')).toMatchObject({ text: '수 있어요', joint: 'separate', support: 3 })
|
||||
})
|
||||
|
||||
it('단어 중간이면 그 어절의 나머지를 붙여 낸다', () => {
|
||||
const m = model('아기를 토닥여 줘요', '조금 토닥여 줬어요', '다시 토닥여 줘요')
|
||||
expect(m.predict('살살 토닥')).toMatchObject({ text: '여 줘요', joint: 'attach' })
|
||||
})
|
||||
|
||||
it('지지 횟수가 모자라거나 갈리면 내지 않는다', () => {
|
||||
expect(model('확인할 수 있어요').predict('확인할 ')).toBeNull()
|
||||
const split = model('그럼 이따가 봐', '그럼 내일 봐', '그럼 다음에 봐', '그럼 이따가 연락할게')
|
||||
expect(split.predict('그럼 ', { minConfidence: 0.6 })).toBeNull()
|
||||
expect(split.predict('그럼 ')).toMatchObject({ text: '이따가', support: 2 })
|
||||
})
|
||||
|
||||
it('문장 경계를 넘지 않고, 새 문장의 첫 어절은 예측하지 않는다', () => {
|
||||
const m = model('좋아요. 내일 봐요', '좋아요. 내일 봐요')
|
||||
expect(m.predict('좋아요. ')).toBeNull()
|
||||
expect(m.predict('좋아요 ')).toBeNull()
|
||||
})
|
||||
|
||||
it('따옴표·쉼표는 비교에서 떼고 대소문자를 가리지 않는다', () => {
|
||||
const m = model('Thank you so much', 'thank you, so much')
|
||||
expect(m.predict('Thank ')).toMatchObject({ text: 'you so much' })
|
||||
})
|
||||
|
||||
it('앱 예측: 공백 없이 멈췄어도 늘일 어절이 없으면 다음 어절을 띄어 쓰기로 낸다 ("그리고")', () => {
|
||||
const m = model('그리고 다음에 보자', '그리고 다음에 해', '그리고 오늘은 쉬자')
|
||||
expect(predictPersonalContinuation(m, '아 그리고')).toMatchObject({ text: '다음에', joint: 'separate' })
|
||||
})
|
||||
|
||||
it('앱 예측: 다음 어절이 갈려도 가장 흔한 것 하나는 내고, 둘째 어절은 확신할 때만 붙인다', () => {
|
||||
const m = model('그리고 다음에 보자', '그리고 다음에 해', '그리고 오늘은 쉬자', '그리고 내일 가자')
|
||||
expect(predictPersonalContinuation(m, '그리고 ')?.text).toBe('다음에')
|
||||
})
|
||||
|
||||
it('maxWords 까지만 늘인다', () => {
|
||||
const m = model('하나 둘 셋 넷 다섯', '하나 둘 셋 넷 다섯')
|
||||
expect(m.predict('하나 ', { maxWords: 2 })?.text).toBe('둘 셋')
|
||||
})
|
||||
})
|
||||
56
packages/core/__tests__/suggestion-confidence.test.ts
Normal file
56
packages/core/__tests__/suggestion-confidence.test.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// packages/core/__tests__/suggestion-confidence.test.ts
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { copiesContext, cutByConfidence } from '../src/suggestion-confidence'
|
||||
|
||||
const t = (token: string, logprob: number) => ({ token, logprob })
|
||||
|
||||
describe('cutByConfidence', () => {
|
||||
it('첫 어절이 자신 있으면 확률이 꺾이는 어절 앞까지 남긴다', () => {
|
||||
const tokens = [t(' 수', -0.05), t(' 있', -0.2), t('어요', -0.1), t(' 그런데', -2.5), t(' 다음', -0.1)]
|
||||
expect(cutByConfidence(tokens)).toEqual({ keepChars: ' 수 있어요'.length, firstWordLogprob: -0.05 })
|
||||
})
|
||||
|
||||
it('첫 어절 확률 합이 낮으면 버린다', () => {
|
||||
expect(cutByConfidence([t(' 다음', -0.6), t('에', -0.5), t(' 봐', -0.1)])).toBeNull()
|
||||
})
|
||||
|
||||
it('어절 중간 토큰에서 꺾이면 그 어절을 통째로 뺀다', () => {
|
||||
const tokens = [t(' 내일', -0.1), t(' 오', -0.2), t('후', -1.5)]
|
||||
expect(cutByConfidence(tokens)?.keepChars).toBe(' 내일'.length)
|
||||
})
|
||||
|
||||
it('첫 어절 중간에서 꺾이면 남는 게 없어 버린다', () => {
|
||||
expect(cutByConfidence([t(' 내', -0.1), t('일', -1.2)])).toBeNull()
|
||||
})
|
||||
|
||||
it('문장 끝 부호에서 멈춘다', () => {
|
||||
const tokens = [t(' 좋아요', -0.1), t('.', -0.05), t(' 그럼', -0.1)]
|
||||
expect(cutByConfidence(tokens)?.keepChars).toBe(' 좋아요.'.length)
|
||||
})
|
||||
|
||||
it('단어에 붙여 쓰는 첫 토큰(단어 중간 이어쓰기)도 첫 어절로 센다', () => {
|
||||
expect(cutByConfidence([t('어요', -0.2), t(' 그럼', -0.3)])).toEqual({
|
||||
keepChars: '어요 그럼'.length,
|
||||
firstWordLogprob: -0.2
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('copiesContext', () => {
|
||||
it('후보 앞부분이 문맥에 그대로 있으면 베낀 것', () => {
|
||||
expect(copiesContext('00달러 이렇게만 나오고 있거든.', '지금 결제창에 00달러 이렇게만 나오고 있거든. 확인해 줘')).toBe(true)
|
||||
})
|
||||
it('짧은 후보나 새 글은 아니다', () => {
|
||||
expect(copiesContext('수 있어요', '확인할 수 있어요')).toBe(false)
|
||||
expect(copiesContext('내일 오후에 다시 볼게', '오늘은 바빠서')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('splitFirstWord', () => {
|
||||
it('첫 어절(문장부호 포함)과 나머지로 나눈다', async () => {
|
||||
const { splitFirstWord } = await import('../src/suggestion-text')
|
||||
expect(splitFirstWord(' 내일 오후에 볼게.')).toEqual({ word: '내일', rest: '오후에 볼게.' })
|
||||
expect(splitFirstWord('좋아요, 그럼')).toEqual({ word: '좋아요,', rest: '그럼' })
|
||||
expect(splitFirstWord('볼게.')).toEqual({ word: '볼게.', rest: '' })
|
||||
})
|
||||
})
|
||||
|
|
@ -102,6 +102,18 @@ describe('extractContinuation', () => {
|
|||
extractContinuation('첨부 파일 검토해 보시고 의견 주세요.', { mode: 'complete-sentence', prefill: '첨부 파일 검토해 보시고' })?.text
|
||||
).toBe('의견 주세요.')
|
||||
})
|
||||
|
||||
it('프롬프트 지시문("검색어입니다.", "키워드 몇 개로만 짧게 이어 쓰세요.")을 되풀이한 출력은 즉시 버린다', () => {
|
||||
expect(
|
||||
extractContinuation(' 검색어입니다.', { mode: 'complete-sentence', prefill: '탭 추가 @ 기호' })
|
||||
).toBeNull()
|
||||
expect(
|
||||
extractContinuation(' 검색어 키워드 몇 개로만 짧게 이어 쓰세요.', {
|
||||
mode: 'complete-sentence',
|
||||
prefill: '탭 추가 @ 기호'
|
||||
})
|
||||
).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('문서 사실', () => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,13 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import { decideSuggestion, extractTerminalPromptPrefix, isTerminalApp } from '../src/input-intelligence'
|
||||
import {
|
||||
TerminalKeystrokeTracker,
|
||||
composeHangul2Set,
|
||||
decideSuggestion,
|
||||
extractTerminalActiveContext,
|
||||
extractTerminalPromptPrefix,
|
||||
isTerminalApp,
|
||||
isTerminalOrDeveloperSurface
|
||||
} from '../src/input-intelligence'
|
||||
|
||||
describe('terminal prompt extraction', () => {
|
||||
it('takes the Claude Code input line and ignores the status line below it', () => {
|
||||
|
|
@ -35,10 +43,291 @@ describe('terminal prompt extraction', () => {
|
|||
expect(extractTerminalPromptPrefix('output\n> ')).toBe('')
|
||||
})
|
||||
|
||||
it('recognises terminal apps', () => {
|
||||
it('recognises terminal apps and developer surfaces', () => {
|
||||
expect(isTerminalApp('WindowsTerminal.exe')).toBe(true)
|
||||
expect(isTerminalApp('Kitedesk.exe')).toBe(true)
|
||||
expect(isTerminalApp('wezterm-gui.exe')).toBe(true)
|
||||
expect(isTerminalApp('neovide.exe')).toBe(true)
|
||||
expect(isTerminalApp('KakaoTalk.exe')).toBe(false)
|
||||
expect(isTerminalApp(null)).toBe(false)
|
||||
expect(isTerminalOrDeveloperSurface('WindowsTerminal.exe')).toBe(true)
|
||||
expect(isTerminalOrDeveloperSurface('Kitedesk.exe')).toBe(true)
|
||||
expect(isTerminalOrDeveloperSurface('Code.exe')).toBe(true)
|
||||
expect(isTerminalOrDeveloperSurface('Agent Switchboard.exe')).toBe(true)
|
||||
expect(isTerminalOrDeveloperSurface('KakaoTalk.exe')).toBe(false)
|
||||
})
|
||||
|
||||
it('extracts active Vim insert line, command line, and normal mode from terminal screen snapshots', () => {
|
||||
const prevVim = ['hello world', '~', '~', '-- INSERT -- 1,12 All'].join(
|
||||
'\n'
|
||||
)
|
||||
const currVim = [
|
||||
'hello world dkssudgktpdy',
|
||||
'~',
|
||||
'~',
|
||||
'-- INSERT -- 1,25 All'
|
||||
].join('\n')
|
||||
|
||||
const insertCtx = extractTerminalActiveContext(prevVim, currVim)
|
||||
expect(insertCtx).toEqual({
|
||||
prefix: 'hello world dkssudgktpdy',
|
||||
caretReliable: true,
|
||||
vimMode: 'insert',
|
||||
isVimScreen: true
|
||||
})
|
||||
|
||||
const normalScreen = ['hello world', '~', '~', ' 1,11 All'].join(
|
||||
'\n'
|
||||
)
|
||||
const normalCtx = extractTerminalActiveContext(currVim, normalScreen)
|
||||
expect(normalCtx.vimMode).toBe('normal')
|
||||
expect(normalCtx.caretReliable).toBe(false)
|
||||
|
||||
const cmdScreen = ['hello world', '~', '~', ':ㅈㅂ'].join('\n')
|
||||
const cmdCtx = extractTerminalActiveContext(normalScreen, cmdScreen)
|
||||
expect(cmdCtx).toEqual({
|
||||
prefix: ':ㅈㅂ',
|
||||
caretReliable: true,
|
||||
vimMode: 'command',
|
||||
isVimScreen: true
|
||||
})
|
||||
})
|
||||
|
||||
it('composes 2-set Hangul and tracks Vim modes + trailing spaces in TerminalKeystrokeTracker', () => {
|
||||
expect(composeHangul2Set('dkssudgktpdy')).toBe('안녕하세요')
|
||||
expect(composeHangul2Set('wq')).toBe('ㅈㅂ')
|
||||
expect(composeHangul2Set('gtihubdp')).toBe('ㅎ샤ㅗㅕㅠ에')
|
||||
|
||||
const tracker = new TerminalKeystrokeTracker()
|
||||
const pressChar = (ch: string, koreanIme = false): void => {
|
||||
const upper = ch.toUpperCase()
|
||||
const vk = ch === ':' ? 0xba : ch === ' ' ? 0x20 : upper.charCodeAt(0)
|
||||
const shift = ch === ':' || (ch >= 'A' && ch <= 'Z')
|
||||
tracker.onKeyDown({
|
||||
hwnd: 101,
|
||||
vk,
|
||||
shift,
|
||||
ctrl: false,
|
||||
alt: false,
|
||||
meta: false,
|
||||
koreanIme
|
||||
})
|
||||
}
|
||||
|
||||
// Esc → Vim Normal mode (h/j/k/l ignored) → 'i' → Insert mode → 'dkssudgktpdy '
|
||||
tracker.onKeyDown({ hwnd: 101, vk: 0x1b, shift: false, ctrl: false, alt: false, meta: false })
|
||||
for (const ch of 'jjlli') pressChar(ch, false)
|
||||
expect(tracker.vimMode).toBe('insert')
|
||||
for (const ch of 'dkssudgktpdy ') pressChar(ch, false)
|
||||
expect(tracker.getSnapshot(101)).toEqual({
|
||||
prefix: 'dkssudgktpdy ',
|
||||
caretReliable: true,
|
||||
isComposing: false,
|
||||
vimMode: 'insert'
|
||||
})
|
||||
|
||||
// Windows Terminal strips trailing space from screen rows; reconcileWithScreen restores it
|
||||
const screenWithoutSpace = ['dkssudgktpdy', '~', '-- INSERT --'].join('\n')
|
||||
expect(tracker.reconcileWithScreen(screenWithoutSpace)).toEqual({
|
||||
prefix: 'dkssudgktpdy ',
|
||||
caretReliable: true,
|
||||
isComposing: false,
|
||||
vimMode: 'insert'
|
||||
})
|
||||
|
||||
// Programmatic replacement updates the tracked buffer
|
||||
tracker.applyReplacement('dkssudgktpdy '.length, '안녕하세요 ')
|
||||
expect(tracker.currentPrefix()).toBe('안녕하세요 ')
|
||||
|
||||
// Esc → ':' → 'wq' in Korean IME → ':ㅈㅂ'
|
||||
tracker.onKeyDown({ hwnd: 101, vk: 0x1b, shift: false, ctrl: false, alt: false, meta: false })
|
||||
expect(tracker.vimMode).toBe('normal')
|
||||
pressChar(':', true)
|
||||
expect(tracker.vimMode).toBe('command')
|
||||
pressChar('w', true)
|
||||
pressChar('q', true)
|
||||
expect(tracker.getSnapshot(101)).toEqual({
|
||||
prefix: ':ㅈㅂ',
|
||||
caretReliable: true,
|
||||
isComposing: true,
|
||||
vimMode: 'command'
|
||||
})
|
||||
})
|
||||
|
||||
it('reconciles IME VK_PROCESSKEY (vk=null) Hangul after : in Vim command line and shell prompts under nvim title', () => {
|
||||
const tracker = new TerminalKeystrokeTracker()
|
||||
const title = 'nvim - D3RO Terminal & Vim E2E'
|
||||
|
||||
// 1. Initial Vim normal screen
|
||||
expect(tracker.reconcileWithScreen('안녕하세요 \n~\n~\n', title)).toEqual({
|
||||
prefix: '',
|
||||
caretReliable: false,
|
||||
isComposing: false,
|
||||
vimMode: 'normal'
|
||||
})
|
||||
|
||||
// 2. ':' sent as hardware VK (0xba + Shift), followed by IME vk=null for 'ㅈ' and 'ㅂ'
|
||||
tracker.onKeyDown({ hwnd: 202, windowTitle: title, vk: 0xba, shift: true, ctrl: false, alt: false, meta: false })
|
||||
tracker.onKeyDown({ hwnd: 202, windowTitle: title, vk: null, shift: false, ctrl: false, alt: false, meta: false })
|
||||
tracker.onKeyDown({ hwnd: 202, windowTitle: title, vk: null, shift: false, ctrl: false, alt: false, meta: false })
|
||||
|
||||
expect(tracker.reconcileWithScreen('안녕하세요 \n~\n~\n:ㅈㅂ', title)).toEqual({
|
||||
prefix: ':ㅈㅂ',
|
||||
caretReliable: true,
|
||||
isComposing: false,
|
||||
vimMode: 'command'
|
||||
})
|
||||
tracker.applyReplacement(2, 'wq')
|
||||
|
||||
// 2b. Even if a stale ':wq' snapshot was reconciled right before a new ':ㅂ!' command line,
|
||||
// the rendered ':ㅂ!' command line must win over stale ':wq:!'.
|
||||
expect(tracker.reconcileWithScreen('안녕하세요 \n~\n~\n:wq', title)).toEqual({
|
||||
prefix: ':wq',
|
||||
caretReliable: true,
|
||||
isComposing: false,
|
||||
vimMode: 'command'
|
||||
})
|
||||
tracker.onKeyDown({ hwnd: 202, windowTitle: title, vk: 0xba, shift: true, ctrl: false, alt: false, meta: false })
|
||||
tracker.onKeyDown({ hwnd: 202, windowTitle: title, vk: null, shift: false, ctrl: false, alt: false, meta: false })
|
||||
tracker.onKeyDown({ hwnd: 202, windowTitle: title, vk: 0x31, shift: true, ctrl: false, alt: false, meta: false })
|
||||
expect(tracker.reconcileWithScreen('안녕하세요 \n~\n~\n:ㅂ!', title)).toEqual({
|
||||
prefix: ':ㅂ!',
|
||||
caretReliable: true,
|
||||
isComposing: false,
|
||||
vimMode: 'command'
|
||||
})
|
||||
|
||||
// 3. Shell prompt screen inside a window whose title still contains 'nvim'
|
||||
tracker.onPointerOrFocusChange(202)
|
||||
tracker.onKeyDown({ hwnd: 202, windowTitle: title, vk: null, shift: false, ctrl: false, alt: false, meta: false })
|
||||
tracker.onKeyDown({ hwnd: 202, windowTitle: title, vk: null, shift: false, ctrl: false, alt: false, meta: false })
|
||||
tracker.onKeyDown({ hwnd: 202, windowTitle: title, vk: 0x20, shift: false, ctrl: false, alt: false, meta: false })
|
||||
|
||||
expect(tracker.reconcileWithScreen('Windows PowerShell\nPS D:\\workspace> 퍄ㅡ ', title)).toEqual({
|
||||
prefix: 'PS D:\\workspace> 퍄ㅡ '.replace('PS D:\\workspace> ', ''),
|
||||
caretReliable: true,
|
||||
isComposing: false,
|
||||
vimMode: null
|
||||
})
|
||||
})
|
||||
|
||||
it('reconciles xterm-helper-textarea without repeating replacements when textarea.value stays stale', () => {
|
||||
const tracker = new TerminalKeystrokeTracker()
|
||||
const hwnd = 303
|
||||
const title = 'Agent Switchboard'
|
||||
|
||||
// User types 'h','e','l','l','o',' ' while koreanIme initially reported false on keydown
|
||||
for (const vk of [0x48, 0x45, 0x4c, 0x4c, 0x4f, 0x20]) {
|
||||
tracker.onKeyDown({
|
||||
hwnd,
|
||||
windowTitle: title,
|
||||
vk,
|
||||
shift: false,
|
||||
ctrl: false,
|
||||
alt: false,
|
||||
meta: false,
|
||||
koreanIme: false
|
||||
})
|
||||
}
|
||||
|
||||
// xterm-helper-textarea receives Hangul from IME ('ㅗ디ㅣㅐ '), proving Korean IME is active
|
||||
expect(tracker.reconcileWithXtermValue('ㅗ디ㅣㅐ ', hwnd, title)).toEqual({
|
||||
prefix: 'ㅗ디ㅣㅐ ',
|
||||
caretReliable: true,
|
||||
isComposing: false,
|
||||
vimMode: null
|
||||
})
|
||||
|
||||
// TypoCorrectionService replaces 'ㅗ디ㅣㅐ ' (6 chars) with 'hello '
|
||||
tracker.applyReplacement(6, 'hello ')
|
||||
|
||||
// Next snapshot 400ms later: xterm.textarea.value is STILL 'ㅗ디ㅣㅐ ' (xterm ignores Backspace/SendInput),
|
||||
// but reconcileWithXtermValue must return 'hello ' so it never loops into 'hhhhhhhhhhhello'!
|
||||
expect(tracker.reconcileWithXtermValue('ㅗ디ㅣㅐ ', hwnd, title)).toEqual({
|
||||
prefix: 'hello ',
|
||||
caretReliable: true,
|
||||
isComposing: false,
|
||||
vimMode: null
|
||||
})
|
||||
|
||||
// User continues typing 'w','o','r','l','d',' ' while Chromium HWND still reports koreanIme: false;
|
||||
// because _imm32Supported is false, koreanIme: false does NOT override _koreanIme = true!
|
||||
for (const vk of [0x57, 0x4f, 0x52, 0x4c, 0x44, 0x20]) {
|
||||
tracker.onKeyDown({
|
||||
hwnd,
|
||||
windowTitle: title,
|
||||
vk,
|
||||
shift: false,
|
||||
ctrl: false,
|
||||
alt: false,
|
||||
meta: false,
|
||||
koreanIme: false
|
||||
})
|
||||
}
|
||||
expect(tracker.reconcileWithXtermValue('ㅗ디ㅣㅐ재깅 ', hwnd, title)).toEqual({
|
||||
prefix: 'hello 재깅 ',
|
||||
caretReliable: true,
|
||||
isComposing: false,
|
||||
vimMode: null
|
||||
})
|
||||
tracker.applyReplacement(3, 'world ')
|
||||
expect(tracker.reconcileWithXtermValue('ㅗ디ㅣㅐ재깅 ', hwnd, title)).toEqual({
|
||||
prefix: 'hello world ',
|
||||
caretReliable: true,
|
||||
isComposing: false,
|
||||
vimMode: null
|
||||
})
|
||||
|
||||
// Even if the host app clears textarea.value to '' mid-line (e.g., on Space or compositionend),
|
||||
// the active line is preserved until Enter/Ctrl+C/Esc.
|
||||
expect(tracker.reconcileWithXtermValue('', hwnd, title)).toEqual({
|
||||
prefix: 'hello world ',
|
||||
caretReliable: true,
|
||||
isComposing: false,
|
||||
vimMode: null
|
||||
})
|
||||
|
||||
// Pressing Enter (0x0D) resets the tracked line
|
||||
tracker.onKeyDown({
|
||||
hwnd,
|
||||
windowTitle: title,
|
||||
vk: 0x0d,
|
||||
shift: false,
|
||||
ctrl: false,
|
||||
alt: false,
|
||||
meta: false
|
||||
})
|
||||
expect(tracker.reconcileWithXtermValue('', hwnd, title)).toEqual({
|
||||
prefix: '',
|
||||
caretReliable: false,
|
||||
isComposing: false,
|
||||
vimMode: null
|
||||
})
|
||||
|
||||
// Pressing Ctrl+C or Esc followed by 'git' or Korean 'dd' ('ㅇㅇ') must NOT falsely enter Vim mode
|
||||
tracker.onKeyDown({
|
||||
hwnd,
|
||||
windowTitle: title,
|
||||
vk: 0x1b,
|
||||
shift: false,
|
||||
ctrl: false,
|
||||
alt: false,
|
||||
meta: false
|
||||
})
|
||||
for (const vk of [0x47, 0x49, 0x54]) {
|
||||
tracker.onKeyDown({
|
||||
hwnd,
|
||||
windowTitle: title,
|
||||
vk,
|
||||
shift: false,
|
||||
ctrl: false,
|
||||
alt: false,
|
||||
meta: false,
|
||||
koreanIme: true
|
||||
})
|
||||
}
|
||||
expect(tracker.vimMode).toBeNull()
|
||||
expect(tracker.currentPrefix()).toBe('햣')
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,14 @@ describe('한영 전환 오타 판정', () => {
|
|||
expect(detectHangulTypedLatin('안녕', KO)).toBeNull()
|
||||
expect(detectHangulTypedLatin('회의', { hangul: 2, latin: 40 })).toBeNull()
|
||||
})
|
||||
|
||||
it('sometime(내ㅡㄷ샤ㅡㄷ), 연속 혼합 토큰(some샤ㅡㄷ), 영문 알파벳+조사(ㄴ가/ㄴ은)를 정확히 고친다', () => {
|
||||
expect(detectHangulTypedLatin('내ㅡㄷ샤ㅡㄷ', KO)).toBe('sometime')
|
||||
expect(detectHangulTypedLatin('some샤ㅡㄷ', KO)).toBe('sometime')
|
||||
expect(detectHangulTypedLatin('ㄴ가', KO)).toBe('s가')
|
||||
expect(detectHangulTypedLatin('ㄴ은', KO)).toBe('s은')
|
||||
expect(detectHangulTypedLatin('ㅠㅕㅎ가', KO)).toBe('bug가')
|
||||
})
|
||||
})
|
||||
|
||||
describe('늘 틀린 철자', () => {
|
||||
|
|
@ -278,3 +286,243 @@ describe('alignCorrectionToPrefix — 교정이 뜬 뒤 끝 공백만 달라져
|
|||
expect(alignCorrectionToPrefix('그ㅓ런\n', correction)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Araso 급 한/영 자동 전환 · 합성어 · 잔류 Shift · URL 런 보호', () => {
|
||||
const applyAll = (prefix: string): string => {
|
||||
const plan = planTypoReplacement(prefix, detectTypos(prefix, { includeTrailingToken: true }))
|
||||
if (!plan) return prefix
|
||||
return prefix.slice(0, prefix.length - plan.deleteCount) + plan.insertText
|
||||
}
|
||||
|
||||
it('잔류 Shift(빠른 쌍자음·복모음 뒤 대문자)를 한글로 정규화해 변환한다', () => {
|
||||
const cases: Array<[string, string]> = [
|
||||
['djEJs', '어떤'],
|
||||
['qkRNl', '바뀌'],
|
||||
['qkRNleh', '바뀌도'],
|
||||
['RNfdmf', '꿀을'],
|
||||
['EKfktj', '따라서'],
|
||||
['TkdRjvnf', '쌍꺼풀'],
|
||||
['TKdRJvnf', '쌍꺼풀'],
|
||||
['djEJfRkdy', '어떨까요'],
|
||||
['gkfRK', '할까'],
|
||||
['wlsWK', '진짜'],
|
||||
['TMfkrh', '쓰라고'],
|
||||
['qkRNjTdj', '바꿨어'],
|
||||
['ahtjflWHrdl', '모서리쪽이'],
|
||||
['RKwl', '까지'],
|
||||
['dPFmf', '예를'],
|
||||
['rOSp', '걔네'],
|
||||
['rPFks', '계란'],
|
||||
['dPDhl', '예외'],
|
||||
['dlTDj', '있어'],
|
||||
['dlTSp', '있네'],
|
||||
['qkRDp', '밖에']
|
||||
]
|
||||
for (const [keys, expected] of cases) {
|
||||
expect(detectLatinTypedHangul(keys, { hangul: 0, latin: 0 }), keys).toBe(expected)
|
||||
}
|
||||
})
|
||||
|
||||
it('잔류 Shift 로 설명되지 않는 영문 전용 대문자는 한글 문맥에서도 영문 그대로 둔다', () => {
|
||||
const words = [
|
||||
'Hello', 'API', 'TV', 'OK', 'QA', 'WE', 'QUICK', 'TEst', 'iPhone', 'GitHub', 'dHello',
|
||||
'TM', 'EU', 'RN', 'TL', 'THe', 'WHat', 'THis', 'QUery', 'tvOS', 'PCqkd', 'OAuth', 'TFxla',
|
||||
'PDF', 'WWDC'
|
||||
]
|
||||
for (const word of words) {
|
||||
expect(detectLatinTypedHangul(word, KO), word).toBeNull()
|
||||
}
|
||||
})
|
||||
|
||||
it('영단어·약어·고유명사 + 한국어 조사/어미 합성어를 분리 변환한다', () => {
|
||||
const cases: Array<[string, string]> = [
|
||||
['githubdp', 'github에'],
|
||||
['APIfmf', 'API를'],
|
||||
['commitgotj', 'commit해서'],
|
||||
['serverdptj', 'server에서'],
|
||||
['pythondmfh', 'python으로'],
|
||||
['deploygoTdj', 'deploy했어'],
|
||||
['TextEditdptj', 'TextEdit에서'],
|
||||
['Slackdptj', 'Slack에서'],
|
||||
['VSCodedptj', 'VSCode에서'],
|
||||
['GitHubdp', 'GitHub에'],
|
||||
['iPhonedptj', 'iPhone에서'],
|
||||
['TVdp', 'TV에'],
|
||||
['QAfmf', 'QA를'],
|
||||
['RNdms', 'RN은'],
|
||||
['UIrkxdmsrjs', 'UI같은건'],
|
||||
['UIdp', 'UI에'],
|
||||
['AIrk', 'AI가'],
|
||||
['githubrkxdmsep', 'github같은데'],
|
||||
['xdp', 'x에'],
|
||||
['Xfmf', 'X를']
|
||||
]
|
||||
for (const [keys, expected] of cases) {
|
||||
expect(detectLatinTypedHangul(keys, { hangul: 0, latin: 0 }), keys).toBe(expected)
|
||||
}
|
||||
})
|
||||
|
||||
it('2글자 약어의 받침 호응(TM은/TL을 vs 쓰는/씨에)을 구별한다', () => {
|
||||
for (const [keys, expected] of [
|
||||
['TMdms', 'TM은'],
|
||||
['TMdmf', 'TM을'],
|
||||
['TLdms', 'TL은'],
|
||||
['TLdmf', 'TL을'],
|
||||
['ELdl', 'EL이'],
|
||||
['ELdms', 'EL은'],
|
||||
['RJdmf', 'RJ을'],
|
||||
['RJdl', 'RJ이'],
|
||||
['TMsms', '쓰는'],
|
||||
['RNsms', '꾸는'],
|
||||
['TLdp', '씨에'],
|
||||
['Tkfdmf', '쌀을'],
|
||||
['Tlsms', '씨는']
|
||||
] as const) {
|
||||
expect(detectLatinTypedHangul(keys, { hangul: 0, latin: 0 }), keys).toBe(expected)
|
||||
}
|
||||
})
|
||||
|
||||
it('영문+한글 단어 및 한글+영문 단어 합성어를 분리 변환한다', () => {
|
||||
for (const [keys, expected] of [
|
||||
['hellodnjfem', 'hello월드'],
|
||||
['githubtjqj', 'github서버'],
|
||||
['loginghkaus', 'login화면'],
|
||||
['designvhsxm', 'design폰트'],
|
||||
['Reactzjavhsjsxm', 'React컴포넌트'],
|
||||
['VSCodetjfwjd', 'VSCode설정'],
|
||||
['PDFvkdlf', 'PDF파일'],
|
||||
['WWDCvhfja', 'WWDC포럼'],
|
||||
['OAuthdlswmd', 'OAuth인증'],
|
||||
['RPAdlswmd', 'RPA인증'],
|
||||
['TPSvkdlf', 'TPS파일'],
|
||||
['EUwjdcor', 'EU정책'],
|
||||
['TUtjqj', 'TU서버'],
|
||||
['TBvkdlf', 'TB파일'],
|
||||
['ETLwjdcor', 'ETL정책'],
|
||||
['TTLtjfwjd', 'TTL설정'],
|
||||
['PCzkxhrdptj', 'PC카톡에서'],
|
||||
['APIzkxhrdptj', 'API카톡에서'],
|
||||
['dhsmfdmsgoogledptj', '오늘은google에서']
|
||||
] as const) {
|
||||
expect(detectLatinTypedHangul(keys, { hangul: 0, latin: 0 }), keys).toBe(expected)
|
||||
}
|
||||
})
|
||||
|
||||
it('한영 키를 누르지 않고 이어 친 문장 전체를 자연스럽게 변환한다', () => {
|
||||
expect(applyAll('Stay hungry, stay foolishsms wkqtmdml akfdlek.')).toBe(
|
||||
'Stay hungry, stay foolish는 잡스의 말이다.'
|
||||
)
|
||||
expect(applyAll('dlrjs githubdp commitgkf rjdi.')).toBe('이건 github에 commit할 거야.')
|
||||
expect(applyAll('dlrjs github dp commit gkf rjdi')).toBe('이건 github 에 commit 할 거야')
|
||||
expect(applyAll('tmvmfls API qkfvy wnsql')).toBe('스프린 API 발표 준비')
|
||||
expect(applyAll("let's go")).toBe("let's go")
|
||||
expect(applyAll('dlrj go')).toBe('이거 해')
|
||||
expect(applyAll('dhsmf 3tl')).toBe('오늘 3시')
|
||||
})
|
||||
|
||||
it('한글 자판 상태에서 친 영단어·영단어+조사를 한글 문맥 안에서도 복원한다', () => {
|
||||
expect(detectHangulTypedLatin('ㅗ디ㅣㅐ', KO)).toBe('hello')
|
||||
expect(detectHangulTypedLatin('ㅎ샤ㅗㅕㅠ', KO)).toBe('github')
|
||||
expect(detectHangulTypedLatin('ㅎ샤ㅗㅕㅠ에', KO)).toBe('github에')
|
||||
expect(detectHangulTypedLatin('메ㅔ을', KO)).toBe('app을')
|
||||
expect(applyAll('오늘 ㅎ샤ㅗㅕㅠ에 올렸어요 ')).toBe('오늘 github에 올렸어요 ')
|
||||
})
|
||||
|
||||
it('URL · 경로 · 이메일 런은 보존하되 멘션·슬래시 쌍·약어 조사는 변환한다', () => {
|
||||
for (const urlText of [
|
||||
'https://example.com/dl ',
|
||||
'https://a.io/?q=dl&p=sk ',
|
||||
'cd ~/src/rk ',
|
||||
'www.ak.com/bb ',
|
||||
'/usr/lib/dl ',
|
||||
'./ak/sk ',
|
||||
'http://localhost:3000/dl ',
|
||||
'localhost:3000/dl ',
|
||||
'x@gmail.com '
|
||||
]) {
|
||||
expect(applyAll(urlText), urlText).toBe(urlText)
|
||||
}
|
||||
expect(applyAll('@dlrjs ')).toBe('@이건 ')
|
||||
expect(applyAll('ska/du ')).toBe('남/여 ')
|
||||
expect(applyAll('TV/fkeldh ')).toBe('TV/라디오 ')
|
||||
expect(applyAll('L.A.fh ')).toBe('L.A.로 ')
|
||||
expect(applyAll('1:1ansdml ')).toBe('1:1문의 ')
|
||||
expect(applyAll('/sk ')).toBe('/나 ')
|
||||
})
|
||||
|
||||
it('단어 중간에 잠시 멈춰 앞부분이 먼저 변환된 뒤 이어 친 토큰도 자연스럽게 재결합한다', () => {
|
||||
expect(detectLatinTypedHangul('안녕gktpdy', KO)).toBe('안녕하세요')
|
||||
expect(detectLatinTypedHangul('안녀d', KO)).toBe('안녕')
|
||||
expect(detectLatinTypedHangul('회의dp', KO)).toBe('회의에')
|
||||
expect(detectLatinTypedHangul('github에tj', KO)).toBe('github에서')
|
||||
expect(detectLatinTypedHangul('오늘meeting', KO)).toBeNull()
|
||||
expect(detectLatinTypedHangul('카카오API', KO)).toBeNull()
|
||||
expect(detectHangulTypedLatin('hellㅐ', KO)).toBe('hello')
|
||||
expect(detectHangulTypedLatin('githuㅠ', KO)).toBe('github')
|
||||
expect(detectHangulTypedLatin('github에', KO)).toBeNull()
|
||||
})
|
||||
|
||||
it('한글 자판 상태로 친 영문 문장 전체(2글자 단어·I·굴절형·기능어 포함)를 정확히 영문으로 복원한다', () => {
|
||||
expect(applyAll('ㅑㄹ ㅑ 쇼ㅔㄷ ㅗ디ㅣㅐ 소두 ㅑㅅ 초뭏ㄷㄴ ㅑㅜ 10 ㄴㄷ채ㅜㅇㄴ')).toBe(
|
||||
'if I type hello then it changes in 10 seconds'
|
||||
)
|
||||
expect(applyAll('ㅑㄹ ㅑ 쇼ㅔㄷ hello 소두 ㅑㅅ 초뭏ㄷㄴ ㅑㅜ 10 ㄴㄷ채ㅜㅇㄴ')).toBe(
|
||||
'if I type hello then it changes in 10 seconds'
|
||||
)
|
||||
expect(applyAll('거의 30 ㄴㄷ채ㅜㅇㄴ 걸리는 것 같음.')).toBe('거의 30 seconds 걸리는 것 같음.')
|
||||
expect(applyAll('ㅗ디ㅣㅐ 재깅 ')).toBe('hello world ')
|
||||
expect(applyAll('ㅗ디ㅣㅐ재깅 ')).toBe('hello world ')
|
||||
expect(applyAll('hello재깅 ')).toBe('hello world ')
|
||||
expect(applyAll('ㅖㅇㄹ파일 ')).toBe('PDF파일 ')
|
||||
expect(applyAll('ㅁㅔㅑ키 ')).toBe('API키 ')
|
||||
expect(
|
||||
detectTypos('ㅗ디ㅣㅐ ', {
|
||||
includeTrailingToken: true,
|
||||
ignoredWords: ['ㅗ디ㅣㅐ']
|
||||
})
|
||||
).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('터미널·Vim 명령줄(:ㅈㅂ → :wq, :ㅂ! → :q!)과 CLI 명령어(퍙 → vim, ㅣㄴ → ls, 채ㅜㄴㅅ → const)를 복원한다', () => {
|
||||
const applyTerminal = (prefix: string): { result: string; deleteCount: number } => {
|
||||
const plan = planTypoReplacement(
|
||||
prefix,
|
||||
detectTypos(prefix, { includeTrailingToken: true, layoutOnly: true, terminalMode: true })
|
||||
)
|
||||
if (!plan) return { result: prefix, deleteCount: 0 }
|
||||
return {
|
||||
result: prefix.slice(0, prefix.length - plan.deleteCount) + plan.insertText,
|
||||
deleteCount: plan.deleteCount
|
||||
}
|
||||
}
|
||||
|
||||
// ':' 는 지우지 않고 뒤의 한글 명령만 지워 영문 Ex 명령으로 바꾼다
|
||||
expect(applyTerminal(':ㅈㅂ')).toEqual({ result: ':wq', deleteCount: 2 })
|
||||
expect(applyTerminal(':ㅈㅂ!')).toEqual({ result: ':wq!', deleteCount: 3 })
|
||||
expect(applyTerminal(':ㅈ')).toEqual({ result: ':w', deleteCount: 1 })
|
||||
expect(applyTerminal(':ㅂ')).toEqual({ result: ':q', deleteCount: 1 })
|
||||
expect(applyTerminal(':ㅂ!')).toEqual({ result: ':q!', deleteCount: 2 })
|
||||
expect(applyTerminal(':ㅌ')).toEqual({ result: ':x', deleteCount: 1 })
|
||||
expect(applyTerminal(':ㅍ네')).toEqual({ result: ':vsp', deleteCount: 2 })
|
||||
expect(applyTerminal(':네')).toEqual({ result: ':sp', deleteCount: 1 })
|
||||
expect(applyTerminal(':ㅜㅐㅗ')).toEqual({ result: ':noh', deleteCount: 3 })
|
||||
|
||||
// 셸·코드 키워드 복원
|
||||
expect(applyTerminal('퍄ㅡ ').result).toBe('vim ')
|
||||
expect(applyTerminal('ㅜ퍄ㅡ ').result).toBe('nvim ')
|
||||
expect(applyTerminal('ㅣㄴ ').result).toBe('ls ')
|
||||
expect(applyTerminal('채ㅜㄴㅅ ').result).toBe('const ')
|
||||
expect(applyTerminal('ㅎ샤 commit ').result).toBe('git commit ')
|
||||
expect(applyTerminal('햣 commit ').result).toBe('git commit ')
|
||||
|
||||
// Vim 노멀 모드에서 i/a/o 를 눌러 입력 모드로 들어간 직후 친 영→한은 앞의 i/a/o 를 지우지 않는다
|
||||
expect(applyTerminal('idkssudgktpdy ')).toEqual({
|
||||
result: 'i안녕하세요 ',
|
||||
deleteCount: 'dkssudgktpdy '.length
|
||||
})
|
||||
expect(applyTerminal('adkssudgktpdy ')).toEqual({
|
||||
result: 'a안녕하세요 ',
|
||||
deleteCount: 'dkssudgktpdy '.length
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue