Skip to content

Commit

Permalink
fix: vim blockwise mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick committed Jan 8, 2025
1 parent ac16ef3 commit 5c4ab1a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
13 changes: 11 additions & 2 deletions frontend/src/core/codemirror/keymaps/keymaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ""),
);
});

/**
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/core/codemirror/keymaps/vim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand All @@ -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",
Expand Down

0 comments on commit 5c4ab1a

Please sign in to comment.