dsh-vscode-mode 0.1.63 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/lib/client.js +919 -43
- package/lib/client.js.map +1 -1
- package/lib/index.js +7 -2
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/client/commandBridge.ts +83 -0
- package/src/client/commandGlobals.ts +13 -0
- package/src/client/commandPaletteStore.ts +165 -0
- package/src/client/commandRegistry.ts +144 -0
- package/src/client/commandSearch.ts +89 -0
- package/src/client/editorModelState.ts +30 -0
- package/src/client/index.ts +32 -0
- package/src/client/keybindings.ts +71 -17
- package/src/client/styles/editor.css +14 -0
- package/src/client/ui/CommandPalette.ts +158 -0
- package/src/client/ui/ConversationDiffDock.ts +17 -9
- package/src/client/ui/EditorView.ts +90 -3
- package/src/client/ui/KeybindingsPanel.ts +1 -1
- package/src/client/ui/QuickOpen.ts +11 -3
- package/src/client/ui/commandCatalog.ts +179 -0
- package/src/shared/keybindings.ts +7 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-vscode-mode client — 编辑器指令目录(纯元数据)。
|
|
3
|
+
* 「一条命令 = 一条注册数据」:命令栏、快捷键设置页、快捷键监听与 Monaco 右键菜单
|
|
4
|
+
* 全部从本表读取;新增一条能力只需在 EDITOR_COMMANDS 追加一项(可选 keybinding)。
|
|
5
|
+
* run 只派发 `edrv.command.*` 窗口事件,不直接触碰 React/Monaco(`edrv.command.` 前缀
|
|
6
|
+
* 与既有 `edrv:` 刷新/主题事件分属不同命名空间,互不干扰)。
|
|
7
|
+
* 作者 ddj 2026年09月10号
|
|
8
|
+
*/
|
|
9
|
+
import { hasEditorModel } from '../editorModelState.js'
|
|
10
|
+
|
|
11
|
+
/** 一条编辑器指令(展示 + 执行 + 可用性)。 */
|
|
12
|
+
export interface CommandDef {
|
|
13
|
+
/** 稳定命令 id(`edrv.` 前缀;第三方注册请避让该前缀)。 */
|
|
14
|
+
id: string
|
|
15
|
+
/** 命令栏与设置页展示名。 */
|
|
16
|
+
label: string
|
|
17
|
+
/** 命令栏分组名。 */
|
|
18
|
+
category: string
|
|
19
|
+
/** 组内排序(小者优先)。 */
|
|
20
|
+
order?: number
|
|
21
|
+
/** 默认键位弦(可选;可含 `|` 多候选)。声明后由快捷键设置页展示与录制。 */
|
|
22
|
+
keybinding?: string
|
|
23
|
+
/** 运行体:派发窗口事件或直接执行。 */
|
|
24
|
+
run: () => void
|
|
25
|
+
/** 可用性判定(缺省视为始终可用;返回 false 时命令栏隐藏且 run 被拒)。 */
|
|
26
|
+
available?: () => boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 派发编辑器命令事件(`edrv.command.<action>`)。
|
|
31
|
+
* 无 window 的运行环境(纯 Node 单测)静默跳过,命令本身不因此失败。
|
|
32
|
+
* @author ddj 2026年09月10号
|
|
33
|
+
* @param action 动作名(不含前缀)
|
|
34
|
+
*/
|
|
35
|
+
function emit(action: string): void {
|
|
36
|
+
if (typeof window === 'undefined') return
|
|
37
|
+
window.dispatchEvent(new CustomEvent('edrv.command.' + action))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 编辑器命令事件名前缀(EditorView / QuickOpen / 第三方据此监听)。 */
|
|
41
|
+
export const COMMAND_EVENT_PREFIX = 'edrv.command.'
|
|
42
|
+
|
|
43
|
+
/** 需要活动编辑器模型才可用的命令(命令栏隐藏并拒绝执行)。 */
|
|
44
|
+
function needsModel(): boolean {
|
|
45
|
+
return hasEditorModel()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 面板区显隐切换始终可用(未挂载编辑器时 run 为空操作)。 */
|
|
49
|
+
function alwaysAvailable(): boolean {
|
|
50
|
+
return true
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 光标整行下移(编辑行导航)。
|
|
55
|
+
* @author ddj 2026年09月10号
|
|
56
|
+
* @returns 命令定义
|
|
57
|
+
*/
|
|
58
|
+
function nextEditorRowDef(): CommandDef {
|
|
59
|
+
return {
|
|
60
|
+
id: 'edrv.nextEditorRow', label: '下一编辑行(光标整行下移)', category: '导航', order: 50,
|
|
61
|
+
keybinding: 'Ctrl+Alt+ArrowDown', available: needsModel,
|
|
62
|
+
run: () => emit('nextEditorRow'),
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 光标整行上移(编辑行导航)。
|
|
68
|
+
* @author ddj 2026年09月10号
|
|
69
|
+
* @returns 命令定义
|
|
70
|
+
*/
|
|
71
|
+
function prevEditorRowDef(): CommandDef {
|
|
72
|
+
return {
|
|
73
|
+
id: 'edrv.prevEditorRow', label: '上一编辑行(光标整行上移)', category: '导航', order: 60,
|
|
74
|
+
keybinding: 'Ctrl+Alt+ArrowUp', available: needsModel,
|
|
75
|
+
run: () => emit('prevEditorRow'),
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 编辑器内置指令目录(顺序 = 快捷键设置页展示顺序)。
|
|
81
|
+
* 前置 8 条的键位由 EditorView / QuickOpen 自行 capture 监听(历史实现),
|
|
82
|
+
* 故不进 BRIDGE_COMMANDS,避免同一按键双执行。
|
|
83
|
+
* @author ddj 2026年09月10号
|
|
84
|
+
*/
|
|
85
|
+
export const EDITOR_COMMANDS: readonly CommandDef[] = [
|
|
86
|
+
{
|
|
87
|
+
id: 'edrv.save', label: '保存文件', category: '文件', order: 10,
|
|
88
|
+
keybinding: 'Ctrl+S', available: needsModel,
|
|
89
|
+
run: () => emit('save'),
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: 'edrv.quickOpen', label: '快速打开文件', category: '文件', order: 20,
|
|
93
|
+
keybinding: 'Ctrl+P', available: alwaysAvailable,
|
|
94
|
+
run: () => emit('quickOpen'),
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: 'edrv.toggleSidebar', label: '切换侧边栏', category: '视图', order: 10,
|
|
98
|
+
keybinding: 'Ctrl+B', available: alwaysAvailable,
|
|
99
|
+
run: () => emit('toggleSidebar'),
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: 'edrv.searchInFiles', label: '在工作区中搜索', category: '视图', order: 20,
|
|
103
|
+
keybinding: 'Ctrl+Shift+F', available: alwaysAvailable,
|
|
104
|
+
run: () => emit('searchInFiles'),
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: 'edrv.navigateBack', label: '后退(导航历史)', category: '导航', order: 10,
|
|
108
|
+
keybinding: 'Alt+ArrowLeft|Ctrl+Alt+-', available: needsModel,
|
|
109
|
+
run: () => emit('navigateBack'),
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: 'edrv.navigateForward', label: '前进(导航历史)', category: '导航', order: 20,
|
|
113
|
+
keybinding: 'Alt+ArrowRight|Ctrl+Shift+-', available: needsModel,
|
|
114
|
+
run: () => emit('navigateForward'),
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: 'edrv.nextTab', label: '下一个页签', category: '导航', order: 30,
|
|
118
|
+
keybinding: 'Ctrl+Alt+ArrowRight|Ctrl+PageDown', available: needsModel,
|
|
119
|
+
run: () => emit('nextTab'),
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
id: 'edrv.prevTab', label: '上一个页签', category: '导航', order: 40,
|
|
123
|
+
keybinding: 'Ctrl+Alt+ArrowLeft|Ctrl+PageUp', available: needsModel,
|
|
124
|
+
run: () => emit('prevTab'),
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: 'edrv.goToDefinition', label: '转到定义', category: '语言智能', order: 10,
|
|
128
|
+
available: needsModel,
|
|
129
|
+
run: () => emit('goToDefinition'),
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: 'edrv.findReferences', label: '查找所有引用', category: '语言智能', order: 20,
|
|
133
|
+
available: needsModel,
|
|
134
|
+
run: () => emit('findReferences'),
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: 'edrv.triggerAi', label: '触发 AI 内联补全', category: '语言智能', order: 30,
|
|
138
|
+
available: needsModel,
|
|
139
|
+
run: () => emit('triggerAi'),
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: 'edrv.openInExplorer', label: '在文件浏览器中打开', category: '文件', order: 30,
|
|
143
|
+
available: needsModel,
|
|
144
|
+
run: () => emit('openInExplorer'),
|
|
145
|
+
},
|
|
146
|
+
]
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 桥接派发指令(无原生监听,键位由 commandBridge 统一 capture 处理)。
|
|
150
|
+
* 新增「只填目录、不写监听」的编辑器指令一律放这里:键位、命令栏、设置页自动可用。
|
|
151
|
+
* @author ddj 2026年09月10号
|
|
152
|
+
*/
|
|
153
|
+
export const BRIDGE_COMMANDS: readonly CommandDef[] = [
|
|
154
|
+
nextEditorRowDef(),
|
|
155
|
+
prevEditorRowDef(),
|
|
156
|
+
]
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 命令栏自身的命令(避免循环依赖,由 commandBridge 注入 run 后注册)。
|
|
160
|
+
* @author ddj 2026年09月10号
|
|
161
|
+
* @param run 打开命令栏
|
|
162
|
+
* @returns 命令定义
|
|
163
|
+
*/
|
|
164
|
+
export function showCommandsDef(run: () => void): CommandDef {
|
|
165
|
+
return {
|
|
166
|
+
id: 'edrv.showCommands', label: '显示所有命令', category: '视图', order: 1,
|
|
167
|
+
keybinding: 'Ctrl+Shift+P|F1', available: alwaysAvailable, run,
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 需要全局键位派发的指令(桥接类 + 命令栏自身;不含 EditorView/QuickOpen 原生监听的那些)。
|
|
173
|
+
* @author ddj 2026年09月10号
|
|
174
|
+
* @param showCommands 命令栏命令定义
|
|
175
|
+
* @returns 派发集合
|
|
176
|
+
*/
|
|
177
|
+
export function dispatchedCommands(showCommands: CommandDef): readonly CommandDef[] {
|
|
178
|
+
return [...BRIDGE_COMMANDS, showCommands]
|
|
179
|
+
}
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* 纯数据模块:host(settings schema 默认值)与 client(执行匹配/设置页)共用。
|
|
4
4
|
* 键位格式:修饰符 + 主键,`+` 连接,如 `Ctrl+Shift+F`;空串 = 未绑定;
|
|
5
5
|
* `|` 连接多个候选(任一命中即触发),如 `Alt+ArrowLeft|Ctrl+Alt+-`。
|
|
6
|
-
*
|
|
6
|
+
* 约束:本模块被 host 与 client 两半共用,**禁止 import client 侧模块**(React/浏览器 API)。
|
|
7
|
+
* 与 client/ui/commandCatalog 的一致性由 tests/commands.test.ts 断言兜底。
|
|
8
|
+
* 作者 ddj 2026年08月26号 / 2026年09月10号
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
11
|
/** 命令 id → 默认键位(可为多候选)。命令目录以此为准,新增命令只需加一项。 */
|
|
@@ -17,6 +19,10 @@ export const KEYBINDING_DEFAULTS: Record<string, string> = {
|
|
|
17
19
|
// 页签循环:主候选避开浏览器保留键(Ctrl+Tab / Ctrl+PgUp/PgDn 会被浏览器截获)
|
|
18
20
|
'edrv.nextTab': 'Ctrl+Alt+ArrowRight|Ctrl+PageDown',
|
|
19
21
|
'edrv.prevTab': 'Ctrl+Alt+ArrowLeft|Ctrl+PageUp',
|
|
22
|
+
// 命令栏(Ctrl+Shift+P 主候选;F1 为 VS Code 同款第二候选)与编辑行导航
|
|
23
|
+
'edrv.showCommands': 'Ctrl+Shift+P|F1',
|
|
24
|
+
'edrv.nextEditorRow': 'Ctrl+Alt+ArrowDown',
|
|
25
|
+
'edrv.prevEditorRow': 'Ctrl+Alt+ArrowUp',
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
/**
|