Kaynağa Gözat

feat(shortcuts): add handler removal functionality

liuyangxing 1 ay önce
ebeveyn
işleme
763efff1ac

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

@@ -31,7 +31,7 @@ export class ShortcutsRegistry {
 
 
   @inject(CommandRegistry) protected commandRegistry: CommandRegistry;
   @inject(CommandRegistry) protected commandRegistry: CommandRegistry;
 
 
-  readonly shortcutsHandlers: ShortcutsHandler[] = [];
+  shortcutsHandlers: ShortcutsHandler[] = [];
 
 
   addHandlers(...handlers: ShortcutsHandler[]): void {
   addHandlers(...handlers: ShortcutsHandler[]): void {
     // 注册 command
     // 注册 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 {
   has(commandId: string): boolean {
     return this.shortcutsHandlers.some((handler) => handler.commandId === commandId);
     return this.shortcutsHandlers.some((handler) => handler.commandId === commandId);
   }
   }