From dce0580aea2ce21b1c3bfe640c7a8446ae32a28f Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Mon, 6 Nov 2023 12:46:15 +0900 Subject: [PATCH] Fix onInterrupt impl (#1744) --- src/commands/registry.ts | 16 ++++++++++------ src/emulator.ts | 8 +------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/commands/registry.ts b/src/commands/registry.ts index 904e427a59..560d43e6f9 100644 --- a/src/commands/registry.ts +++ b/src/commands/registry.ts @@ -1,24 +1,28 @@ -import { EmacsCommand } from "."; +import { EmacsCommand, ITextEditorInterruptionHandler, isTextEditorInterruptionHandler } from "."; export class EmacsCommandRegistry { private commands: Map; + private interruptionHandlers: ITextEditorInterruptionHandler[]; constructor() { this.commands = new Map(); + this.interruptionHandlers = []; } public register(command: EmacsCommand): void { this.commands.set(command.id, command); + if (isTextEditorInterruptionHandler(command)) { + this.interruptionHandlers.push(command); + } } public get(commandName: string): EmacsCommand | undefined { return this.commands.get(commandName); } - public forEach( - callbackfn: (value: EmacsCommand, key: string, map: Map) => void, - thisArg?: unknown, - ): void { - this.commands.forEach(callbackfn, thisArg); + public onInterrupt(): void { + for (const handler of this.interruptionHandlers) { + handler.onDidInterruptTextEditor(); + } } } diff --git a/src/emulator.ts b/src/emulator.ts index 9bc74714a0..17d8826f9d 100644 --- a/src/emulator.ts +++ b/src/emulator.ts @@ -1,6 +1,5 @@ import * as vscode from "vscode"; import { Selection, TextEditor } from "vscode"; -import { isTextEditorInterruptionHandler } from "./commands"; import { AddSelectionToNextFindMatch, AddSelectionToPreviousFindMatch } from "./commands/add-selection-to-find-match"; import * as CaseCommands from "./commands/case"; import { DeleteBlankLines } from "./commands/delete-blank-lines"; @@ -611,12 +610,7 @@ export class EmacsEmulator implements IEmacsController, vscode.Disposable { } private onDidInterruptTextEditor() { - this.commandRegistry.forEach((command) => { - if (isTextEditorInterruptionHandler(command)) { - // TODO: Cache the array of IEmacsCommandInterrupted instances - command.onDidInterruptTextEditor(); - } - }); + this.commandRegistry.onInterrupt(); } public saveRegister(arg: string): void {