Просмотр исходного кода

feat(shortcuts): add handler removal functionality

liuyangxing 1 месяц назад
Родитель
Сommit
763efff1ac
1 измененных файлов с 7 добавлено и 1 удалено
  1. 7 1
      packages/plugins/shortcuts-plugin/src/shortcuts-contribution.ts

+ 7 - 1
packages/plugins/shortcuts-plugin/src/shortcuts-contribution.ts

@@ -31,7 +31,7 @@ export class ShortcutsRegistry {
 
   @inject(CommandRegistry) protected commandRegistry: CommandRegistry;
 
-  readonly shortcutsHandlers: ShortcutsHandler[] = [];
+  shortcutsHandlers: ShortcutsHandler[] = [];
 
   addHandlers(...handlers: ShortcutsHandler[]): void {
     // 注册 command
@@ -60,6 +60,12 @@ export class ShortcutsRegistry {
     });
   }
 
+  removeHandler(commandId: string): void {
+    this.shortcutsHandlers = this.shortcutsHandlers.filter(
+      (handler) => handler.commandId !== commandId
+    );
+  }
+
   has(commandId: string): boolean {
     return this.shortcutsHandlers.some((handler) => handler.commandId === commandId);
   }