From 7d3ff27c64c87e442dc4aae0a0a4947e03c40407 Mon Sep 17 00:00:00 2001 From: can1357 Date: Sun, 22 Mar 2026 21:12:55 +0100 Subject: [PATCH] fix(editor): corrected editor consuming rebound copy keys preventing custom bindings - Fixed editor consuming user-rebound copy keys, preventing custom keybindings from working. - Changed copy key detection from generic `tui.input.copy` binding to explicit `ctrl+c` check to avoid swallowing user-rebound keys. - Added test case verifying editor does not consume keys rebound to copy action. --- packages/tui/CHANGELOG.md | 5 +++++ packages/tui/src/components/editor.ts | 6 ++++-- packages/tui/test/editor.test.ts | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/tui/CHANGELOG.md b/packages/tui/CHANGELOG.md index d13917853..2f717af51 100644 --- a/packages/tui/CHANGELOG.md +++ b/packages/tui/CHANGELOG.md @@ -1,10 +1,15 @@ # Changelog ## [Unreleased] + ### Added - Added `renderInlineMarkdown()` function to render inline markdown (bold, italic, code, links, strikethrough) to styled strings +### Fixed + +- Fixed editor consuming user-rebound copy keys, preventing custom keybindings from working in the editor + ## [13.14.1] - 2026-03-21 ### Added diff --git a/packages/tui/src/components/editor.ts b/packages/tui/src/components/editor.ts index 3095d6f3a..93d4c32d9 100644 --- a/packages/tui/src/components/editor.ts +++ b/packages/tui/src/components/editor.ts @@ -732,8 +732,10 @@ export class Editor implements Component, Focusable { // Handle special key combinations first - // Ctrl+C - Exit (let parent handle this) - if (kb.matches(data, "tui.input.copy")) { + // Ctrl+C is reserved by parent components for app-level handling. + // Do not consume arbitrary user-bound "copy" keys here, since the editor + // has no copy implementation and would make those keys disappear. + if (matchesKey(data, "ctrl+c")) { return; } diff --git a/packages/tui/test/editor.test.ts b/packages/tui/test/editor.test.ts index 36f6faab2..dfa9534bc 100644 --- a/packages/tui/test/editor.test.ts +++ b/packages/tui/test/editor.test.ts @@ -1356,6 +1356,23 @@ describe("Editor component", () => { expect(editor.getCursor()).toEqual({ line: 0, col: 0 }); }); + it("does not swallow keys rebound to copy", () => { + setKeybindings( + new KeybindingsManager(TUI_KEYBINDINGS, { + "tui.input.copy": "left", + }), + ); + + const editor = new Editor(defaultEditorTheme); + editor.setText("ab"); + + editor.handleInput("\x1b[D"); // Left arrow + editor.handleInput("X"); + + expect(editor.getText()).toBe("aXb"); + expect(editor.getCursor()).toEqual({ line: 0, col: 2 }); + }); + it("undoes the last paste when a transient #undo trigger is executed", () => { const editor = new Editor(defaultEditorTheme);