diff --git a/frontend/bindings/voidraft/internal/models/models.ts b/frontend/bindings/voidraft/internal/models/models.ts index 4ca364d..ac13b81 100644 --- a/frontend/bindings/voidraft/internal/models/models.ts +++ b/frontend/bindings/voidraft/internal/models/models.ts @@ -343,11 +343,6 @@ export class Extension { */ "id": ExtensionID; - /** - * 扩展分类 - */ - "category": ExtensionCategory; - /** * 是否启用 */ @@ -368,9 +363,6 @@ export class Extension { if (!("id" in $$source)) { this["id"] = ("" as ExtensionID); } - if (!("category" in $$source)) { - this["category"] = ("" as ExtensionCategory); - } if (!("enabled" in $$source)) { this["enabled"] = false; } @@ -388,42 +380,17 @@ export class Extension { * Creates a new Extension instance from a string or object. */ static createFrom($$source: any = {}): Extension { - const $$createField4_0 = $$createType6; + const $$createField3_0 = $$createType6; let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; if ("config" in $$parsedSource) { - $$parsedSource["config"] = $$createField4_0($$parsedSource["config"]); + $$parsedSource["config"] = $$createField3_0($$parsedSource["config"]); } return new Extension($$parsedSource as Partial); } } /** - * ExtensionCategory 扩展分类 - */ -export enum ExtensionCategory { - /** - * The Go zero value for the underlying type of the enum. - */ - $zero = "", - - /** - * 编辑增强 - */ - CategoryEditing = "editing", - - /** - * 界面增强 - */ - CategoryUI = "ui", - - /** - * 工具类 - */ - CategoryTools = "tools", -}; - -/** - * ExtensionConfig 扩展配置项(动态配置) + * ExtensionConfig 扩展配置项 */ export type ExtensionConfig = { [_: string]: any }; @@ -470,6 +437,12 @@ export enum ExtensionID { * 代码块 */ ExtensionCodeBlock = "codeBlock", + + /** + * 核心扩展 + * 编辑器核心功能 + */ + ExtensionEditor = "editor", }; /** @@ -613,9 +586,9 @@ export class KeyBinding { "command": KeyBindingCommand; /** - * 快捷键分类 + * 所属扩展 */ - "category": KeyBindingCategory; + "extension": ExtensionID; /** * 快捷键组合(如 "Mod-f", "Ctrl-Shift-p") @@ -637,8 +610,8 @@ export class KeyBinding { if (!("command" in $$source)) { this["command"] = ("" as KeyBindingCommand); } - if (!("category" in $$source)) { - this["category"] = ("" as KeyBindingCategory); + if (!("extension" in $$source)) { + this["extension"] = ("" as ExtensionID); } if (!("key" in $$source)) { this["key"] = ""; @@ -662,41 +635,6 @@ export class KeyBinding { } } -/** - * KeyBindingCategory 快捷键分类 - */ -export enum KeyBindingCategory { - /** - * The Go zero value for the underlying type of the enum. - */ - $zero = "", - - /** - * 搜索相关 - */ - CategorySearch = "search", - - /** - * 编辑相关 - */ - CategoryEdit = "edit", - - /** - * 代码块相关 - */ - CategoryCodeBlock = "block", - - /** - * 历史记录相关 - */ - CategoryHistory = "history", - - /** - * 代码折叠相关 - */ - CategoryFold = "fold", -}; - /** * KeyBindingCommand 快捷键命令 */ @@ -707,7 +645,7 @@ export enum KeyBindingCommand { $zero = "", /** - * 搜索相关 + * 搜索扩展相关 * 显示搜索 */ ShowSearchCommand = "showSearch", @@ -743,7 +681,7 @@ export enum KeyBindingCommand { SearchReplaceAllCommand = "searchReplaceAll", /** - * 代码块相关 + * 代码块扩展相关 * 块内选择全部 */ BlockSelectAllCommand = "blockSelectAll", @@ -839,28 +777,7 @@ export enum KeyBindingCommand { BlockPasteCommand = "blockPaste", /** - * 历史记录相关 - * 撤销 - */ - HistoryUndoCommand = "historyUndo", - - /** - * 重做 - */ - HistoryRedoCommand = "historyRedo", - - /** - * 撤销选择 - */ - HistoryUndoSelectionCommand = "historyUndoSelection", - - /** - * 重做选择 - */ - HistoryRedoSelectionCommand = "historyRedoSelection", - - /** - * 代码折叠相关 + * 代码折叠扩展相关 * 折叠代码 */ FoldCodeCommand = "foldCode", @@ -881,7 +798,7 @@ export enum KeyBindingCommand { UnfoldAllCommand = "unfoldAll", /** - * 编辑相关 + * 通用编辑扩展相关 * 光标按语法左移 */ CursorSyntaxLeftCommand = "cursorSyntaxLeft", @@ -980,6 +897,27 @@ export enum KeyBindingCommand { * 向前删除组 */ DeleteGroupForwardCommand = "deleteGroupForward", + + /** + * 历史记录扩展相关 + * 撤销 + */ + HistoryUndoCommand = "historyUndo", + + /** + * 重做 + */ + HistoryRedoCommand = "historyRedo", + + /** + * 撤销选择 + */ + HistoryUndoSelectionCommand = "historyUndoSelection", + + /** + * 重做选择 + */ + HistoryRedoSelectionCommand = "historyRedoSelection", }; /** diff --git a/frontend/src/stores/editorStore.ts b/frontend/src/stores/editorStore.ts index b5238f2..3ca6acc 100644 --- a/frontend/src/stores/editorStore.ts +++ b/frontend/src/stores/editorStore.ts @@ -5,6 +5,7 @@ import {EditorState, Extension} from '@codemirror/state'; import {useConfigStore} from './configStore'; import {useDocumentStore} from './documentStore'; import {useThemeStore} from './themeStore'; +import {useKeybindingStore} from './keybindingStore'; import {SystemThemeType} from '@/../bindings/voidraft/internal/models/models'; import {DocumentService, ExtensionService} from '@/../bindings/voidraft/internal/services'; import {ensureSyntaxTree} from "@codemirror/language" @@ -14,7 +15,7 @@ import {getTabExtensions, updateTabConfig} from '@/views/editor/basic/tabExtensi import {createFontExtensionFromBackend, updateFontConfig} from '@/views/editor/basic/fontExtension'; import {createStatsUpdateExtension} from '@/views/editor/basic/statsExtension'; import {createAutoSavePlugin, createSaveShortcutPlugin} from '@/views/editor/basic/autoSaveExtension'; -import {createDynamicKeymapExtension} from '@/views/editor/keymap'; +import {createDynamicKeymapExtension, updateKeymapExtension} from '@/views/editor/keymap'; import {createDynamicExtensions, getExtensionManager, setExtensionManagerView} from '@/views/editor/manager'; import {useExtensionStore} from './extensionStore'; @@ -271,18 +272,31 @@ export const useEditorStore = defineStore('editor', () => { await ExtensionService.UpdateExtensionState(id, enabled, config) } - // 更新前端编辑器 + // 更新前端编辑器扩展 const manager = getExtensionManager() if (manager) { manager.updateExtension(id, enabled, config || {}) } + // 重新加载扩展配置 await extensionStore.loadExtensions() + + // 更新快捷键映射 + if (editorView.value) { + updateKeymapExtension(editorView.value) + } } catch (error) { throw error } } + // 监听扩展状态变化,自动更新快捷键 + watch(() => extensionStore.enabledExtensions.length, () => { + if (editorView.value) { + updateKeymapExtension(editorView.value) + } + }) + return { // 状态 documentStats, diff --git a/frontend/src/stores/extensionStore.ts b/frontend/src/stores/extensionStore.ts index 0c55040..4e09f40 100644 --- a/frontend/src/stores/extensionStore.ts +++ b/frontend/src/stores/extensionStore.ts @@ -12,6 +12,11 @@ export const useExtensionStore = defineStore('extension', () => { extensions.value.filter(ext => ext.enabled) ) + // 获取启用的扩展ID列表 + const enabledExtensionIds = computed(() => + enabledExtensions.value.map(ext => ext.id) + ) + /** * 从后端加载扩展配置 */ @@ -35,9 +40,10 @@ export const useExtensionStore = defineStore('extension', () => { // 状态 extensions, enabledExtensions, + enabledExtensionIds, // 方法 loadExtensions, - getExtensionConfig + getExtensionConfig, } }) \ No newline at end of file diff --git a/frontend/src/stores/keybindingStore.ts b/frontend/src/stores/keybindingStore.ts index 96bdfd4..a310df6 100644 --- a/frontend/src/stores/keybindingStore.ts +++ b/frontend/src/stores/keybindingStore.ts @@ -1,18 +1,37 @@ import {defineStore} from 'pinia' import {computed, ref} from 'vue' -import {KeyBinding, KeyBindingCommand} from '@/../bindings/voidraft/internal/models/models' +import {ExtensionID, KeyBinding, KeyBindingCommand} from '@/../bindings/voidraft/internal/models/models' import {GetAllKeyBindings} from '@/../bindings/voidraft/internal/services/keybindingservice' export const useKeybindingStore = defineStore('keybinding', () => { // 快捷键配置数据 const keyBindings = ref([]) - // 获取启用的快捷键 const enabledKeyBindings = computed(() => keyBindings.value.filter(kb => kb.enabled) ) + // 按扩展分组的快捷键 + const keyBindingsByExtension = computed(() => { + const groups = new Map() + + for (const binding of keyBindings.value) { + if (!groups.has(binding.extension)) { + groups.set(binding.extension, []) + } + groups.get(binding.extension)!.push(binding) + } + + return groups + }) + + // 获取指定扩展的快捷键 + const getKeyBindingsByExtension = computed(() => + (extension: ExtensionID) => + keyBindings.value.filter(kb => kb.extension === extension) + ) + // 按命令获取快捷键 const getKeyBindingByCommand = computed(() => (command: KeyBindingCommand) => @@ -26,7 +45,7 @@ export const useKeybindingStore = defineStore('keybinding', () => { try { keyBindings.value = await GetAllKeyBindings() } catch (err) { - console.error(err) + throw err } } @@ -37,16 +56,31 @@ export const useKeybindingStore = defineStore('keybinding', () => { return keyBindings.value.some(kb => kb.command === command && kb.enabled) } + + /** + * 获取扩展相关的所有扩展ID + */ + const getAllExtensionIds = computed(() => { + const extensionIds = new Set() + for (const binding of keyBindings.value) { + extensionIds.add(binding.extension) + } + return Array.from(extensionIds) + }) + return { // 状态 keyBindings, enabledKeyBindings, + keyBindingsByExtension, + getAllExtensionIds, // 计算属性 getKeyBindingByCommand, + getKeyBindingsByExtension, // 方法 loadKeyBindings, - hasCommand + hasCommand, } }) \ No newline at end of file diff --git a/frontend/src/views/editor/keymap/index.ts b/frontend/src/views/editor/keymap/index.ts index 70d2f79..00977a0 100644 --- a/frontend/src/views/editor/keymap/index.ts +++ b/frontend/src/views/editor/keymap/index.ts @@ -1,20 +1,55 @@ import { Extension } from '@codemirror/state' import { useKeybindingStore } from '@/stores/keybindingStore' +import { useExtensionStore } from '@/stores/extensionStore' import { KeymapManager } from './keymapManager' +import { ExtensionID } from '@/../bindings/voidraft/internal/models/models' /** * 异步创建快捷键扩展 - * 确保快捷键配置已加载 + * 确保快捷键配置和扩展配置已加载 */ export const createDynamicKeymapExtension = async (): Promise => { const keybindingStore = useKeybindingStore() + const extensionStore = useExtensionStore() // 确保快捷键配置已加载 if (keybindingStore.keyBindings.length === 0) { await keybindingStore.loadKeyBindings() } - return KeymapManager.createKeymapExtension(keybindingStore.enabledKeyBindings) + // 确保扩展配置已加载 + if (extensionStore.extensions.length === 0) { + await extensionStore.loadExtensions() + } + + // 获取启用的扩展ID列表 + const enabledExtensionIds = extensionStore.enabledExtensions.map(ext => ext.id) + + return KeymapManager.createKeymapExtension(keybindingStore.keyBindings, enabledExtensionIds) +} + +/** + * 更新快捷键映射 + * @param view 编辑器视图 + */ +export const updateKeymapExtension = (view: any): void => { + const keybindingStore = useKeybindingStore() + const extensionStore = useExtensionStore() + + // 获取启用的扩展ID列表 + const enabledExtensionIds = extensionStore.enabledExtensions.map(ext => ext.id) + + KeymapManager.updateKeymap(view, keybindingStore.keyBindings, enabledExtensionIds) +} + +/** + * 获取指定扩展的快捷键 + * @param extensionId 扩展ID + * @returns 该扩展的快捷键列表 + */ +export const getExtensionKeyBindings = (extensionId: ExtensionID) => { + const keybindingStore = useKeybindingStore() + return keybindingStore.getKeyBindingsByExtension(extensionId) } // 导出相关模块 diff --git a/frontend/src/views/editor/keymap/keymapManager.ts b/frontend/src/views/editor/keymap/keymapManager.ts index 93615db..6b47fda 100644 --- a/frontend/src/views/editor/keymap/keymapManager.ts +++ b/frontend/src/views/editor/keymap/keymapManager.ts @@ -1,6 +1,6 @@ import {keymap} from '@codemirror/view' -import {Extension} from '@codemirror/state' -import {KeyBinding as KeyBindingConfig} from '@/../bindings/voidraft/internal/models/models' +import {Extension, Compartment} from '@codemirror/state' +import {KeyBinding as KeyBindingConfig, ExtensionID} from '@/../bindings/voidraft/internal/models/models' import {KeyBinding, KeymapResult} from './types' import {getCommandHandler, isCommandRegistered} from './commandRegistry' @@ -9,12 +9,15 @@ import {getCommandHandler, isCommandRegistered} from './commandRegistry' * 负责将后端配置转换为CodeMirror快捷键扩展 */ export class KeymapManager { + private static compartment = new Compartment() + /** * 将后端快捷键配置转换为CodeMirror快捷键绑定 * @param keyBindings 后端快捷键配置列表 + * @param enabledExtensions 启用的扩展ID列表,如果不提供则使用所有启用的快捷键 * @returns 转换结果 */ - static convertToKeyBindings(keyBindings: KeyBindingConfig[]): KeymapResult { + static convertToKeyBindings(keyBindings: KeyBindingConfig[], enabledExtensions?: ExtensionID[]): KeymapResult { const result: KeyBinding[] = [] for (const binding of keyBindings) { @@ -23,6 +26,11 @@ export class KeymapManager { continue } + // 如果提供了扩展列表,则只处理启用扩展的快捷键 + if (enabledExtensions && !enabledExtensions.includes(binding.extension)) { + continue + } + // 检查命令是否已注册 if (!isCommandRegistered(binding.command)) { continue @@ -50,13 +58,47 @@ export class KeymapManager { /** * 创建CodeMirror快捷键扩展 * @param keyBindings 后端快捷键配置列表 + * @param enabledExtensions 启用的扩展ID列表 * @returns CodeMirror扩展 */ - static createKeymapExtension(keyBindings: KeyBindingConfig[]): Extension { + static createKeymapExtension(keyBindings: KeyBindingConfig[], enabledExtensions?: ExtensionID[]): Extension { const {keyBindings: cmKeyBindings} = - this.convertToKeyBindings(keyBindings) + this.convertToKeyBindings(keyBindings, enabledExtensions) - return keymap.of(cmKeyBindings) + return this.compartment.of(keymap.of(cmKeyBindings)) + } + + /** + * 动态更新快捷键扩展 + * @param view 编辑器视图 + * @param keyBindings 后端快捷键配置列表 + * @param enabledExtensions 启用的扩展ID列表 + */ + static updateKeymap(view: any, keyBindings: KeyBindingConfig[], enabledExtensions: ExtensionID[]): void { + const {keyBindings: cmKeyBindings} = + this.convertToKeyBindings(keyBindings, enabledExtensions) + + view.dispatch({ + effects: this.compartment.reconfigure(keymap.of(cmKeyBindings)) + }) + } + + /** + * 按扩展分组快捷键 + * @param keyBindings 快捷键配置列表 + * @returns 按扩展分组的快捷键映射 + */ + static groupByExtension(keyBindings: KeyBindingConfig[]): Map { + const groups = new Map() + + for (const binding of keyBindings) { + if (!groups.has(binding.extension)) { + groups.set(binding.extension, []) + } + groups.get(binding.extension)!.push(binding) + } + + return groups } /** diff --git a/frontend/src/views/settings/pages/KeyBindingsPage.vue b/frontend/src/views/settings/pages/KeyBindingsPage.vue index f1be592..f5f6c44 100644 --- a/frontend/src/views/settings/pages/KeyBindingsPage.vue +++ b/frontend/src/views/settings/pages/KeyBindingsPage.vue @@ -3,23 +3,33 @@ import { useI18n } from 'vue-i18n'; import { onMounted, computed } from 'vue'; import SettingSection from '../components/SettingSection.vue'; import { useKeybindingStore } from '@/stores/keybindingStore'; +import { useExtensionStore } from '@/stores/extensionStore'; import { useSystemStore } from '@/stores/systemStore'; import { getCommandDescription } from '@/views/editor/keymap/commandRegistry'; import {KeyBindingCommand} from "@/../bindings/voidraft/internal/models"; const { t } = useI18n(); const keybindingStore = useKeybindingStore(); +const extensionStore = useExtensionStore(); const systemStore = useSystemStore(); +// 加载数据 +onMounted(async () => { + await keybindingStore.loadKeyBindings(); + await extensionStore.loadExtensions(); +}); // 从store中获取快捷键数据并转换为显示格式 const keyBindings = computed(() => { + // 只显示启用扩展的快捷键 + const enabledExtensionIds = new Set(extensionStore.enabledExtensionIds); + return keybindingStore.keyBindings - .filter(kb => kb.enabled) + .filter(kb => kb.enabled && enabledExtensionIds.has(kb.extension)) .map(kb => ({ id: kb.command, keys: parseKeyBinding(kb.key, kb.command), - category: kb.category, + category: kb.extension, description: getCommandDescription(kb.command) || kb.command })); }); diff --git a/internal/models/extensions.go b/internal/models/extensions.go index 9d4ca57..678a891 100644 --- a/internal/models/extensions.go +++ b/internal/models/extensions.go @@ -4,11 +4,10 @@ import "time" // Extension 单个扩展配置 type Extension struct { - ID ExtensionID `json:"id"` // 扩展唯一标识 - Category ExtensionCategory `json:"category"` // 扩展分类 - Enabled bool `json:"enabled"` // 是否启用 - IsDefault bool `json:"isDefault"` // 是否为默认扩展 - Config ExtensionConfig `json:"config"` // 扩展配置项 + ID ExtensionID `json:"id"` // 扩展唯一标识 + Enabled bool `json:"enabled"` // 是否启用 + IsDefault bool `json:"isDefault"` // 是否为默认扩展 + Config ExtensionConfig `json:"config"` // 扩展配置项 } // ExtensionID 扩展标识符 @@ -28,18 +27,12 @@ const ( // 工具扩展 ExtensionSearch ExtensionID = "search" // 搜索功能 ExtensionCodeBlock ExtensionID = "codeBlock" // 代码块 + + // 核心扩展 + ExtensionEditor ExtensionID = "editor" // 编辑器核心功能 ) -// ExtensionCategory 扩展分类 -type ExtensionCategory string - -const ( - CategoryEditing ExtensionCategory = "editing" // 编辑增强 - CategoryUI ExtensionCategory = "ui" // 界面增强 - CategoryTools ExtensionCategory = "tools" // 工具类 -) - -// ExtensionConfig 扩展配置项(动态配置) +// ExtensionConfig 扩展配置项 type ExtensionConfig map[string]interface{} // ExtensionMetadata 扩展配置元数据 @@ -71,21 +64,30 @@ func NewDefaultExtensions() []Extension { // 编辑增强扩展 { ID: ExtensionRainbowBrackets, - Category: CategoryEditing, Enabled: true, IsDefault: true, Config: ExtensionConfig{}, }, { ID: ExtensionHyperlink, - Category: CategoryEditing, Enabled: true, IsDefault: true, Config: ExtensionConfig{}, }, { ID: ExtensionColorSelector, - Category: CategoryEditing, + Enabled: true, + IsDefault: true, + Config: ExtensionConfig{}, + }, + { + ID: ExtensionFold, + Enabled: true, + IsDefault: true, + Config: ExtensionConfig{}, + }, + { + ID: ExtensionTextHighlight, Enabled: true, IsDefault: true, Config: ExtensionConfig{}, @@ -94,7 +96,6 @@ func NewDefaultExtensions() []Extension { // UI增强扩展 { ID: ExtensionMinimap, - Category: CategoryUI, Enabled: true, IsDefault: true, Config: ExtensionConfig{ @@ -107,14 +108,12 @@ func NewDefaultExtensions() []Extension { // 工具扩展 { ID: ExtensionSearch, - Category: CategoryTools, Enabled: true, IsDefault: true, Config: ExtensionConfig{}, }, { ID: ExtensionCodeBlock, - Category: CategoryTools, Enabled: true, IsDefault: true, Config: ExtensionConfig{ @@ -122,16 +121,10 @@ func NewDefaultExtensions() []Extension { "enableAutoDetection": true, }, }, + + // 核心扩展 { - ID: ExtensionFold, - Category: CategoryEditing, - Enabled: true, - IsDefault: true, - Config: ExtensionConfig{}, - }, - { - ID: ExtensionTextHighlight, - Category: CategoryEditing, + ID: ExtensionEditor, Enabled: true, IsDefault: true, Config: ExtensionConfig{}, diff --git a/internal/models/key_bindings.go b/internal/models/key_bindings.go index 711afe3..79c755d 100644 --- a/internal/models/key_bindings.go +++ b/internal/models/key_bindings.go @@ -4,29 +4,18 @@ import "time" // KeyBinding 单个快捷键绑定 type KeyBinding struct { - Command KeyBindingCommand `json:"command"` // 快捷键动作 - Category KeyBindingCategory `json:"category"` // 快捷键分类 - Key string `json:"key"` // 快捷键组合(如 "Mod-f", "Ctrl-Shift-p") - Enabled bool `json:"enabled"` // 是否启用 - IsDefault bool `json:"isDefault"` // 是否为默认快捷键 + Command KeyBindingCommand `json:"command"` // 快捷键动作 + Extension ExtensionID `json:"extension"` // 所属扩展 + Key string `json:"key"` // 快捷键组合(如 "Mod-f", "Ctrl-Shift-p") + Enabled bool `json:"enabled"` // 是否启用 + IsDefault bool `json:"isDefault"` // 是否为默认快捷键 } -// KeyBindingCategory 快捷键分类 -type KeyBindingCategory string - -const ( - CategorySearch KeyBindingCategory = "search" // 搜索相关 - CategoryEdit KeyBindingCategory = "edit" // 编辑相关 - CategoryCodeBlock KeyBindingCategory = "block" // 代码块相关 - CategoryHistory KeyBindingCategory = "history" // 历史记录相关 - CategoryFold KeyBindingCategory = "fold" // 代码折叠相关 -) - // KeyBindingCommand 快捷键命令 type KeyBindingCommand string const ( - // 搜索相关 + // 搜索扩展相关 ShowSearchCommand KeyBindingCommand = "showSearch" // 显示搜索 HideSearchCommand KeyBindingCommand = "hideSearch" // 隐藏搜索 SearchToggleCaseCommand KeyBindingCommand = "searchToggleCase" // 搜索切换大小写 @@ -35,7 +24,7 @@ const ( SearchShowReplaceCommand KeyBindingCommand = "searchShowReplace" // 显示替换 SearchReplaceAllCommand KeyBindingCommand = "searchReplaceAll" // 替换全部 - // 代码块相关 + // 代码块扩展相关 BlockSelectAllCommand KeyBindingCommand = "blockSelectAll" // 块内选择全部 BlockAddAfterCurrentCommand KeyBindingCommand = "blockAddAfterCurrent" // 在当前块后添加新块 BlockAddAfterLastCommand KeyBindingCommand = "blockAddAfterLast" // 在最后添加新块 @@ -56,19 +45,13 @@ const ( BlockCutCommand KeyBindingCommand = "blockCut" // 剪切 BlockPasteCommand KeyBindingCommand = "blockPaste" // 粘贴 - // 历史记录相关 - HistoryUndoCommand KeyBindingCommand = "historyUndo" // 撤销 - HistoryRedoCommand KeyBindingCommand = "historyRedo" // 重做 - HistoryUndoSelectionCommand KeyBindingCommand = "historyUndoSelection" // 撤销选择 - HistoryRedoSelectionCommand KeyBindingCommand = "historyRedoSelection" // 重做选择 - - // 代码折叠相关 + // 代码折叠扩展相关 FoldCodeCommand KeyBindingCommand = "foldCode" // 折叠代码 UnfoldCodeCommand KeyBindingCommand = "unfoldCode" // 展开代码 FoldAllCommand KeyBindingCommand = "foldAll" // 折叠全部 UnfoldAllCommand KeyBindingCommand = "unfoldAll" // 展开全部 - // 编辑相关 + // 通用编辑扩展相关 CursorSyntaxLeftCommand KeyBindingCommand = "cursorSyntaxLeft" // 光标按语法左移 CursorSyntaxRightCommand KeyBindingCommand = "cursorSyntaxRight" // 光标按语法右移 SelectSyntaxLeftCommand KeyBindingCommand = "selectSyntaxLeft" // 按语法选择左侧 @@ -89,6 +72,12 @@ const ( DeleteCharForwardCommand KeyBindingCommand = "deleteCharForward" // 向前删除字符 DeleteGroupBackwardCommand KeyBindingCommand = "deleteGroupBackward" // 向后删除组 DeleteGroupForwardCommand KeyBindingCommand = "deleteGroupForward" // 向前删除组 + + // 历史记录扩展相关 + HistoryUndoCommand KeyBindingCommand = "historyUndo" // 撤销 + HistoryRedoCommand KeyBindingCommand = "historyRedo" // 重做 + HistoryUndoSelectionCommand KeyBindingCommand = "historyUndoSelection" // 撤销选择 + HistoryRedoSelectionCommand KeyBindingCommand = "historyRedoSelection" // 重做选择 ) // KeyBindingMetadata 快捷键配置元数据 @@ -117,389 +106,389 @@ func NewDefaultKeyBindingConfig() *KeyBindingConfig { // NewDefaultKeyBindings 创建默认快捷键配置 func NewDefaultKeyBindings() []KeyBinding { return []KeyBinding{ - // 搜索相关快捷键 + // 搜索扩展快捷键 { Command: ShowSearchCommand, - Category: CategorySearch, + Extension: ExtensionSearch, Key: "Mod-f", Enabled: true, IsDefault: true, }, { Command: HideSearchCommand, - Category: CategorySearch, + Extension: ExtensionSearch, Key: "Escape", Enabled: true, IsDefault: true, }, { Command: SearchToggleCaseCommand, - Category: CategorySearch, + Extension: ExtensionSearch, Key: "Alt-c", Enabled: true, IsDefault: true, }, { Command: SearchToggleWordCommand, - Category: CategorySearch, + Extension: ExtensionSearch, Key: "Alt-w", Enabled: true, IsDefault: true, }, { Command: SearchToggleRegexCommand, - Category: CategorySearch, + Extension: ExtensionSearch, Key: "Alt-r", Enabled: true, IsDefault: true, }, { Command: SearchShowReplaceCommand, - Category: CategorySearch, + Extension: ExtensionSearch, Key: "Mod-h", Enabled: true, IsDefault: true, }, { Command: SearchReplaceAllCommand, - Category: CategorySearch, + Extension: ExtensionSearch, Key: "Mod-Alt-Enter", Enabled: true, IsDefault: true, }, - // 代码块相关快捷键 + // 代码块扩展快捷键 { Command: BlockSelectAllCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Mod-a", Enabled: true, IsDefault: true, }, { Command: BlockAddAfterCurrentCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Mod-Enter", Enabled: true, IsDefault: true, }, { Command: BlockAddAfterLastCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Mod-Shift-Enter", Enabled: true, IsDefault: true, }, { Command: BlockAddBeforeCurrentCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Alt-Enter", Enabled: true, IsDefault: true, }, { Command: BlockGotoPreviousCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Mod-ArrowUp", Enabled: true, IsDefault: true, }, { Command: BlockGotoNextCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Mod-ArrowDown", Enabled: true, IsDefault: true, }, { Command: BlockSelectPreviousCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Mod-Shift-ArrowUp", Enabled: true, IsDefault: true, }, { Command: BlockSelectNextCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Mod-Shift-ArrowDown", Enabled: true, IsDefault: true, }, { Command: BlockDeleteCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Mod-Shift-d", Enabled: true, IsDefault: true, }, { Command: BlockMoveUpCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Alt-Mod-ArrowUp", Enabled: true, IsDefault: true, }, { Command: BlockMoveDownCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Alt-Mod-ArrowDown", Enabled: true, IsDefault: true, }, { Command: BlockDeleteLineCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Mod-Shift-k", Enabled: true, IsDefault: true, }, { Command: BlockMoveLineUpCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Alt-ArrowUp", Enabled: true, IsDefault: true, }, { Command: BlockMoveLineDownCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Alt-ArrowDown", Enabled: true, IsDefault: true, }, { Command: BlockTransposeCharsCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Ctrl-t", Enabled: true, IsDefault: true, }, { Command: BlockFormatCommand, - Category: CategoryCodeBlock, + Extension: ExtensionCodeBlock, Key: "Mod-Shift-f", Enabled: true, IsDefault: true, }, { Command: BlockCopyCommand, - Category: CategoryCodeBlock, + Extension: ExtensionEditor, Key: "Mod-c", Enabled: true, IsDefault: true, }, { Command: BlockCutCommand, - Category: CategoryCodeBlock, + Extension: ExtensionEditor, Key: "Mod-x", Enabled: true, IsDefault: true, }, { Command: BlockPasteCommand, - Category: CategoryCodeBlock, + Extension: ExtensionEditor, Key: "Mod-v", Enabled: true, IsDefault: true, }, - // 历史记录相关快捷键 - { - Command: HistoryUndoCommand, - Category: CategoryHistory, - Key: "Mod-z", - Enabled: true, - IsDefault: true, - }, - { - Command: HistoryRedoCommand, - Category: CategoryHistory, - Key: "Mod-Shift-z", - Enabled: true, - IsDefault: true, - }, - { - Command: HistoryUndoSelectionCommand, - Category: CategoryHistory, - Key: "Mod-u", - Enabled: true, - IsDefault: true, - }, - { - Command: HistoryRedoSelectionCommand, - Category: CategoryHistory, - Key: "Mod-Shift-u", - Enabled: true, - IsDefault: true, - }, - - // 代码折叠相关快捷键 + // 代码折叠扩展快捷键 { Command: FoldCodeCommand, - Category: CategoryFold, + Extension: ExtensionFold, Key: "Ctrl-Shift-[", Enabled: true, IsDefault: true, }, { Command: UnfoldCodeCommand, - Category: CategoryFold, + Extension: ExtensionFold, Key: "Ctrl-Shift-]", Enabled: true, IsDefault: true, }, { Command: FoldAllCommand, - Category: CategoryFold, + Extension: ExtensionFold, Key: "Ctrl-Alt-[", Enabled: true, IsDefault: true, }, { Command: UnfoldAllCommand, - Category: CategoryFold, + Extension: ExtensionFold, Key: "Ctrl-Alt-]", Enabled: true, IsDefault: true, }, - // 编辑相关快捷键 (避免冲突的快捷键) + // 历史记录扩展快捷键 + { + Command: HistoryUndoCommand, + Extension: ExtensionEditor, + Key: "Mod-z", + Enabled: true, + IsDefault: true, + }, + { + Command: HistoryRedoCommand, + Extension: ExtensionEditor, + Key: "Mod-Shift-z", + Enabled: true, + IsDefault: true, + }, + { + Command: HistoryUndoSelectionCommand, + Extension: ExtensionEditor, + Key: "Mod-u", + Enabled: true, + IsDefault: true, + }, + { + Command: HistoryRedoSelectionCommand, + Extension: ExtensionEditor, + Key: "Mod-Shift-u", + Enabled: true, + IsDefault: true, + }, + + // 通用编辑扩展快捷键 { Command: CursorSyntaxLeftCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Alt-ArrowLeft", Enabled: true, IsDefault: true, }, { Command: CursorSyntaxRightCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Alt-ArrowRight", Enabled: true, IsDefault: true, }, { Command: SelectSyntaxLeftCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Shift-Alt-ArrowLeft", Enabled: true, IsDefault: true, }, { Command: SelectSyntaxRightCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Shift-Alt-ArrowRight", Enabled: true, IsDefault: true, }, { Command: CopyLineUpCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Shift-Alt-ArrowUp", Enabled: true, IsDefault: true, }, { Command: CopyLineDownCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Shift-Alt-ArrowDown", Enabled: true, IsDefault: true, }, { Command: InsertBlankLineCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Ctrl-Enter", Enabled: true, IsDefault: true, }, { Command: SelectLineCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Alt-l", Enabled: true, IsDefault: true, }, { Command: SelectParentSyntaxCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Ctrl-i", Enabled: true, IsDefault: true, }, { Command: IndentLessCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Ctrl-[", Enabled: true, IsDefault: true, }, { Command: IndentMoreCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Ctrl-]", Enabled: true, IsDefault: true, }, { Command: IndentSelectionCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Ctrl-Alt-\\", Enabled: true, IsDefault: true, }, { Command: CursorMatchingBracketCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Shift-Ctrl-\\", Enabled: true, IsDefault: true, }, { Command: ToggleCommentCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Ctrl-/", Enabled: true, IsDefault: true, }, { Command: ToggleBlockCommentCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Shift-Alt-a", Enabled: true, IsDefault: true, }, { Command: InsertNewlineAndIndentCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Enter", Enabled: true, IsDefault: true, }, { Command: DeleteCharBackwardCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Backspace", Enabled: true, IsDefault: true, }, { Command: DeleteCharForwardCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Delete", Enabled: true, IsDefault: true, }, { Command: DeleteGroupBackwardCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Ctrl-Backspace", Enabled: true, IsDefault: true, }, { Command: DeleteGroupForwardCommand, - Category: CategoryEdit, + Extension: ExtensionEditor, Key: "Ctrl-Delete", Enabled: true, IsDefault: true,