fix(desktop): resolve Ctrl+Alt+Enter accept drops and duplicate typo LLM checks
This commit is contained in:
parent
2a62f2496a
commit
02d0d0c6c1
15 changed files with 238 additions and 19 deletions
|
|
@ -284,7 +284,7 @@ async function initInputIntelligence(): Promise<void> {
|
|||
// 제안 창이 떠 있는 동안만 제안 단축키를 OS 에서 잡는다 — Ctrl+Alt+Enter 가 앱에도 전달돼
|
||||
// 개행이 들어가던 문제(2026-10-03). 창이 사라지면 바로 푼다.
|
||||
const syncSuggestionKeyCapture = (): void =>
|
||||
getKeyBindingService().setSuggestionCaptureActive(suggestion.isPresentationActive)
|
||||
getKeyBindingService().setSuggestionCaptureActive(suggestion.isOverlayOrCaptureActive)
|
||||
suggestion.on('updated', (state) => {
|
||||
overlay.onUpdated(state)
|
||||
syncSuggestionKeyCapture()
|
||||
|
|
@ -319,7 +319,7 @@ async function initInputIntelligence(): Promise<void> {
|
|||
trackModifierKeys()
|
||||
uIOhook.on('keydown', (event: UiohookKeyboardEvent) => {
|
||||
if (uiohookCodeToVk(event.keycode) !== VK.Escape) return
|
||||
const shouldDismiss = shouldDismissOnEscape(suggestion.isPresentationActive, {
|
||||
const shouldDismiss = shouldDismissOnEscape(suggestion.isOverlayOrCaptureActive, {
|
||||
ctrl: event.ctrlKey === true,
|
||||
alt: event.altKey === true,
|
||||
shift: event.shiftKey === true,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,11 @@ import { getLogger } from './LoggerService'
|
|||
import { acquireGlobalInputHook } from './global-input-hook'
|
||||
import { forgetHeldModifiers } from './modifier-state'
|
||||
import { configGet, loadKeyBindings, onConfigChanged } from './ConfigService'
|
||||
import { acceleratorsToReserve, suggestionCaptureAccelerators } from './keybinding-accelerator-policy'
|
||||
import {
|
||||
acceleratorsToReserve,
|
||||
bindingToAccelerator,
|
||||
suggestionCaptureAccelerators
|
||||
} from './keybinding-accelerator-policy'
|
||||
import type { ReservableBinding } from './keybinding-accelerator-policy'
|
||||
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
|
||||
import {
|
||||
|
|
@ -33,7 +37,12 @@ import type {
|
|||
ChordClock,
|
||||
ChordTriggerEvent
|
||||
} from '@d3ro/core/keybinding-runtime'
|
||||
import type { KeyBinding, KeyBindingActionSpec, MouseButtonCode } from '@d3ro/core/types'
|
||||
import type {
|
||||
KeyBinding,
|
||||
KeyBindingActionId,
|
||||
KeyBindingActionSpec,
|
||||
MouseButtonCode
|
||||
} from '@d3ro/core/types'
|
||||
|
||||
const logger = getLogger('KeyBindingService')
|
||||
|
||||
|
|
@ -205,9 +214,22 @@ const VK_TO_UIOHOOK: ReadonlyMap<number, number> = new Map([
|
|||
[VK.NumLock, UiohookKey.NumLock]
|
||||
])
|
||||
|
||||
const UIOHOOK_TO_VK: ReadonlyMap<number, number> = new Map(
|
||||
Array.from(VK_TO_UIOHOOK, ([vk, uiohookCode]) => [uiohookCode, vk] as const)
|
||||
)
|
||||
const UIOHOOK_TO_VK: ReadonlyMap<number, number> = new Map([
|
||||
...Array.from(VK_TO_UIOHOOK, ([vk, uiohookCode]) => [uiohookCode, vk] as const),
|
||||
// 넘패드 확장 키(NumpadEnter / Numpad 방향키)는 Windows VK 에 별도 코드가 없어
|
||||
// 일반 Enter / 방향키 VK 로 합류시킨다 — 넘패드 Enter 로도 Ctrl+Alt+Enter 수락이 동작하도록 한다.
|
||||
[UiohookKey.NumpadEnter, VK.Enter],
|
||||
[UiohookKey.NumpadArrowLeft, VK.ArrowLeft],
|
||||
[UiohookKey.NumpadArrowUp, VK.ArrowUp],
|
||||
[UiohookKey.NumpadArrowRight, VK.ArrowRight],
|
||||
[UiohookKey.NumpadArrowDown, VK.ArrowDown],
|
||||
[UiohookKey.NumpadHome, VK.Home],
|
||||
[UiohookKey.NumpadEnd, VK.End],
|
||||
[UiohookKey.NumpadPageUp, VK.PageUp],
|
||||
[UiohookKey.NumpadPageDown, VK.PageDown],
|
||||
[UiohookKey.NumpadInsert, VK.Insert],
|
||||
[UiohookKey.NumpadDelete, VK.Delete]
|
||||
])
|
||||
|
||||
/**
|
||||
* uiohook 이트 키코드 → Windows VK (정본 좌표계).
|
||||
|
|
@ -263,7 +285,12 @@ class KeyBindingService extends EventEmitter {
|
|||
/** press / release · 더블프레스 · AltGr 보류 판정 (순수 정책, core) */
|
||||
private readonly _machine = new ChordStateMachine({
|
||||
clock: systemClock,
|
||||
onTrigger: (event) => this.emit('triggered', event),
|
||||
onTrigger: (event) => {
|
||||
if (event.type === 'pressed') {
|
||||
this._lastPressedAt.set(event.actionId, Date.now())
|
||||
}
|
||||
this.emit('triggered', event)
|
||||
},
|
||||
debug: (message) => logger.debug(message)
|
||||
})
|
||||
|
||||
|
|
@ -279,6 +306,8 @@ class KeyBindingService extends EventEmitter {
|
|||
/** 제안 창이 떠 있는 동안만 잡는 제안 단축키 (키를 앱에 넘기지 않으려고) */
|
||||
private _suggestionCaptureWanted = false
|
||||
private _capturedAccelerators: Set<string> = new Set()
|
||||
private _lastPressedAt: Map<KeyBindingActionId, number> = new Map()
|
||||
private _captureFallbackTimers: Set<ReturnType<typeof setTimeout>> = new Set()
|
||||
|
||||
/** 상태 머신에 등록한 바인딩과 액션 — accelerator 예약 정책의 입력 */
|
||||
private _reservable: ReservableBinding[] = []
|
||||
|
|
@ -509,7 +538,9 @@ class KeyBindingService extends EventEmitter {
|
|||
for (const accelerator of suggestionCaptureAccelerators(this._reservable, process.platform, this._ownedAccelerators)) {
|
||||
try {
|
||||
const ok = globalShortcut.register(accelerator, () => {
|
||||
// noop — 동작은 uiohook 이 낸다. 등록 목적은 키를 앱에 넘기지 않는 것이다.
|
||||
// 기본 경로는 uiohook 이나, 관리자 창(UIPI)·수정자 비동기 등으로 uiohook 이 놓쳤을 때
|
||||
// OS 핫키만 삼켜지고 동작이 안 나가는 일을 막기 위해 25ms 뒤 폴백 트리거를 보낸다.
|
||||
this._scheduleCapturedSuggestionFallback(accelerator)
|
||||
})
|
||||
if (ok) this._capturedAccelerators.add(accelerator)
|
||||
else logger.debug(`제안 단축키를 잡지 못함 (다른 곳에서 사용 중): ${accelerator}`)
|
||||
|
|
@ -519,7 +550,37 @@ class KeyBindingService extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
private _scheduleCapturedSuggestionFallback(accelerator: string): void {
|
||||
const timer = setTimeout(() => {
|
||||
this._captureFallbackTimers.delete(timer)
|
||||
if (!this._suggestionCaptureWanted || !this._isRunning) return
|
||||
const now = Date.now()
|
||||
for (const { actionId, binding } of this._reservable) {
|
||||
if (bindingToAccelerator(binding, process.platform) !== accelerator) continue
|
||||
const lastPressed = this._lastPressedAt.get(actionId) ?? 0
|
||||
if (now - lastPressed <= 250) continue
|
||||
this._lastPressedAt.set(actionId, now)
|
||||
logger.info(`제안 단축키 OS 캡처 폴백 발동: ${actionId} (${accelerator})`)
|
||||
this.emit('triggered', {
|
||||
actionId,
|
||||
type: 'pressed',
|
||||
isDoublePress: false,
|
||||
holdMode: false,
|
||||
timestamp: now,
|
||||
durationMs: 0,
|
||||
binding: { ...binding }
|
||||
})
|
||||
}
|
||||
}, 25)
|
||||
timer.unref?.()
|
||||
this._captureFallbackTimers.add(timer)
|
||||
}
|
||||
|
||||
private _releaseSuggestionCapture(): void {
|
||||
for (const timer of this._captureFallbackTimers) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
this._captureFallbackTimers.clear()
|
||||
for (const accelerator of this._capturedAccelerators) {
|
||||
try {
|
||||
globalShortcut.unregister(accelerator)
|
||||
|
|
|
|||
|
|
@ -468,6 +468,11 @@ export class SuggestionService extends EventEmitter {
|
|||
return this.isVisible || this._generating || this._warmingUp || this._partialText.length > 0
|
||||
}
|
||||
|
||||
/** 오버레이가 화면에 떠 있거나("생성 중" 보류·수락 대기 포함) 제안 단축키 캡처가 필요한 상태인가 */
|
||||
get isOverlayOrCaptureActive(): boolean {
|
||||
return this.isPresentationActive || this._pending || this._acceptInFlight
|
||||
}
|
||||
|
||||
get activeText(): string | null {
|
||||
return this._candidates[this._activeIndex]?.text ?? null
|
||||
}
|
||||
|
|
@ -2116,6 +2121,26 @@ export class SuggestionService extends EventEmitter {
|
|||
if (index !== undefined && index >= 0 && index < this._candidates.length) {
|
||||
this._activeIndex = index
|
||||
}
|
||||
if (!this._candidates[this._activeIndex] && (this._inFlight || this._generating || this._pending)) {
|
||||
if (this._pending && !this._inFlight && this._lastContext) {
|
||||
const config = this.readPolicyConfig()
|
||||
const prefix = normalizeRequestPrefix(this._lastContext.prefix)
|
||||
if (prefix.length > 0) {
|
||||
this._clearPending(false)
|
||||
void this._generate(prefix, this._lastContext, config.maxCandidates, config.maxChars)
|
||||
}
|
||||
}
|
||||
logger.info('제안 수락 대기: 첫 후보 생성 중 — 완료 즉시 수락합니다')
|
||||
this._acceptInFlight = true
|
||||
try {
|
||||
await this._waitForFirstCandidate(2500)
|
||||
} finally {
|
||||
this._acceptInFlight = false
|
||||
}
|
||||
if (index !== undefined && index >= 0 && index < this._candidates.length) {
|
||||
this._activeIndex = index
|
||||
}
|
||||
}
|
||||
const candidate = this._candidates[this._activeIndex]
|
||||
if (!candidate) {
|
||||
// 창이 이미 닫힌 뒤의 클릭·단축키 — 조용히 끝나면 "골라도 안 들어간다" 의 원인이 안 보인다.
|
||||
|
|
@ -2204,6 +2229,34 @@ export class SuggestionService extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
private _waitForFirstCandidate(timeoutMs: number): Promise<boolean> {
|
||||
if (this._candidates.length > 0) return Promise.resolve(true)
|
||||
if (!this._inFlight && !this._generating && !this._pending) return Promise.resolve(false)
|
||||
return new Promise<boolean>((resolve) => {
|
||||
let settled = false
|
||||
const finish = (ok: boolean): void => {
|
||||
if (settled) return
|
||||
settled = true
|
||||
clearTimeout(timer)
|
||||
this.off('updated', onUpdated)
|
||||
this.off('cleared', onCleared)
|
||||
resolve(ok)
|
||||
}
|
||||
const onUpdated = (): void => {
|
||||
if (this._candidates.length > 0) {
|
||||
finish(true)
|
||||
} else if (!this._inFlight && !this._generating && !this._pending) {
|
||||
finish(false)
|
||||
}
|
||||
}
|
||||
const onCleared = (): void => finish(false)
|
||||
const timer = setTimeout(() => finish(this._candidates.length > 0), timeoutMs)
|
||||
timer.unref?.()
|
||||
this.on('updated', onUpdated)
|
||||
this.on('cleared', onCleared)
|
||||
})
|
||||
}
|
||||
|
||||
/** 단어 단위 수락 뒤 남은 문장을 같은 자리에 다시 띄운다 — 세션 접두는 방금 넣은 글까지로 맞춘다. */
|
||||
private _presentRemainder(
|
||||
prefixAfterInsert: string,
|
||||
|
|
@ -2277,7 +2330,8 @@ export class SuggestionService extends EventEmitter {
|
|||
// 터미널(xterm-helper-textarea, Windows Terminal, Kitedesk 등)에서는 Ctrl+V 붙여넣기가
|
||||
// 클립보드 복원 타이밍(250ms)과 경합해 이전 클립보드(URL 등)가 대신 붙여넣어지거나 ^V 가 입력될 수 있으므로
|
||||
// 클립보드를 건드리지 않는 직접 유니코드 키보드 주입('keyboard')을 사용한다.
|
||||
const insertMethod = method === 'keyboard' || terminalMode ? 'keyboard' : 'clipboard'
|
||||
const isTerminal = terminalMode || isTerminalApp(appName)
|
||||
const insertMethod = method === 'keyboard' || isTerminal ? 'keyboard' : 'clipboard'
|
||||
try {
|
||||
if (deleteCount > 0) {
|
||||
// 확정용 Space(+1)·백스페이스·붙여넣기(Ctrl, V) 키는 사용자 입력 통계에서 뺀다.
|
||||
|
|
@ -2296,7 +2350,7 @@ export class SuggestionService extends EventEmitter {
|
|||
logger.warn(`제안 삽입 실패 (method=${result.method}, len=${result.textLength})`)
|
||||
return { ok: false, reason: 'generation-failed' }
|
||||
}
|
||||
if (terminalMode) {
|
||||
if (isTerminal) {
|
||||
this._learning.applyProgrammaticReplacement?.(deleteCount, text)
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -368,7 +368,12 @@ export class TypoCorrectionService extends EventEmitter {
|
|||
|
||||
let fromModel: TypoCorrection[] = []
|
||||
const model = configGet('typoAutoCorrectUseModel') !== false ? this._deps.warmModel() : null
|
||||
const worthAsking = hasSuspiciousTypo(region) || (options.thorough === true && this._worthModelCheck(region))
|
||||
// handleTypingContext 의 자동 교정(_runModelCheck)이 이미 같은 구간을 모델로 검사해
|
||||
// 교정 사항 없음으로 확인했다면, 제안 채우기 중(_proposeLateCorrection) 같은 구간을
|
||||
// 다시 모델에 물어 Ollama KV 캐시를 밀어내지 않는다.
|
||||
const worthAsking =
|
||||
!this._isRegionChecked(region) &&
|
||||
(hasSuspiciousTypo(region) || (options.thorough === true && this._worthModelCheck(region)))
|
||||
if (model && worthAsking) {
|
||||
const abort = new AbortController()
|
||||
const forward = (): void => abort.abort()
|
||||
|
|
@ -377,6 +382,9 @@ export class TypoCorrectionService extends EventEmitter {
|
|||
timer.unref?.()
|
||||
try {
|
||||
fromModel = await this._askModel(model, prefix, abort.signal, ignoredWords, vocabulary.known)
|
||||
if (!abort.signal.aborted && fromModel.length === 0) {
|
||||
this._markRegionChecked(region)
|
||||
}
|
||||
} catch (error) {
|
||||
if (!abort.signal.aborted) {
|
||||
logger.debug(`제안용 오타 검사 실패: ${error instanceof Error ? error.message : String(error)}`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue