fix(desktop): prevent modifier key buffer resets, clipboard race on terminal accept, and redundant UIA settle snapshots

This commit is contained in:
Yun Chan 2026-10-31 04:19:53 +09:00
parent 6d909dd0e5
commit 41901c1ec5
10 changed files with 198 additions and 23 deletions

View file

@ -86,6 +86,8 @@ export interface SuggestionLearningPort {
recordAccepted(text: string, meta: { appName: string | null; windowTitle: string | null }): void
/** 곧 보낼 프로그램 키 수(교정 수락의 백스페이스 등) — 입력 통계에서 뺀다. */
expectProgrammaticKeys?(count: number): void
/** 터미널 키스트로크 버퍼에 프로그램 치환/삽입을 반영한다. */
applyProgrammaticReplacement?(deleteCount: number, insertText: string, baseLength?: number): void
}
/**
@ -132,6 +134,8 @@ export function createDefaultSuggestionServiceDeps(): SuggestionServiceDeps {
learning: {
expectProgrammaticInsert: (text) => getInputTelemetryService().expectProgrammaticInsert(text),
expectProgrammaticKeys: (count) => getInputTelemetryService().expectProgrammaticKeys(count),
applyProgrammaticReplacement: (deleteCount, insertText, baseLength) =>
getInputTelemetryService().applyProgrammaticReplacement(deleteCount, insertText, baseLength),
recordAccepted: (text, meta) =>
getInputTelemetryService().recordExternalText(text, { ...meta, source: 'suggestion' })
}
@ -2146,11 +2150,22 @@ export class SuggestionService extends EventEmitter {
const anchorKind = this._anchorKind
const provenance = this._provenance
const composing = this._lastContext?.isComposing === true
const terminalMode = this._lastContext?.terminalMode === true
const appName = this._appName
const windowTitle = this._windowTitle
const targetWindow = this._windowHandle
const sessionRecordId = this._sessionRecordId
// 수락이 시작된 순간 추가 후보 채우기 루프는 즉시 멈춘다 — 손을 떼길 기다리는 동안
// 2/12, 3/12 후보가 계속 스트리밍되면 사용자가 아직 선택 중이라 오인해 Ctrl+Alt 를 계속 쥐고 있게 된다.
if (this._filling) {
this._filling = false
this._fillAbort?.abort()
this._fillAbort = null
if (!this._inFlight) this._generating = false
this.emit('updated', this.getState())
}
// 단축키로 수락했다면 사용자가 아직 키를 쥐고 있다. 그대로 Ctrl+V 를 보내면 대상 앱에 Ctrl+Alt+V 가 들어가
// 붙여넣기가 되지 않는다. 창을 띄워 둔 채 손을 다 뗄 때까지 기다린다(최대 5초) — 창이 먼저 사라지면 사용자는
// "들어가는 중" 이라 여기고 계속 쥐고 있었다(2026-10-25). 클릭 수락은 기다림 없이 바로 지나간다.
@ -2173,6 +2188,7 @@ export class SuggestionService extends EventEmitter {
text,
deleteCount,
composing,
terminalMode,
appName,
windowTitle,
targetWindow,
@ -2222,6 +2238,7 @@ export class SuggestionService extends EventEmitter {
text: string
deleteCount: number
composing: boolean
terminalMode?: boolean
appName: string | null
windowTitle: string | null
targetWindow: number | null
@ -2230,7 +2247,17 @@ export class SuggestionService extends EventEmitter {
/** 수락한 문장을 사용자 문체 표본으로 배운다 (단어 단위 수락은 false) */
learn?: boolean
}): Promise<SuggestionRequestResult> {
const { text, deleteCount, composing, appName, windowTitle, targetWindow, sessionRecordId, candidateText } = params
const {
text,
deleteCount,
composing,
terminalMode = false,
appName,
windowTitle,
targetWindow,
sessionRecordId,
candidateText
} = params
// 붙여넣기(Ctrl+V)는 그 순간의 포그라운드 창으로 간다. 오버레이는 다음 스냅샷이 와야
// 닫히므로, 그사이 다른 앱으로 옮겨 간 뒤 수락하면 엉뚱한 창에 삽입됐다 — 세션을 만든
// 창이 아니면 삽입하지 않는다 (창을 알 수 없으면 기존처럼 진행한다).
@ -2247,7 +2274,10 @@ export class SuggestionService extends EventEmitter {
// 삽입 직후의 텍스트 스냅샷 diff 가 이 텍스트를 "타이핑" 으로 다시 학습하지 않도록 알린다.
const cancelExpectedInsert = this._learning.expectProgrammaticInsert(text)
const method = configGet('insertMethod')
const insertMethod = method === 'keyboard' ? 'keyboard' : 'clipboard'
// 터미널(xterm-helper-textarea, Windows Terminal, Kitedesk 등)에서는 Ctrl+V 붙여넣기가
// 클립보드 복원 타이밍(250ms)과 경합해 이전 클립보드(URL 등)가 대신 붙여넣어지거나 ^V 가 입력될 수 있으므로
// 클립보드를 건드리지 않는 직접 유니코드 키보드 주입('keyboard')을 사용한다.
const insertMethod = method === 'keyboard' || terminalMode ? 'keyboard' : 'clipboard'
try {
if (deleteCount > 0) {
// 확정용 Space(+1)·백스페이스·붙여넣기(Ctrl, V) 키는 사용자 입력 통계에서 뺀다.
@ -2266,6 +2296,9 @@ export class SuggestionService extends EventEmitter {
logger.warn(`제안 삽입 실패 (method=${result.method}, len=${result.textLength})`)
return { ok: false, reason: 'generation-failed' }
}
if (terminalMode) {
this._learning.applyProgrammaticReplacement?.(deleteCount, text)
}
} catch (error) {
cancelExpectedInsert()
logger.warn(`제안 삽입 예외: ${error instanceof Error ? error.message : String(error)}`)