Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: vim blockwise mode (#3371)

Myles Scolnick05d34b03bbeb
diff --git a/frontend/src/core/codemirror/keymaps/keymaps.ts b/frontend/src/core/codemirror/keymaps/keymaps.ts
index 194dd93573..b1d1ed104b 100644
--- a/frontend/src/core/codemirror/keymaps/keymaps.ts
+++ b/frontend/src/core/codemirror/keymaps/keymaps.ts
@@ -61,8 +61,17 @@ export function keymapBundle(
}
const defaultVimKeymap = once(() => {
- // Remove Enter (<CR>) from the keymap
- return defaultKeymap.filter((k) => k.key !== "Enter");
+ const toRemove = new Set(["Enter", "Ctrl-v", "ArrowLeft", "ArrowRight"]);
+ // Remove conflicting keys from the keymap
+ // Enter (<CR>) adds a new line
+ // - it should just go to the next line
+ // Ctrl-v goes to the bottom of the cell
+ // - should enter blockwise visual mode
+ // ArrowLeft/ArrowRight exit blockwise visual mode
+ // - should keep blockwise, but continue with cursor movement
+ return defaultKeymap.filter(
+ (k) => !toRemove.has(k.key || k.mac || k.linux || k.win || ""),
+ );
});
/**
diff --git a/frontend/src/core/codemirror/keymaps/vim.ts b/frontend/src/core/codemirror/keymaps/vim.ts
index 43ad3293b6..2082466fc8 100644
--- a/frontend/src/core/codemirror/keymaps/vim.ts
+++ b/frontend/src/core/codemirror/keymaps/vim.ts
@@ -87,14 +87,13 @@ class CodeMirrorVimSync {
// Create an event listener for Vim mode changes
// When it changes, we broadcast it to all other CodeMirror instances
- cm.on("vim-mode-change", (e: { mode: string }) => {
+ cm.on("vim-mode-change", (e: { mode: string; subMode?: string }) => {
if (this.isBroadcasting) {
return;
}
invariant("mode" in e, 'Expected event to have a "mode" property');
- const mode = e.mode;
this.isBroadcasting = true;
- this.broadcastModeChange(instance, mode);
+ this.broadcastModeChange(instance, e.mode, e.subMode);
this.isBroadcasting = false;
});
}
@@ -103,7 +102,11 @@ class CodeMirrorVimSync {
this.instances.delete(instance);
}
- broadcastModeChange(originInstance: EditorView, mode: string) {
+ broadcastModeChange(
+ originInstance: EditorView,
+ mode: string,
+ subMode?: string,
+ ) {
invariant(
"exitInsertMode" in Vim,
"Vim does not have an exitInsertMode method",