Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undo #92

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -90,6 +96,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 change 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