fix(keybinding): stop stealing chords on Windows, release mouse holds, keep cleared actions
This commit is contained in:
parent
115e8488ac
commit
1a4c39cb94
8 changed files with 927 additions and 148 deletions
|
|
@ -6,10 +6,10 @@ import type { AppConfig, ConfigChangedEvent, KeyBinding, KeyBindingActionId, Key
|
|||
import {
|
||||
bindingsEqual,
|
||||
createDefaultBindingMap,
|
||||
decodeKeyBindingMap,
|
||||
findActionSpec,
|
||||
kb,
|
||||
normalizeBinding,
|
||||
parseBindingMap,
|
||||
VK
|
||||
} from '@d3ro/core/keybinding'
|
||||
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
|
||||
|
|
@ -40,16 +40,13 @@ function migrateSuggestionTuning(activeStore: ElectronStore<AppConfig>): void {
|
|||
}
|
||||
|
||||
if (current < 2) {
|
||||
const rawBindings = raw.keyBindings as unknown
|
||||
const bindings = parseBindingMap(rawBindings)
|
||||
const defaults = createDefaultBindingMap()
|
||||
const suggestionActions = ['suggestion-accept', 'suggestion-next', 'suggestion-prev', 'suggestion-dismiss'] as const
|
||||
for (const action of suggestionActions) {
|
||||
const spec = findActionSpec(action)
|
||||
if (!spec) continue
|
||||
bindings[action] = defaults[action] ?? spec.defaultBindings.map((binding) => ({ ...binding }))
|
||||
}
|
||||
activeStore.set('keyBindings', bindings)
|
||||
// 의도된 강제 초기화 — 이 개정판은 제안 액션 4개를 기본값으로 되돌린다.
|
||||
updateStoredKeyBindings(activeStore, (bindings) => {
|
||||
const defaults = createDefaultBindingMap()
|
||||
const suggestionActions = ['suggestion-accept', 'suggestion-next', 'suggestion-prev', 'suggestion-dismiss'] as const
|
||||
for (const action of suggestionActions) bindings[action] = defaults[action]
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
if (current < 3) activeStore.set('suggestionRequestTimeoutMs', 8000)
|
||||
|
|
@ -88,20 +85,41 @@ function bindingListEquals(a: readonly KeyBinding[], b: readonly KeyBinding[]):
|
|||
* 절대 건드리지 않는다.
|
||||
*/
|
||||
function migrateSuggestionOverlayBindings(activeStore: ElectronStore<AppConfig>): void {
|
||||
const raw = activeStore.store as unknown as Record<string, unknown>
|
||||
const bindings = parseBindingMap(raw.keyBindings)
|
||||
updateStoredKeyBindings(activeStore, (bindings) => {
|
||||
const migrateIfOldDefault = (actionId: KeyBindingActionId, oldDefault: readonly KeyBinding[]): boolean => {
|
||||
if (!bindingListEquals(bindings[actionId], oldDefault)) return false
|
||||
const spec = findActionSpec(actionId)
|
||||
if (!spec) return false
|
||||
bindings[actionId] = spec.defaultBindings.map((binding) => ({ ...binding }))
|
||||
return true
|
||||
}
|
||||
|
||||
const migrateIfOldDefault = (actionId: KeyBindingActionId, oldDefault: readonly KeyBinding[]): void => {
|
||||
const existing = bindings[actionId] ?? []
|
||||
if (!bindingListEquals(existing, oldDefault)) return
|
||||
const spec = findActionSpec(actionId)
|
||||
if (spec) bindings[actionId] = spec.defaultBindings.map((binding) => ({ ...binding }))
|
||||
const acceptMoved = migrateIfOldDefault('suggestion-accept', OLD_SUGGESTION_ACCEPT_DEFAULT)
|
||||
const dismissMoved = migrateIfOldDefault('suggestion-dismiss', OLD_SUGGESTION_DISMISS_DEFAULT)
|
||||
return acceptMoved || dismissMoved
|
||||
})
|
||||
}
|
||||
|
||||
// ── 키바인딩 저장 코덱 경계 ──
|
||||
//
|
||||
// 저장된 keyBindings 는 전부 core 의 decodeKeyBindingMap 으로만 해석한다. 명시적 빈 목록(사용자가
|
||||
// 단축키를 모두 지운 액션)은 보존하고, 누락·손상 항목만 기본값으로 복구한다. 설정 로딩 · IPC ·
|
||||
// 후킹 서비스 · 마이그레이션이 같은 해석을 공유해야 화면과 런타임과 저장소가 어긋나지 않는다.
|
||||
|
||||
/**
|
||||
* 저장된 키바인딩을 해석하고 migrate 로 고친 뒤, 실제로 바뀐 것이 있을 때만 다시 쓴다.
|
||||
* migrate 는 맵을 제자리에서 고치고, 무언가 바꿨으면 true 를 돌려준다.
|
||||
*/
|
||||
function updateStoredKeyBindings(
|
||||
activeStore: ElectronStore<AppConfig>,
|
||||
migrate: (bindings: KeyBindingMap) => boolean,
|
||||
): void {
|
||||
const decoded = decodeKeyBindingMap(activeStore.get('keyBindings') as unknown)
|
||||
const changed = migrate(decoded.map)
|
||||
if (decoded.repairedActions.length > 0) {
|
||||
logger.info(`Restored default key bindings for: ${decoded.repairedActions.join(', ')}`)
|
||||
}
|
||||
|
||||
migrateIfOldDefault('suggestion-accept', OLD_SUGGESTION_ACCEPT_DEFAULT)
|
||||
migrateIfOldDefault('suggestion-dismiss', OLD_SUGGESTION_DISMISS_DEFAULT)
|
||||
|
||||
activeStore.set('keyBindings', bindings)
|
||||
if (changed || decoded.needsRewrite) activeStore.set('keyBindings', decoded.map)
|
||||
}
|
||||
|
||||
// electron-store v10은 ESM 전용이므로 동적 import 필요
|
||||
|
|
@ -261,33 +279,30 @@ function isLegacyShortcut(value: unknown): value is LegacyShortcut {
|
|||
*/
|
||||
function migrateKeyBindings(activeStore: ElectronStore<AppConfig>): void {
|
||||
const raw = activeStore.store as unknown as Record<string, unknown>
|
||||
const restored: KeyBindingMap = parseBindingMap(raw.keyBindings)
|
||||
|
||||
const legacyKeys = Object.keys(LEGACY_SHORTCUT_ACTIONS).filter((key) =>
|
||||
isLegacyShortcut(raw[key]),
|
||||
)
|
||||
if (legacyKeys.length === 0) {
|
||||
activeStore.set('keyBindings', restored)
|
||||
return
|
||||
}
|
||||
|
||||
for (const key of legacyKeys) {
|
||||
const legacy = raw[key] as LegacyShortcut
|
||||
const actionId = LEGACY_SHORTCUT_ACTIONS[key]
|
||||
if (actionId === undefined) continue
|
||||
restored[actionId] = [
|
||||
normalizeBinding({
|
||||
device: 'keyboard',
|
||||
code: legacy.keyCode,
|
||||
ctrl: legacy.ctrl,
|
||||
alt: legacy.alt,
|
||||
shift: legacy.shift,
|
||||
meta: legacy.meta,
|
||||
}),
|
||||
]
|
||||
}
|
||||
updateStoredKeyBindings(activeStore, (restored) => {
|
||||
for (const key of legacyKeys) {
|
||||
const legacy = raw[key] as LegacyShortcut
|
||||
const actionId = LEGACY_SHORTCUT_ACTIONS[key]
|
||||
if (actionId === undefined) continue
|
||||
restored[actionId] = [
|
||||
normalizeBinding({
|
||||
device: 'keyboard',
|
||||
code: legacy.keyCode,
|
||||
ctrl: legacy.ctrl,
|
||||
alt: legacy.alt,
|
||||
shift: legacy.shift,
|
||||
meta: legacy.meta,
|
||||
}),
|
||||
]
|
||||
}
|
||||
return legacyKeys.length > 0
|
||||
})
|
||||
|
||||
activeStore.set('keyBindings', restored)
|
||||
if (legacyKeys.length === 0) return
|
||||
for (const key of legacyKeys) {
|
||||
activeStore.delete(key)
|
||||
}
|
||||
|
|
@ -347,6 +362,21 @@ export function configSet<K extends keyof AppConfig>(key: K, value: AppConfig[K]
|
|||
logger.debug(`Config changed: ${key}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 저장된 키바인딩 맵을 읽는다 — 모든 액션 키를 갖고, 명시적 빈 목록은 빈 목록 그대로다.
|
||||
* keyBindings 를 읽는 곳은 configGet('keyBindings') 대신 이것을 쓴다.
|
||||
*/
|
||||
export function loadKeyBindings(): KeyBindingMap {
|
||||
return decodeKeyBindingMap(configGet('keyBindings') as unknown).map
|
||||
}
|
||||
|
||||
/** 키바인딩 맵을 정규화해 저장하고, 실제로 저장한 맵을 돌려준다. */
|
||||
export function saveKeyBindings(map: KeyBindingMap): KeyBindingMap {
|
||||
const normalized = decodeKeyBindingMap(map).map
|
||||
configSet('keyBindings', normalized)
|
||||
return normalized
|
||||
}
|
||||
|
||||
export function configGetAll(): AppConfig {
|
||||
if (!store) return { ...CONFIG_DEFAULTS }
|
||||
return store.store
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue