Skip to content

Commit

Permalink
Rename IEmacsCommandInterrupted to TextEditorInterruptionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
whitphx committed Nov 5, 2023
1 parent 57f715e commit cde5a83
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export abstract class EmacsCommand {
public onDidInterruptTextEditor?(): void;
}

export interface IEmacsCommandInterrupted {
export interface TextEditorInterruptionHandler {
onDidInterruptTextEditor(): void;
}

// This type guard trick is from https://stackoverflow.com/a/64163454/13103190
export function instanceOfIEmacsCommandInterrupted<T extends { onDidInterruptTextEditor?: unknown }>(
export function isTextEditorInterruptionHandler<T extends { onDidInterruptTextEditor?: unknown }>(
obj: T,
): obj is T & IEmacsCommandInterrupted {
): obj is T & TextEditorInterruptionHandler {
return typeof obj.onDidInterruptTextEditor === "function";
}
4 changes: 2 additions & 2 deletions src/commands/recenter.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as vscode from "vscode";
import { TextEditorRevealType } from "vscode";
import { EmacsCommand, IEmacsCommandInterrupted } from ".";
import { EmacsCommand, TextEditorInterruptionHandler } from ".";

enum RecenterPosition {
Middle,
Top,
Bottom,
}

export class RecenterTopBottom extends EmacsCommand implements IEmacsCommandInterrupted {
export class RecenterTopBottom extends EmacsCommand implements TextEditorInterruptionHandler {
public readonly id = "recenterTopBottom";

private recenterPosition: RecenterPosition = RecenterPosition.Middle;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/rectangle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import { EmacsCommand, IEmacsCommandInterrupted } from ".";
import { EmacsCommand, TextEditorInterruptionHandler } from ".";
import { IEmacsController } from "../emulator";
import { getNonEmptySelections, makeSelectionsEmpty } from "./helpers/selection";
import { convertSelectionToRectSelections } from "../rectangle";
Expand All @@ -15,7 +15,7 @@ import { Minibuffer } from "src/minibuffer";
* with `{ "when": "emacs-mcx.acceptingRectCommand" }` condition.
* Then, `kill-rectangle` can be executed through `C-x r k`.
*/
export class StartAcceptingRectCommand extends EmacsCommand implements IEmacsCommandInterrupted {
export class StartAcceptingRectCommand extends EmacsCommand implements TextEditorInterruptionHandler {
public readonly id = "startAcceptingRectCommand";

private acceptingRectCommand = false;
Expand Down
6 changes: 3 additions & 3 deletions src/commands/registers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as vscode from "vscode";
import { EmacsCommand, IEmacsCommandInterrupted } from ".";
import { EmacsCommand, TextEditorInterruptionHandler } from ".";

// Will bind this this to C-x r s
export class StartRegisterSaveCommand extends EmacsCommand implements IEmacsCommandInterrupted {
export class StartRegisterSaveCommand extends EmacsCommand implements TextEditorInterruptionHandler {
public readonly id = "StartRegisterSaveCommand";

private acceptingRegisterSaveCommand = false;
Expand Down Expand Up @@ -30,7 +30,7 @@ export class StartRegisterSaveCommand extends EmacsCommand implements IEmacsComm
}

// Will bind this this to C-x r i
export class StartRegisterInsertCommand extends EmacsCommand implements IEmacsCommandInterrupted {
export class StartRegisterInsertCommand extends EmacsCommand implements TextEditorInterruptionHandler {
public readonly id = "StartRegisterInsertCommand";

private acceptingRegisterInsertCommand = false;
Expand Down
4 changes: 2 additions & 2 deletions src/emulator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode";
import { Selection, TextEditor } from "vscode";
import { instanceOfIEmacsCommandInterrupted } from "./commands";
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 @@ -618,7 +618,7 @@ export class EmacsEmulator implements IEmacsController, vscode.Disposable {

private onDidInterruptTextEditor() {
this.commandRegistry.forEach((command) => {
if (instanceOfIEmacsCommandInterrupted(command)) {
if (isTextEditorInterruptionHandler(command)) {
// TODO: Cache the array of IEmacsCommandInterrupted instances
command.onDidInterruptTextEditor();
}
Expand Down

0 comments on commit cde5a83

Please sign in to comment.