From 916c84e9c1cb2e4d48bd50abae80954b20687efc Mon Sep 17 00:00:00 2001 From: Ohad Lutzky Date: Mon, 11 Nov 2024 12:57:19 +0000 Subject: [PATCH] Fix Enter for vim mode (#1146) This is a workaround for https://github.com/replit/codemirror-vim/issues/182 Fixes https://github.com/silverbulletmd/silverbullet/pull/1145 (harder) --- web/editor_state.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/web/editor_state.ts b/web/editor_state.ts index 5541c03e..87eef9a4 100644 --- a/web/editor_state.ts +++ b/web/editor_state.ts @@ -2,6 +2,7 @@ import customMarkdownStyle from "./style.ts"; import { history, indentWithTab, + insertNewlineAndIndent, isolateHistory, standardKeymap, } from "@codemirror/commands"; @@ -367,7 +368,18 @@ export function createKeyBindings(client: Client): Extension { ...createCommandKeyBindings(client), ...createSmartQuoteKeyBindings(client), ...closeBracketsKeymap, - ...client.ui.viewState.uiOptions.vimMode ? [] : standardKeymap, + ...client.ui.viewState.uiOptions.vimMode + ? [ + // Workaround for https://github.com/replit/codemirror-vim/issues/182; + // without this, Enter does nothing for ordinary paragraphs in insert + // mode. + { + key: "Enter", + run: insertNewlineAndIndent, + shift: insertNewlineAndIndent, + }, + ] + : standardKeymap, ...completionKeymap, indentWithTab, ]);