feat(keybindings): 快捷键自定义系统 — store+冲突检测+交互式重新绑定UI | 13 files +1032/-137 | 72 tests passing tsc零错误
This commit is contained in:
1 parent
514d62644e
commit
3f636b1b0e
13 files changed
+1033
-138
No files matched your search
@@ -4,8 +4,4 @@
|
||||
* 避免硬编码,集中管理可配置参数
|
||||
*/
|
||||
|
||||
// 待实现
|
||||
// export * from './terminal'
|
||||
// export * from './sftp'
|
||||
// export * from './keybindings'
|
||||
// export * from './ui'
|
||||
export * from './keybindings'
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* Keybinding 常量定义
|
||||
*
|
||||
* 集中管理所有快捷键操作的 ID、描述、分类和默认键绑定。
|
||||
* 与 keybindingStore 配合实现快捷键自定义。
|
||||
*/
|
||||
|
||||
// ─── 快捷键操作 ID ──────────────────────────────────────
|
||||
export const KeybindingAction = {
|
||||
// 标签管理
|
||||
TAB_NEXT: 'tab.next',
|
||||
TAB_PREV: 'tab.prev',
|
||||
TAB_GOTO_N: 'tab.gotoN',
|
||||
TAB_CLOSE: 'tab.close',
|
||||
TAB_NEW: 'tab.new',
|
||||
|
||||
// 视图
|
||||
VIEW_FULLSCREEN: 'view.fullscreen',
|
||||
|
||||
// 会话
|
||||
SESSION_NEW: 'session.new',
|
||||
SESSION_QUICK_CONNECT: 'session.quickConnect',
|
||||
|
||||
// 工具
|
||||
TOOLS_COMMAND_PALETTE: 'tools.commandPalette',
|
||||
} as const
|
||||
|
||||
export type KeybindingActionId = typeof KeybindingAction[keyof typeof KeybindingAction]
|
||||
|
||||
// ─── 快捷键分类 ─────────────────────────────────────────
|
||||
export const KeybindingCategory = {
|
||||
TAB_MANAGEMENT: '标签管理',
|
||||
VIEW: '视图',
|
||||
SESSION: '会话',
|
||||
TOOLS: '工具',
|
||||
} as const
|
||||
|
||||
export type KeybindingCategoryValue = typeof KeybindingCategory[keyof typeof KeybindingCategory]
|
||||
|
||||
// ─── 单个快捷键定义 ─────────────────────────────────────
|
||||
export interface KeybindingDefinition {
|
||||
/** 操作 ID (如 'tab.next') */
|
||||
id: KeybindingActionId
|
||||
/** 操作描述 (如 '切换到下一个标签') */
|
||||
label: string
|
||||
/** 分类 */
|
||||
category: KeybindingCategoryValue
|
||||
/** 默认键绑定 (如 'Ctrl+Tab') */
|
||||
defaultKeys: string
|
||||
/** 是否在输入框中也触发 */
|
||||
fireInInput: boolean
|
||||
}
|
||||
|
||||
// ─── 所有快捷键定义 ─────────────────────────────────────
|
||||
export const KEYBINDING_DEFINITIONS: KeybindingDefinition[] = [
|
||||
{
|
||||
id: KeybindingAction.TAB_NEXT,
|
||||
label: '切换到下一个标签',
|
||||
category: KeybindingCategory.TAB_MANAGEMENT,
|
||||
defaultKeys: 'Ctrl+Tab',
|
||||
fireInInput: true,
|
||||
},
|
||||
{
|
||||
id: KeybindingAction.TAB_PREV,
|
||||
label: '切换到上一个标签',
|
||||
category: KeybindingCategory.TAB_MANAGEMENT,
|
||||
defaultKeys: 'Ctrl+Shift+Tab',
|
||||
fireInInput: true,
|
||||
},
|
||||
{
|
||||
id: KeybindingAction.TAB_GOTO_N,
|
||||
label: '跳转到第 N 个标签',
|
||||
category: KeybindingCategory.TAB_MANAGEMENT,
|
||||
defaultKeys: 'Ctrl+1…9',
|
||||
fireInInput: true,
|
||||
},
|
||||
{
|
||||
id: KeybindingAction.TAB_CLOSE,
|
||||
label: '关闭当前标签',
|
||||
category: KeybindingCategory.TAB_MANAGEMENT,
|
||||
defaultKeys: 'Ctrl+W',
|
||||
fireInInput: false,
|
||||
},
|
||||
{
|
||||
id: KeybindingAction.TAB_NEW,
|
||||
label: '新建标签',
|
||||
category: KeybindingCategory.TAB_MANAGEMENT,
|
||||
defaultKeys: 'Ctrl+Shift+N',
|
||||
fireInInput: false,
|
||||
},
|
||||
{
|
||||
id: KeybindingAction.VIEW_FULLSCREEN,
|
||||
label: '切换全屏',
|
||||
category: KeybindingCategory.VIEW,
|
||||
defaultKeys: 'F11',
|
||||
fireInInput: true,
|
||||
},
|
||||
{
|
||||
id: KeybindingAction.SESSION_NEW,
|
||||
label: '新建会话',
|
||||
category: KeybindingCategory.SESSION,
|
||||
defaultKeys: 'Ctrl+N',
|
||||
fireInInput: false,
|
||||
},
|
||||
{
|
||||
id: KeybindingAction.SESSION_QUICK_CONNECT,
|
||||
label: '快速连接',
|
||||
category: KeybindingCategory.SESSION,
|
||||
defaultKeys: 'Ctrl+K',
|
||||
fireInInput: false,
|
||||
},
|
||||
{
|
||||
id: KeybindingAction.TOOLS_COMMAND_PALETTE,
|
||||
label: '命令面板',
|
||||
category: KeybindingCategory.TOOLS,
|
||||
defaultKeys: 'Ctrl+Shift+P',
|
||||
fireInInput: true,
|
||||
},
|
||||
]
|
||||
|
||||
// ─── 通过 ID 查找定义 ────────────────────────────────────
|
||||
export function getKeybindingDefinition(id: KeybindingActionId): KeybindingDefinition | undefined {
|
||||
return KEYBINDING_DEFINITIONS.find((d) => d.id === id)
|
||||
}
|
||||
|
||||
// ─── 获取所有分类 ────────────────────────────────────────
|
||||
export function getKeybindingCategories(): KeybindingCategoryValue[] {
|
||||
return KEYBINDING_DEFINITIONS.map((d) => d.category).filter(
|
||||
(v, i, arr) => arr.indexOf(v) === i
|
||||
)
|
||||
}
|
||||
|
||||
// ─── 获取某分类下的所有定义 ──────────────────────────────
|
||||
export function getKeybindingsByCategory(category: KeybindingCategoryValue): KeybindingDefinition[] {
|
||||
return KEYBINDING_DEFINITIONS.filter((d) => d.category === category)
|
||||
}
|
||||
Reference in new issue
Block a user