fix(desktop): prevent Korean character swallowing in terminal and xterm.js surfaces (INPUT-04, INPUT-19)
This commit is contained in:
parent
f18cebaa24
commit
61123b5ad8
11 changed files with 264 additions and 50 deletions
|
|
@ -444,6 +444,7 @@ export class TerminalKeystrokeTracker {
|
|||
private _composingKeys = ''
|
||||
private _koreanIme = false
|
||||
private _imm32Supported = false
|
||||
private _imeObserved = false
|
||||
private _lastImeToggleAt = 0
|
||||
private _vimSession = false
|
||||
private _vimMode: TerminalVimMode = null
|
||||
|
|
@ -466,10 +467,32 @@ export class TerminalKeystrokeTracker {
|
|||
this._unreplacedStart = 0
|
||||
}
|
||||
|
||||
hasObservedImeForHwnd(hwnd: number | null): boolean {
|
||||
return hwnd !== null && this._hwnd === hwnd && this._imeObserved
|
||||
}
|
||||
|
||||
/**
|
||||
* 키다운 훅 도중(WM_KEYDOWN 처리 중)이 아니라 유휴 스냅샷 시점에 관측한 IME 상태를 반영한다.
|
||||
* 포커스 직후 첫 스냅샷에서 한글 IME 가 감지되면 아직 치환되지 않은 영문 키 꼬리를 두벌식 한글로 복원한다.
|
||||
*/
|
||||
syncKoreanIme(koreanIme: boolean | null | undefined): void {
|
||||
this._imeObserved = true
|
||||
if (typeof koreanIme !== 'boolean') return
|
||||
if (koreanIme) {
|
||||
this._imm32Supported = true
|
||||
this._koreanIme = true
|
||||
this._convertUnreplacedAsciiTailToHangul()
|
||||
} else if (this._imm32Supported) {
|
||||
this._flushComposing()
|
||||
this._koreanIme = false
|
||||
}
|
||||
}
|
||||
|
||||
onPointerOrFocusChange(hwnd?: number | null): void {
|
||||
if (hwnd !== undefined && hwnd !== this._hwnd) {
|
||||
this._hwnd = hwnd
|
||||
this._imm32Supported = false
|
||||
this._imeObserved = false
|
||||
this._vimSession = false
|
||||
this._vimMode = null
|
||||
this._shellPromptScreen = false
|
||||
|
|
@ -484,6 +507,7 @@ export class TerminalKeystrokeTracker {
|
|||
if (input.hwnd !== null && input.hwnd !== this._hwnd) {
|
||||
this._hwnd = input.hwnd
|
||||
this._imm32Supported = false
|
||||
this._imeObserved = false
|
||||
this._vimSession = false
|
||||
this._vimMode = null
|
||||
this._shellPromptScreen = false
|
||||
|
|
@ -511,6 +535,7 @@ export class TerminalKeystrokeTracker {
|
|||
this._afterEscape = false
|
||||
}
|
||||
this._koreanIme = !this._koreanIme
|
||||
this._imeObserved = true
|
||||
this._lastImeToggleAt = now
|
||||
return
|
||||
}
|
||||
|
|
@ -519,6 +544,7 @@ export class TerminalKeystrokeTracker {
|
|||
// ImmGetDefaultIMEWnd(IMC_GETCONVERSIONMODE)가 한글 상태에서도 항상 false(0)를 돌려준다.
|
||||
// 따라서 해당 창에서 한 번이라도 true 가 관측된 경우(_imm32Supported)에만 false 로의 하향 동기화를 허용한다.
|
||||
if (typeof input.koreanIme === 'boolean') {
|
||||
this._imeObserved = true
|
||||
if (input.koreanIme) {
|
||||
this._imm32Supported = true
|
||||
}
|
||||
|
|
@ -792,6 +818,14 @@ export class TerminalKeystrokeTracker {
|
|||
resolved = resolved.trimEnd() + ' '
|
||||
}
|
||||
|
||||
if (/[가-힣ㄱ-ㆎ]\s*$/u.test(resolved)) {
|
||||
this._koreanIme = true
|
||||
this._imeObserved = true
|
||||
this._convertUnreplacedAsciiTailToHangul()
|
||||
} else if (/[A-Za-z]\s*$/u.test(resolved)) {
|
||||
this._imeObserved = true
|
||||
}
|
||||
|
||||
this._lastScreenPrefix = resolved
|
||||
return {
|
||||
prefix: resolved,
|
||||
|
|
@ -818,6 +852,7 @@ export class TerminalKeystrokeTracker {
|
|||
if (hwnd !== null && this._hwnd !== null && hwnd !== this._hwnd) {
|
||||
this._hwnd = hwnd
|
||||
this._imm32Supported = false
|
||||
this._imeObserved = false
|
||||
this._vimSession = false
|
||||
this._vimMode = null
|
||||
this._shellPromptScreen = false
|
||||
|
|
@ -829,20 +864,16 @@ export class TerminalKeystrokeTracker {
|
|||
/[가-힣ㄱ-ㆎ]\s*$/u.test(raw) && raw.trimEnd() !== this._lastXtermValue.trimEnd()
|
||||
if (hasNewHangul) {
|
||||
this._koreanIme = true
|
||||
const unreplacedTail = this._committed.slice(this._unreplacedStart)
|
||||
if (/[A-Za-z]/u.test(unreplacedTail) && !/[가-힣ㄱ-ㆎ]/u.test(unreplacedTail)) {
|
||||
const convertedTail = unreplacedTail.replace(/[A-Za-z]+/gu, (word) => {
|
||||
const norm = word.replace(/[A-Z]/gu, (c) => (/^[QWERTPO]$/u.test(c) ? c : c.toLowerCase()))
|
||||
return composeHangul2Set(norm)
|
||||
})
|
||||
this._committed = this._committed.slice(0, this._unreplacedStart) + convertedTail
|
||||
} else if (
|
||||
this._unreplacedStart === 0 &&
|
||||
this._lastXtermValue === '' &&
|
||||
this._committed.length === 0 &&
|
||||
this._composingKeys.length === 0
|
||||
) {
|
||||
this._committed = raw
|
||||
this._imeObserved = true
|
||||
if (!this._convertUnreplacedAsciiTailToHangul()) {
|
||||
if (
|
||||
this._unreplacedStart === 0 &&
|
||||
this._lastXtermValue === '' &&
|
||||
this._committed.length === 0 &&
|
||||
this._composingKeys.length === 0
|
||||
) {
|
||||
this._committed = raw
|
||||
}
|
||||
}
|
||||
}
|
||||
this._lastXtermValue = raw
|
||||
|
|
@ -850,6 +881,19 @@ export class TerminalKeystrokeTracker {
|
|||
return this.getSnapshot(hwnd, windowTitle)
|
||||
}
|
||||
|
||||
private _convertUnreplacedAsciiTailToHangul(): boolean {
|
||||
const unreplacedTail = this._committed.slice(this._unreplacedStart)
|
||||
if (/[A-Za-z]/u.test(unreplacedTail) && !/[가-힣ㄱ-ㆎ]/u.test(unreplacedTail)) {
|
||||
const convertedTail = unreplacedTail.replace(/[A-Za-z]+/gu, (word) => {
|
||||
const norm = word.replace(/[A-Z]/gu, (c) => (/^[QWERTPO]$/u.test(c) ? c : c.toLowerCase()))
|
||||
return composeHangul2Set(norm)
|
||||
})
|
||||
this._committed = this._committed.slice(0, this._unreplacedStart) + convertedTail
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private _handleVimNormalChar(ch: string): void {
|
||||
if (this._pendingVimOperator === 'c') {
|
||||
if (ch === 'i' || ch === 'a' || ch === 'f' || ch === 'F' || ch === 't' || ch === 'T') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue