Skip to content

Commit

Permalink
Fix undo/redo
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Jul 31, 2023
1 parent c24762c commit 1f5a3f3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/codemirrorCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export namespace VimCellManager {
}
}

interface IUndoOptions {
repeat: number;
repeatIsExplicit: boolean;
registerName: unknown;
}

export class VimEditorManager {
constructor({ enabled, userKeybindings }: VimEditorManager.IOptions) {
this.enabled = enabled;
Expand Down Expand Up @@ -89,6 +95,20 @@ export class VimEditorManager {
return view.hasFocus;
};
}

// Override vim-mode undo/redo to make it work with JupyterLab RTC-aware
// history; it needs to happen on every chang of the editor.
Vim.defineAction('undo', (cm: CodeMirror, options: IUndoOptions) => {
for (let i = 0; i < options.repeat; i++) {
editor!.undo();
}
});
Vim.defineAction('redo', (cm: CodeMirror, options: IUndoOptions) => {
for (let i = 0; i < options.repeat; i++) {
editor!.redo();
}
});

const lcm = getCM(view);

// Clear existing user keybindings, then re-register in case they changed in the user settings
Expand Down

0 comments on commit 1f5a3f3

Please sign in to comment.