fix(suggestion): paste after the shortcut keys are released and keep typing detection stable
Ctrl+Alt+Enter pasted while Ctrl+Alt were still down, so the target app got Ctrl+Alt+V; accepting now closes the panel and waits for the modifiers to be released. Candidates are accepted on pointer press because the list is redrawn as new candidates stream in, which swallowed clicks. The typing gate identified the focused field by its bounds, so chat boxes that grow while typing looked like a new field on every keystroke and were reported as "not typing". Fields are now keyed by window, control type and name, and a mouse click re-baselines the text instead. The decision log includes both gate values. The live-caption model selector moves to the caption section of the General tab, next to the other caption settings.
This commit is contained in:
parent
4b0f685941
commit
da0da98285
8 changed files with 144 additions and 55 deletions
|
|
@ -7,6 +7,7 @@ import { initLoggerService, getLogger } from './services/LoggerService'
|
|||
import { initConfigService, configGet, configSet } from './services/ConfigService'
|
||||
import { getKeyBindingService, uiohookCodeToVk } from './services/KeyBindingService'
|
||||
import { acquireGlobalInputHook } from './services/global-input-hook'
|
||||
import { trackModifierKeys } from './services/modifier-state'
|
||||
import { getVoiceModeService } from './services/VoiceModeService'
|
||||
import { startLocalLLMAvailability, getLocalLLMService } from './services/LocalLLMService'
|
||||
import { getHistoryService } from './services/HistoryService'
|
||||
|
|
@ -224,6 +225,8 @@ async function initInputIntelligence(): Promise<void> {
|
|||
// KeyBindingService 의 등록 바인딩 경로로는 절대 들어오지 않는다 — 원본 keydown을
|
||||
// 직접 듣는다(InputTelemetryService/KeyBindingService 가 이미 쓰는 것과 같은 패턴).
|
||||
acquireGlobalInputHook()
|
||||
// 단축키로 수락할 때 Ctrl/Alt 를 뗄 때까지 기다리려면 누른 순간부터 추적해야 한다.
|
||||
trackModifierKeys()
|
||||
uIOhook.on('keydown', (event: UiohookKeyboardEvent) => {
|
||||
if (uiohookCodeToVk(event.keycode) !== VK.Escape) return
|
||||
const shouldDismiss = shouldDismissOnEscape(suggestion.isPresentationActive, {
|
||||
|
|
|
|||
|
|
@ -165,6 +165,8 @@ class InputTelemetryService extends EventEmitter {
|
|||
private _lastFocusKey = ''
|
||||
/** 현재 포커스에 들어왔을 때의 텍스트 (비밀번호는 저장하지 않는다) — 편집 여부 판정 기준선. */
|
||||
private _textAtFocus = ''
|
||||
/** 클릭 뒤 첫 스냅샷에서 기준선을 다시 잡는다 */
|
||||
private _rebaseFocusText = false
|
||||
private _lastActiveTickAt = 0
|
||||
private _lastMouse: { x: number; y: number } | null = null
|
||||
private _lastClickAt = 0
|
||||
|
|
@ -407,6 +409,8 @@ class InputTelemetryService extends EventEmitter {
|
|||
this._lastClickAt = now
|
||||
this._lastClickButton = button
|
||||
this._lastClickPos = position
|
||||
// 클릭은 다른 칸으로 옮겨 갔을 수 있다 — 다음 스냅샷의 텍스트를 새 기준으로 삼는다.
|
||||
this._rebaseFocusText = true
|
||||
}
|
||||
|
||||
private _handleMouseUp(event: UiohookMouseEvent): void {
|
||||
|
|
@ -607,15 +611,16 @@ class InputTelemetryService extends EventEmitter {
|
|||
: tail
|
||||
this._caretFallback = !caretKnown
|
||||
|
||||
// 포커스 식별: 바뀌었으면 그 시점 텍스트를 기준선으로 저장한다(비밀번호는 비운다).
|
||||
// 마우스로 필드에 들어오기만 하고 아무것도 안 쳤으면, 이 기준선과 현재 텍스트가
|
||||
// 같아 editedSinceFocus 가 false 로 남는다(실측: YouTube 검색창 클릭만 했는데
|
||||
// 옛 검색어로 제안이 뜸).
|
||||
const focusKey = computeFocusKey(this._foreground.hwnd, snapshot.controlType ?? null, snapshot.elementRect)
|
||||
// 포커스 식별: 칸이 바뀌었거나 클릭이 있었으면 그 시점 텍스트를 기준선으로 저장한다
|
||||
// (비밀번호는 비운다). 마우스로 칸에 들어오기만 하고 아무것도 안 쳤으면 기준선과
|
||||
// 현재 텍스트가 같아 editedSinceFocus 가 false 로 남는다(실측: YouTube 검색창 클릭만
|
||||
// 했는데 옛 검색어로 제안이 뜸).
|
||||
const focusKey = computeFocusKey(this._foreground.hwnd, snapshot.controlType ?? null, snapshot.controlName ?? null)
|
||||
const textForFocus = snapshot.isPassword ? '' : snapshot.text
|
||||
if (focusKey !== this._lastFocusKey) {
|
||||
if (focusKey !== this._lastFocusKey || this._rebaseFocusText) {
|
||||
this._lastFocusKey = focusKey
|
||||
this._textAtFocus = textForFocus
|
||||
this._rebaseFocusText = false
|
||||
}
|
||||
context.editedSinceFocus = textForFocus !== this._textAtFocus
|
||||
|
||||
|
|
@ -1385,16 +1390,14 @@ function lastLineOf(text: string): string {
|
|||
}
|
||||
|
||||
/**
|
||||
* 포커스된 컨트롤 식별 키 — 창(hwnd) + 컨트롤 종류 + 위치.
|
||||
* 포커스된 컨트롤 식별 키 — 창(hwnd) + 컨트롤 종류 + 컨트롤 이름.
|
||||
*
|
||||
* 높이는 뺀다 — 여러 줄 입력창은 타이핑에 따라 높이가 자라, 높이를 포함하면
|
||||
* 같은 필드인데도 칠 때마다 "새 포커스" 로 오인돼 기준선이 계속 리셋된다.
|
||||
* 위치·크기는 쓰지 않는다 — 채팅 입력창은 글이 늘면 자라고 움직여, 넣으면 같은 칸인데도
|
||||
* 칠 때마다 "새 칸" 으로 오인돼 기준선이 리셋되고 제안이 거의 막혔다(실측: Agent
|
||||
* Switchboard 에서 not-typing 반복). 같은 창 안의 칸 이동은 클릭 재기준으로 잡는다.
|
||||
*/
|
||||
function computeFocusKey(hwnd: number | null, controlType: string | null, elementRect: UiRect | null): string {
|
||||
const rect = elementRect
|
||||
? `${Math.round(elementRect.x)},${Math.round(elementRect.y)},${Math.round(elementRect.width)}`
|
||||
: 'none'
|
||||
return `${hwnd ?? ''}|${controlType ?? ''}|${rect}`
|
||||
function computeFocusKey(hwnd: number | null, controlType: string | null, controlName: string | null): string {
|
||||
return `${hwnd ?? ''}|${controlType ?? ''}|${controlName ?? ''}`
|
||||
}
|
||||
|
||||
function formatLocalDate(date: Date): string {
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import { buildSuggestionPrompt } from './llm-prompts'
|
|||
import { getInputTelemetryService, type TypingContext } from './InputTelemetryService'
|
||||
import { getPersonalGraphService } from './PersonalGraphService'
|
||||
import { getTextInsertService } from './TextInsertService'
|
||||
import { waitForModifiersReleased } from './modifier-state'
|
||||
|
||||
const logger = getLogger('SuggestionService')
|
||||
|
||||
|
|
@ -1074,6 +1075,8 @@ class SuggestionService extends EventEmitter {
|
|||
context.isPassword,
|
||||
context.isComposing,
|
||||
context.anchor ? 'A' : '-',
|
||||
context.editedSinceFocus,
|
||||
context.typedRecently,
|
||||
getLocalLLMService().isAvailable(),
|
||||
this.isEnabled()
|
||||
].join('|')
|
||||
|
|
@ -1082,7 +1085,8 @@ class SuggestionService extends EventEmitter {
|
|||
this._lastDecisionSignature = signature
|
||||
logger.info(
|
||||
`제안 판단 입력: avail=${context.available} edit=${context.isEditable} pw=${context.isPassword} ` +
|
||||
`comp=${context.isComposing} prefixLen=${context.prefix.length} idle=${context.idleMs}ms ` +
|
||||
`comp=${context.isComposing} edited=${context.editedSinceFocus} typed=${context.typedRecently} ` +
|
||||
`prefixLen=${context.prefix.length} idle=${context.idleMs}ms ` +
|
||||
`app=${context.appName ?? '-'} enabled=${this.isEnabled()} ` +
|
||||
`model=${getLocalLLMService().isAvailable()} anchor=${context.anchor ? 'yes' : 'no'}`
|
||||
)
|
||||
|
|
@ -1244,11 +1248,24 @@ class SuggestionService extends EventEmitter {
|
|||
}
|
||||
const candidate = this._candidates[this._activeIndex]
|
||||
if (!candidate) return { ok: false, reason: 'already-visible' }
|
||||
const text = candidate.text
|
||||
const appName = this._appName
|
||||
const windowTitle = this._windowTitle
|
||||
|
||||
// 먼저 창을 닫고 생성을 멈춘다 — 수락은 즉시 반응해야 한다.
|
||||
this.dismiss('accepted')
|
||||
this.emit('state-changed', this.getState())
|
||||
|
||||
// 단축키로 수락했다면 사용자가 아직 Ctrl+Alt 를 쥐고 있다. 그대로 Ctrl+V 를 보내면
|
||||
// 대상 앱에 Ctrl+Alt+V 가 들어가 붙여넣기가 되지 않는다(실측) — 뗄 때까지 기다린다.
|
||||
if (!(await waitForModifiersReleased())) {
|
||||
logger.warn('수정자 키가 떼어지지 않은 채 제안을 삽입한다 (1.5초 초과)')
|
||||
}
|
||||
|
||||
const method = configGet('insertMethod')
|
||||
try {
|
||||
const result = await getTextInsertService().insertText(
|
||||
candidate.text,
|
||||
text,
|
||||
method === 'keyboard' ? 'keyboard' : 'clipboard'
|
||||
)
|
||||
if (!result.success) {
|
||||
|
|
@ -1260,16 +1277,9 @@ class SuggestionService extends EventEmitter {
|
|||
return { ok: false, reason: 'generation-failed' }
|
||||
}
|
||||
|
||||
this._markAccepted(candidate.text)
|
||||
this._markAccepted(text)
|
||||
// 수락한 문장은 사용자 문체의 확실한 표본이다 (학습 동의 시에만 저장됨).
|
||||
getInputTelemetryService().recordExternalText(candidate.text, {
|
||||
appName: this._appName,
|
||||
windowTitle: this._windowTitle,
|
||||
source: 'suggestion'
|
||||
})
|
||||
|
||||
this.dismiss('accepted')
|
||||
this.emit('state-changed', this.getState())
|
||||
getInputTelemetryService().recordExternalText(text, { appName, windowTitle, source: 'suggestion' })
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
|
|
|
|||
50
apps/desktop/src/main/services/modifier-state.ts
Normal file
50
apps/desktop/src/main/services/modifier-state.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// src/main/services/modifier-state.ts
|
||||
//
|
||||
// 사용자가 물리적으로 누르고 있는 수정자 키(Ctrl/Alt/Shift/Win)를 추적한다.
|
||||
//
|
||||
// 단축키로 무언가를 삽입할 때(예: Ctrl+Alt+Enter 로 제안 수락) 동작은 키를 누르는
|
||||
// 순간 실행되는데, 그때 사용자는 아직 Ctrl+Alt 를 쥐고 있다. 그 상태로 Ctrl+V 를
|
||||
// 보내면 대상 앱에는 Ctrl+Alt+V 가 들어가 붙여넣기가 되지 않는다(실측). 삽입 전에
|
||||
// 손을 뗄 때까지 잠깐 기다린다.
|
||||
|
||||
import { uIOhook, type UiohookKeyboardEvent } from 'uiohook-napi'
|
||||
import { acquireGlobalInputHook } from './global-input-hook'
|
||||
|
||||
/** uiohook 키 코드 (UiohookKey.Ctrl/CtrlRight/Alt/AltRight/Shift/ShiftRight/Meta/MetaRight) */
|
||||
const MODIFIER_KEYCODES: ReadonlySet<number> = new Set([29, 3613, 56, 3640, 42, 54, 3675, 3676])
|
||||
|
||||
const held = new Set<number>()
|
||||
let attached = false
|
||||
|
||||
function attach(): void {
|
||||
if (attached) return
|
||||
attached = true
|
||||
acquireGlobalInputHook()
|
||||
uIOhook.on('keydown', (event: UiohookKeyboardEvent) => {
|
||||
if (MODIFIER_KEYCODES.has(event.keycode)) held.add(event.keycode)
|
||||
})
|
||||
uIOhook.on('keyup', (event: UiohookKeyboardEvent) => {
|
||||
held.delete(event.keycode)
|
||||
})
|
||||
}
|
||||
|
||||
/** 추적을 시작한다 — 단축키가 눌리기 전에 붙어 있어야 누른 상태를 안다. */
|
||||
export function trackModifierKeys(): void {
|
||||
attach()
|
||||
}
|
||||
|
||||
/**
|
||||
* 수정자 키가 모두 떼어질 때까지 기다린다.
|
||||
*
|
||||
* 시간 안에 떼지 않으면(떼는 이벤트를 놓친 경우 포함) 추적 상태를 비우고 false 를
|
||||
* 돌려준다 — 호출자는 그래도 진행한다(영원히 막히면 안 된다).
|
||||
*/
|
||||
export async function waitForModifiersReleased(timeoutMs = 1500): Promise<boolean> {
|
||||
const deadline = Date.now() + timeoutMs
|
||||
while (held.size > 0 && Date.now() < deadline) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 15))
|
||||
}
|
||||
if (held.size === 0) return true
|
||||
held.clear()
|
||||
return false
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue