🎨 Updated

This commit is contained in:
2025-06-20 13:46:13 +08:00
parent 85544ba1e4
commit cb3d369aef
4 changed files with 49 additions and 130 deletions

View File

@@ -453,11 +453,6 @@ export class HotkeyCombo {
* KeyBinding 单个快捷键绑定
*/
export class KeyBinding {
/**
* 快捷键唯一标识
*/
"id": string;
/**
* 快捷键动作
*/
@@ -490,9 +485,6 @@ export class KeyBinding {
/** Creates a new KeyBinding instance. */
constructor($$source: Partial<KeyBinding> = {}) {
if (!("id" in $$source)) {
this["id"] = "";
}
if (!("action" in $$source)) {
this["action"] = ("" as KeyBindingAction);
}

View File

@@ -17,16 +17,16 @@ import * as models$0 from "../models/models.js";
/**
* DisableKeyBinding 禁用快捷键
*/
export function DisableKeyBinding(id: string): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(1594003006, id) as any;
export function DisableKeyBinding(action: models$0.KeyBindingAction): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(1594003006, action) as any;
return $resultPromise;
}
/**
* EnableKeyBinding 启用快捷键
*/
export function EnableKeyBinding(id: string): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(1462644129, id) as any;
export function EnableKeyBinding(action: models$0.KeyBindingAction): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(1462644129, action) as any;
return $resultPromise;
}
@@ -66,18 +66,6 @@ export function GetKeyBindingByAction(action: models$0.KeyBindingAction): Promis
return $typingPromise;
}
/**
* GetKeyBindingByID 根据ID获取快捷键
*/
export function GetKeyBindingByID(id: string): Promise<models$0.KeyBinding | null> & { cancel(): void } {
let $resultPromise = $Call.ByID(1578192526, id) as any;
let $typingPromise = $resultPromise.then(($result: any) => {
return $$createType2($result);
}) as any;
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
return $typingPromise;
}
/**
* GetKeyBindingCategories 获取所有快捷键分类
*/
@@ -157,16 +145,16 @@ export function ResetAllKeyBindings(): Promise<void> & { cancel(): void } {
/**
* ResetKeyBinding 重置快捷键到默认值
*/
export function ResetKeyBinding(id: string): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(3466323405, id) as any;
export function ResetKeyBinding(action: models$0.KeyBindingAction): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(3466323405, action) as any;
return $resultPromise;
}
/**
* UpdateKeyBinding 更新快捷键
*/
export function UpdateKeyBinding(id: string, newKey: string): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(1469368983, id, newKey) as any;
export function UpdateKeyBinding(action: models$0.KeyBindingAction, newKey: string): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(1469368983, action, newKey) as any;
return $resultPromise;
}

View File

@@ -4,7 +4,6 @@ import "time"
// KeyBinding 单个快捷键绑定
type KeyBinding struct {
ID string `json:"id"` // 快捷键唯一标识
Action KeyBindingAction `json:"action"` // 快捷键动作
Category KeyBindingCategory `json:"category"` // 快捷键分类
Scope KeyBindingScope `json:"scope"` // 快捷键作用域
@@ -116,7 +115,6 @@ func NewDefaultKeyBindings() []KeyBinding {
return []KeyBinding{
// 搜索相关快捷键
{
ID: "search.show",
Action: ActionShowSearch,
Category: CategorySearch,
Scope: ScopeGlobal,
@@ -125,7 +123,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "search.hide",
Action: ActionHideSearch,
Category: CategorySearch,
Scope: ScopeSearch,
@@ -134,7 +131,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "search.findNext",
Action: ActionFindNext,
Category: CategorySearch,
Scope: ScopeSearch,
@@ -143,7 +139,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "search.findPrevious",
Action: ActionFindPrevious,
Category: CategorySearch,
Scope: ScopeSearch,
@@ -152,7 +147,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "search.showReplace",
Action: ActionShowReplace,
Category: CategorySearch,
Scope: ScopeSearch,
@@ -161,7 +155,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "search.replaceAll",
Action: ActionReplaceAll,
Category: CategorySearch,
Scope: ScopeSearch,
@@ -170,7 +163,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "search.toggleCase",
Action: ActionToggleCase,
Category: CategorySearch,
Scope: ScopeSearch,
@@ -179,7 +171,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "search.toggleWholeWord",
Action: ActionToggleWholeWord,
Category: CategorySearch,
Scope: ScopeSearch,
@@ -188,7 +179,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "search.toggleRegex",
Action: ActionToggleRegex,
Category: CategorySearch,
Scope: ScopeSearch,
@@ -199,7 +189,6 @@ func NewDefaultKeyBindings() []KeyBinding {
// 编辑相关快捷键
{
ID: "edit.selectAll",
Action: ActionSelectAll,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -208,7 +197,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "edit.copy",
Action: ActionCopy,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -217,7 +205,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "edit.cut",
Action: ActionCut,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -226,7 +213,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "edit.paste",
Action: ActionPaste,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -235,7 +221,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "edit.undo",
Action: ActionUndo,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -244,7 +229,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "edit.redo",
Action: ActionRedo,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -253,7 +237,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "edit.duplicateLine",
Action: ActionDuplicateLine,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -262,7 +245,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "edit.deleteLine",
Action: ActionDeleteLine,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -271,7 +253,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "edit.moveLineUp",
Action: ActionMoveLineUp,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -280,7 +261,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "edit.moveLineDown",
Action: ActionMoveLineDown,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -289,7 +269,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "edit.toggleComment",
Action: ActionToggleComment,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -298,7 +277,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "edit.indent",
Action: ActionIndent,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -307,7 +285,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "edit.outdent",
Action: ActionOutdent,
Category: CategoryEdit,
Scope: ScopeEditor,
@@ -318,7 +295,6 @@ func NewDefaultKeyBindings() []KeyBinding {
// 代码块相关快捷键
{
ID: "codeblock.new",
Action: ActionNewCodeBlock,
Category: CategoryCodeBlock,
Scope: ScopeEditor,
@@ -327,7 +303,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "codeblock.delete",
Action: ActionDeleteCodeBlock,
Category: CategoryCodeBlock,
Scope: ScopeEditor,
@@ -336,7 +311,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "codeblock.select",
Action: ActionSelectCodeBlock,
Category: CategoryCodeBlock,
Scope: ScopeEditor,
@@ -345,7 +319,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "codeblock.format",
Action: ActionFormatCode,
Category: CategoryCodeBlock,
Scope: ScopeEditor,
@@ -354,7 +327,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "codeblock.changeLanguage",
Action: ActionChangeLanguage,
Category: CategoryCodeBlock,
Scope: ScopeEditor,
@@ -365,7 +337,6 @@ func NewDefaultKeyBindings() []KeyBinding {
// 导航相关快捷键
{
ID: "navigation.goToLine",
Action: ActionGoToLine,
Category: CategoryNavigation,
Scope: ScopeEditor,
@@ -374,7 +345,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "navigation.foldAll",
Action: ActionFoldAll,
Category: CategoryNavigation,
Scope: ScopeEditor,
@@ -383,7 +353,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "navigation.unfoldAll",
Action: ActionUnfoldAll,
Category: CategoryNavigation,
Scope: ScopeEditor,
@@ -392,7 +361,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "navigation.toggleFold",
Action: ActionToggleFold,
Category: CategoryNavigation,
Scope: ScopeEditor,
@@ -403,7 +371,6 @@ func NewDefaultKeyBindings() []KeyBinding {
// 视图相关快捷键
{
ID: "view.zoomIn",
Action: ActionZoomIn,
Category: CategoryView,
Scope: ScopeGlobal,
@@ -412,7 +379,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "view.zoomOut",
Action: ActionZoomOut,
Category: CategoryView,
Scope: ScopeGlobal,
@@ -421,7 +387,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "view.resetZoom",
Action: ActionResetZoom,
Category: CategoryView,
Scope: ScopeGlobal,
@@ -430,7 +395,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "view.toggleMinimap",
Action: ActionToggleMinimap,
Category: CategoryView,
Scope: ScopeGlobal,
@@ -439,7 +403,6 @@ func NewDefaultKeyBindings() []KeyBinding {
IsDefault: true,
},
{
ID: "view.toggleLineNumbers",
Action: ActionToggleLineNumbers,
Category: CategoryView,
Scope: ScopeGlobal,
@@ -450,7 +413,6 @@ func NewDefaultKeyBindings() []KeyBinding {
// 文件相关快捷键
{
ID: "file.save",
Action: ActionSave,
Category: CategoryFile,
Scope: ScopeGlobal,

View File

@@ -26,14 +26,14 @@ type KeyBindingService struct {
// KeyBindingError 快捷键错误
type KeyBindingError struct {
Operation string // 操作名称
KeyID string // 快捷键ID
Action string // 快捷键Action
Err error // 原始错误
}
// Error 实现error接口
func (e *KeyBindingError) Error() string {
if e.KeyID != "" {
return fmt.Sprintf("keybinding error during %s for key %s: %v", e.Operation, e.KeyID, e.Err)
if e.Action != "" {
return fmt.Sprintf("keybinding error during %s for action %s: %v", e.Operation, e.Action, e.Err)
}
return fmt.Sprintf("keybinding error during %s: %v", e.Operation, e.Err)
}
@@ -245,29 +245,6 @@ func (kbs *KeyBindingService) GetKeyBindingsByScope(scope models.KeyBindingScope
return result, nil
}
// GetKeyBindingByID 根据ID获取快捷键
func (kbs *KeyBindingService) GetKeyBindingByID(id string) (*models.KeyBinding, error) {
kbs.mu.RLock()
defer kbs.mu.RUnlock()
allKeyBindings, err := kbs.GetAllKeyBindings()
if err != nil {
return nil, err
}
for _, kb := range allKeyBindings {
if kb.ID == id {
return &kb, nil
}
}
return nil, &KeyBindingError{
Operation: "get_keybinding_by_id",
KeyID: id,
Err: errors.New("keybinding not found"),
}
}
// GetKeyBindingByAction 根据动作获取快捷键
func (kbs *KeyBindingService) GetKeyBindingByAction(action models.KeyBindingAction) (*models.KeyBinding, error) {
kbs.mu.RLock()
@@ -291,7 +268,7 @@ func (kbs *KeyBindingService) GetKeyBindingByAction(action models.KeyBindingActi
}
// UpdateKeyBinding 更新快捷键
func (kbs *KeyBindingService) UpdateKeyBinding(id string, newKey string) error {
func (kbs *KeyBindingService) UpdateKeyBinding(action models.KeyBindingAction, newKey string) error {
kbs.mu.Lock()
defer kbs.mu.Unlock()
@@ -299,16 +276,16 @@ func (kbs *KeyBindingService) UpdateKeyBinding(id string, newKey string) error {
if err := kbs.validateKeyFormat(newKey); err != nil {
return &KeyBindingError{
Operation: "update_keybinding",
KeyID: id,
Action: string(action),
Err: fmt.Errorf("invalid key format: %v", err),
}
}
// 检查快捷键冲突
if err := kbs.checkKeyConflict(id, newKey); err != nil {
if err := kbs.checkKeyConflict(action, newKey); err != nil {
return &KeyBindingError{
Operation: "update_keybinding",
KeyID: id,
Action: string(action),
Err: fmt.Errorf("key conflict: %v", err),
}
}
@@ -316,13 +293,13 @@ func (kbs *KeyBindingService) UpdateKeyBinding(id string, newKey string) error {
// 获取当前配置
config, err := kbs.GetKeyBindingConfig()
if err != nil {
return &KeyBindingError{Operation: "update_keybinding", KeyID: id, Err: err}
return &KeyBindingError{Operation: "update_keybinding", Action: string(action), Err: err}
}
// 查找并更新快捷键
found := false
for i, kb := range config.KeyBindings {
if kb.ID == id {
if kb.Action == action {
config.KeyBindings[i].Key = newKey
config.KeyBindings[i].IsDefault = false // 标记为非默认
found = true
@@ -333,7 +310,7 @@ func (kbs *KeyBindingService) UpdateKeyBinding(id string, newKey string) error {
if !found {
return &KeyBindingError{
Operation: "update_keybinding",
KeyID: id,
Action: string(action),
Err: errors.New("keybinding not found"),
}
}
@@ -343,38 +320,38 @@ func (kbs *KeyBindingService) UpdateKeyBinding(id string, newKey string) error {
// 保存配置
if err := kbs.saveConfig(config); err != nil {
return &KeyBindingError{Operation: "update_keybinding", KeyID: id, Err: err}
return &KeyBindingError{Operation: "update_keybinding", Action: string(action), Err: err}
}
kbs.logger.Info("KeyBinding: Updated keybinding", "id", id, "newKey", newKey)
kbs.logger.Info("KeyBinding: Updated keybinding", "action", action, "newKey", newKey)
return nil
}
// EnableKeyBinding 启用快捷键
func (kbs *KeyBindingService) EnableKeyBinding(id string) error {
return kbs.setKeyBindingEnabled(id, true)
func (kbs *KeyBindingService) EnableKeyBinding(action models.KeyBindingAction) error {
return kbs.setKeyBindingEnabled(action, true)
}
// DisableKeyBinding 禁用快捷键
func (kbs *KeyBindingService) DisableKeyBinding(id string) error {
return kbs.setKeyBindingEnabled(id, false)
func (kbs *KeyBindingService) DisableKeyBinding(action models.KeyBindingAction) error {
return kbs.setKeyBindingEnabled(action, false)
}
// setKeyBindingEnabled 设置快捷键启用状态
func (kbs *KeyBindingService) setKeyBindingEnabled(id string, enabled bool) error {
func (kbs *KeyBindingService) setKeyBindingEnabled(action models.KeyBindingAction, enabled bool) error {
kbs.mu.Lock()
defer kbs.mu.Unlock()
// 获取当前配置
config, err := kbs.GetKeyBindingConfig()
if err != nil {
return &KeyBindingError{Operation: "set_keybinding_enabled", KeyID: id, Err: err}
return &KeyBindingError{Operation: "set_keybinding_enabled", Action: string(action), Err: err}
}
// 查找并更新快捷键
found := false
for i, kb := range config.KeyBindings {
if kb.ID == id {
if kb.Action == action {
config.KeyBindings[i].Enabled = enabled
found = true
break
@@ -384,7 +361,7 @@ func (kbs *KeyBindingService) setKeyBindingEnabled(id string, enabled bool) erro
if !found {
return &KeyBindingError{
Operation: "set_keybinding_enabled",
KeyID: id,
Action: string(action),
Err: errors.New("keybinding not found"),
}
}
@@ -394,19 +371,19 @@ func (kbs *KeyBindingService) setKeyBindingEnabled(id string, enabled bool) erro
// 保存配置
if err := kbs.saveConfig(config); err != nil {
return &KeyBindingError{Operation: "set_keybinding_enabled", KeyID: id, Err: err}
return &KeyBindingError{Operation: "set_keybinding_enabled", Action: string(action), Err: err}
}
action := "enabled"
status := "enabled"
if !enabled {
action = "disabled"
status = "disabled"
}
kbs.logger.Info("KeyBinding: "+action+" keybinding", "id", id)
kbs.logger.Info("KeyBinding: "+status+" keybinding", "action", action)
return nil
}
// ResetKeyBinding 重置快捷键到默认值
func (kbs *KeyBindingService) ResetKeyBinding(id string) error {
func (kbs *KeyBindingService) ResetKeyBinding(action models.KeyBindingAction) error {
kbs.mu.Lock()
defer kbs.mu.Unlock()
@@ -414,7 +391,7 @@ func (kbs *KeyBindingService) ResetKeyBinding(id string) error {
defaultKeyBindings := models.NewDefaultKeyBindings()
var defaultKeyBinding *models.KeyBinding
for _, kb := range defaultKeyBindings {
if kb.ID == id {
if kb.Action == action {
defaultKeyBinding = &kb
break
}
@@ -423,7 +400,7 @@ func (kbs *KeyBindingService) ResetKeyBinding(id string) error {
if defaultKeyBinding == nil {
return &KeyBindingError{
Operation: "reset_keybinding",
KeyID: id,
Action: string(action),
Err: errors.New("default keybinding not found"),
}
}
@@ -431,13 +408,13 @@ func (kbs *KeyBindingService) ResetKeyBinding(id string) error {
// 获取当前配置
config, err := kbs.GetKeyBindingConfig()
if err != nil {
return &KeyBindingError{Operation: "reset_keybinding", KeyID: id, Err: err}
return &KeyBindingError{Operation: "reset_keybinding", Action: string(action), Err: err}
}
// 查找并重置快捷键
found := false
for i, kb := range config.KeyBindings {
if kb.ID == id {
if kb.Action == action {
config.KeyBindings[i].Key = defaultKeyBinding.Key
config.KeyBindings[i].Enabled = defaultKeyBinding.Enabled
config.KeyBindings[i].IsDefault = true
@@ -449,7 +426,7 @@ func (kbs *KeyBindingService) ResetKeyBinding(id string) error {
if !found {
return &KeyBindingError{
Operation: "reset_keybinding",
KeyID: id,
Action: string(action),
Err: errors.New("keybinding not found"),
}
}
@@ -459,10 +436,10 @@ func (kbs *KeyBindingService) ResetKeyBinding(id string) error {
// 保存配置
if err := kbs.saveConfig(config); err != nil {
return &KeyBindingError{Operation: "reset_keybinding", KeyID: id, Err: err}
return &KeyBindingError{Operation: "reset_keybinding", Action: string(action), Err: err}
}
kbs.logger.Info("KeyBinding: Reset keybinding to default", "id", id, "key", defaultKeyBinding.Key)
kbs.logger.Info("KeyBinding: Reset keybinding to default", "action", action, "key", defaultKeyBinding.Key)
return nil
}
@@ -538,15 +515,15 @@ func (kbs *KeyBindingService) validateKeyFormat(key string) error {
}
// checkKeyConflict 检查快捷键冲突
func (kbs *KeyBindingService) checkKeyConflict(excludeID, key string) error {
func (kbs *KeyBindingService) checkKeyConflict(excludeAction models.KeyBindingAction, key string) error {
allKeyBindings, err := kbs.GetAllKeyBindings()
if err != nil {
return err
}
for _, kb := range allKeyBindings {
if kb.ID != excludeID && kb.Key == key && kb.Enabled {
return fmt.Errorf("key %s is already used by %s", key, kb.ID)
if kb.Action != excludeAction && kb.Key == key && kb.Enabled {
return fmt.Errorf("key %s is already used by %s", key, kb.Action)
}
}
@@ -593,23 +570,23 @@ func (kbs *KeyBindingService) ImportKeyBindings(keyBindings []models.KeyBinding)
if err := kbs.validateKeyFormat(kb.Key); err != nil {
return &KeyBindingError{
Operation: "import_keybindings",
KeyID: kb.ID,
Err: fmt.Errorf("invalid key format for %s: %v", kb.ID, err),
Action: string(kb.Action),
Err: fmt.Errorf("invalid key format for %s: %v", kb.Action, err),
}
}
}
// 检查重复的快捷键
keyMap := make(map[string]string)
keyMap := make(map[string]models.KeyBindingAction)
for _, kb := range keyBindings {
if kb.Enabled {
if existingID, exists := keyMap[kb.Key]; exists {
if existingAction, exists := keyMap[kb.Key]; exists {
return &KeyBindingError{
Operation: "import_keybindings",
Err: fmt.Errorf("duplicate key %s found in %s and %s", kb.Key, existingID, kb.ID),
Err: fmt.Errorf("duplicate key %s found in %s and %s", kb.Key, existingAction, kb.Action),
}
}
keyMap[kb.Key] = kb.ID
keyMap[kb.Key] = kb.Action
}
}