From 103e20046db39ad0281245b0b63e0f96d39f2229 Mon Sep 17 00:00:00 2001 From: Argus Agent Date: Tue, 17 Mar 2026 18:31:26 -0400 Subject: [PATCH] fix: handle ctrl-c copy in vim binding mode (fixes #773) In Vim keymap mode, Ctrl-C is intercepted by CodeMirror's Vim addon and acts as escape, preventing users from copying selected text with Ctrl-C. This adds a Ctrl-C extraKey handler that, when in vim keymap mode and text is selected, writes the selection to the clipboard via navigator.clipboard (with execCommand fallback) instead of triggering escape. When nothing is selected, Ctrl-C falls through to the default Vim handler (escape) as expected. --- src/cloud/components/Editor/index.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/cloud/components/Editor/index.tsx b/src/cloud/components/Editor/index.tsx index 639530cb0..a3ce7b2e8 100644 --- a/src/cloud/components/Editor/index.tsx +++ b/src/cloud/components/Editor/index.tsx @@ -269,6 +269,18 @@ const Editor = ({ Enter: 'newlineAndIndentContinueMarkdownList', Tab: 'indentMore', 'Ctrl-Space': 'autocomplete', + 'Ctrl-C': (cm: CodeMirror.Editor) => { + // In Vim mode, Ctrl-C normally triggers escape. When text is + // selected, intercept and copy to clipboard instead so users + // can copy text without leaving visual/insert mode unexpectedly. + if (keyMap === 'vim' && cm.somethingSelected()) { + navigator.clipboard + .writeText(cm.getSelection()) + .catch(() => document.execCommand('copy')) + return + } + return CodeMirror.Pass + }, }, scrollPastEnd: true, // fixes IME being on top of current line, Codemirror issue: https://github.com/codemirror/CodeMirror/issues/3137