Skip to content

Commit 718d294

Browse files
krassowskiianhi
andauthored
Fix undo (#92)
* Fix undo/redo * Fix a typo in a comment Co-authored-by: Ian Hunt-Isaak <[email protected]> --------- Co-authored-by: Ian Hunt-Isaak <[email protected]>
1 parent de8afca commit 718d294

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/codemirrorCommands.ts

+20
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export namespace VimCellManager {
3737
}
3838
}
3939

40+
interface IUndoOptions {
41+
repeat: number;
42+
repeatIsExplicit: boolean;
43+
registerName: unknown;
44+
}
45+
4046
export class VimEditorManager {
4147
constructor({ enabled, userKeybindings }: VimEditorManager.IOptions) {
4248
this.enabled = enabled;
@@ -90,6 +96,20 @@ export class VimEditorManager {
9096
return view.hasFocus;
9197
};
9298
}
99+
100+
// Override vim-mode undo/redo to make it work with JupyterLab RTC-aware
101+
// history; it needs to happen on every change of the editor.
102+
Vim.defineAction('undo', (cm: CodeMirror, options: IUndoOptions) => {
103+
for (let i = 0; i < options.repeat; i++) {
104+
editor!.undo();
105+
}
106+
});
107+
Vim.defineAction('redo', (cm: CodeMirror, options: IUndoOptions) => {
108+
for (let i = 0; i < options.repeat; i++) {
109+
editor!.redo();
110+
}
111+
});
112+
93113
const lcm = getCM(view);
94114

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

0 commit comments

Comments
 (0)