fix(desktop): prevent fast correction input races
This commit is contained in:
parent
5ec063c744
commit
21a684d572
12 changed files with 134 additions and 18 deletions
|
|
@ -823,9 +823,8 @@ class InputTelemetryService extends EventEmitter {
|
|||
}
|
||||
|
||||
private _scheduleTextSnapshot(keyClass?: KeyStrokeClass): void {
|
||||
// Araso 급 빠른 한영 전환: 공백·문장부호 직후에는 40ms 뒤에 즉시 스냅샷을 찍고,
|
||||
// 일반 글자 입력 중에는 단어를 치는 도중(예: sometime 의 some 시점) 끼어들어 글자를 삼키지 않도록
|
||||
// 700ms 디바운스 타이머(_textTimer)에 맡긴다(Vim 명령줄 :wq 등은 160ms).
|
||||
// 공백·문장부호 뒤의 한영 전환은 140ms 동안 다음 키가 없을 때만 시작한다.
|
||||
// 더 빠른 연속 입력 중에는 삭제 배치와 다음 키가 섞일 수 있으므로 유휴 스냅샷에서 묶어서 교정한다.
|
||||
if (this._typoTimer) clearTimeout(this._typoTimer)
|
||||
if (keyClass && TYPING_KEY_CLASSES.has(keyClass) && configGet('typoAutoCorrectEnabled') !== false) {
|
||||
const isBoundaryKey =
|
||||
|
|
@ -834,7 +833,7 @@ class InputTelemetryService extends EventEmitter {
|
|||
(keyClass === 'digit' && this._modifiers.shift)
|
||||
const quickDelay =
|
||||
isBoundaryKey && this._shouldRunFastTerminalBoundarySnapshot()
|
||||
? 40
|
||||
? 140
|
||||
: !isBoundaryKey && this._terminalTracker.vimMode === 'command'
|
||||
? 160
|
||||
: null
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import { EventEmitter } from 'events'
|
|||
import {
|
||||
TYPO_IGNORED_WORDS_MAX,
|
||||
TYPO_MIN_IDLE_MS,
|
||||
TYPO_REGION_MAX_CHARS,
|
||||
TYPO_REVERT_WINDOW_MS,
|
||||
buildVocabulary,
|
||||
detectJamoNoise,
|
||||
|
|
@ -248,9 +249,11 @@ export class TypoCorrectionService extends EventEmitter {
|
|||
const keyAtDecision = this._deps.lastKeyAt()
|
||||
|
||||
const maxDeterministicSpan =
|
||||
options.trailingWordOnly === true || context.idleMs < TYPO_MIN_IDLE_MS
|
||||
? MAX_FAST_DELETE_CHARS
|
||||
: MAX_INPLACE_DELETE_CHARS
|
||||
options.trailingWordOnly === true && context.idleMs >= LAYOUT_TRAILING_MIN_IDLE_MS
|
||||
? TYPO_REGION_MAX_CHARS
|
||||
: options.trailingWordOnly === true || context.idleMs < TYPO_MIN_IDLE_MS
|
||||
? MAX_FAST_DELETE_CHARS
|
||||
: MAX_INPLACE_DELETE_CHARS
|
||||
const allCorrections = detectTypos(prefix, {
|
||||
includeTrailingToken: true,
|
||||
ignoredWords,
|
||||
|
|
@ -259,6 +262,7 @@ export class TypoCorrectionService extends EventEmitter {
|
|||
terminalMode: isTerminal
|
||||
})
|
||||
const baseCorrections: TypoCorrection[] = []
|
||||
let deferredTrailingCorrections = false
|
||||
if (options.trailingWordOnly !== true) {
|
||||
for (const c of allCorrections) {
|
||||
if (prefix.length - c.start <= maxDeterministicSpan) {
|
||||
|
|
@ -266,11 +270,16 @@ export class TypoCorrectionService extends EventEmitter {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// trailingWordOnly: 커서 끝에서 가까운 연속 교정 사슬만 남긴다 (예: "ㅑ ㅊ무'ㅅ " → "I can't ",
|
||||
// 반면 문장 앞쪽의 이미 지나간 긴 문장은 건드리지 않는다).
|
||||
// 빠른 연속 입력 뒤 일부만 고치면 다음 스냅샷에서 앞쪽 교정이 누락된다.
|
||||
// 짧은 유휴에는 꼬리 사슬 전체가 들어올 때까지 기다리고, 충분히 멈추면 현재 검사 영역을 한 번에 교정한다.
|
||||
for (let i = allCorrections.length - 1; i >= 0; i -= 1) {
|
||||
const c = allCorrections[i]
|
||||
if (prefix.length - c.start > maxDeterministicSpan) break
|
||||
if (prefix.length - c.start > maxDeterministicSpan) {
|
||||
const nextCorr = baseCorrections[0]
|
||||
const between = nextCorr ? prefix.slice(c.end, nextCorr.start) : ''
|
||||
deferredTrailingCorrections = /^[ \t.,!?;:]*$/u.test(between) || between.trim().length <= 2
|
||||
break
|
||||
}
|
||||
if (baseCorrections.length === 0) {
|
||||
const tailAfter = prefix.slice(c.end)
|
||||
const nonSpaceTailLen = tailAfter.replace(/[ \t.,!?;:]/gu, '').length
|
||||
|
|
@ -287,6 +296,7 @@ export class TypoCorrectionService extends EventEmitter {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (deferredTrailingCorrections && context.idleMs < LAYOUT_TRAILING_MIN_IDLE_MS) return 'pass'
|
||||
const loneJamoRemovals =
|
||||
!isTerminal && options.trailingWordOnly !== true && (fullCheckEligible || baseCorrections.length > 0)
|
||||
? detectJamoNoise(prefix, { ignoredWords }).filter(
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ export function sendWin32UnicodeText(text: string): boolean {
|
|||
* (선택적 IME 조합 확정 Space) + 커서 앞 백스페이스 N번 + UTF-16 문자열 입력을
|
||||
* 단 한 번의 Windows SendInput 호출로 입력 큐에 연속해서 주입한다.
|
||||
*
|
||||
* Win32 SendInput 규약상 단일 호출 안의 INPUT 배열 사이에 사용자의 물리 키 입력이 끼어들 수 없으므로,
|
||||
* 다른 프로세스의 입력이 배치 사이에 섞일 수 있으므로 자동 교정 호출자는 연속 타이핑 중 삭제를 미뤄야 한다.
|
||||
* 배치 내부의 순서만 보장한다. 이전 스냅샷 이후 바뀐 커서/텍스트, 대상 앱의 처리 시간,
|
||||
* IME 상태까지 보장하지 않는다. 일부 입력만 성공하면 삭제/입력 배치를 재실행하지 않는다.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue