Skip to content

Commit

Permalink
Fix onInterrupt impl (#1744)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitphx committed Nov 6, 2023
1 parent 1b9d11e commit dce0580
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
16 changes: 10 additions & 6 deletions src/commands/registry.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { EmacsCommand } from ".";
import { EmacsCommand, ITextEditorInterruptionHandler, isTextEditorInterruptionHandler } from ".";

export class EmacsCommandRegistry {
private commands: Map<string, EmacsCommand>;
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<string, EmacsCommand>) => void,
thisArg?: unknown,
): void {
this.commands.forEach(callbackfn, thisArg);
public onInterrupt(): void {
for (const handler of this.interruptionHandlers) {
handler.onDidInterruptTextEditor();
}
}
}
8 changes: 1 addition & 7 deletions src/emulator.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit dce0580

Please sign in to comment.