Skip to content

Commit 1f5a3f3

Browse files
committed
Fix undo/redo
1 parent c24762c commit 1f5a3f3

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;
@@ -89,6 +95,20 @@ export class VimEditorManager {
8995
return view.hasFocus;
9096
};
9197
}
98+
99+
// Override vim-mode undo/redo to make it work with JupyterLab RTC-aware
100+
// history; it needs to happen on every chang of the editor.
101+
Vim.defineAction('undo', (cm: CodeMirror, options: IUndoOptions) => {
102+
for (let i = 0; i < options.repeat; i++) {
103+
editor!.undo();
104+
}
105+
});
106+
Vim.defineAction('redo', (cm: CodeMirror, options: IUndoOptions) => {
107+
for (let i = 0; i < options.repeat; i++) {
108+
editor!.redo();
109+
}
110+
});
111+
92112
const lcm = getCM(view);
93113

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

0 commit comments

Comments
 (0)