Skip to content

Commit b0b8cd6

Browse files
committed
fix(tui): kill prompt text while the transcript is focused
1 parent 108b6f0 commit b0b8cd6

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎src/tui/prompt-kill-ring.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, test } from "bun:test";
22
import { defined } from "../../testkit/defined.js";
33
import { withTestRenderer } from "./harness";
4+
import { shellFocusTranscript } from "./shell/chrome";
45
import { createAppShell } from "./shell/index";
56
import {
67
beginYank,
@@ -322,4 +323,21 @@ describe("prompt kill ring chords", () => {
322323
expect(shell.prompt.value).toBe("ab你cd");
323324
});
324325
});
326+
327+
test("ctrl+k still kills prompt text while the transcript is focused", async () => {
328+
await withTestRenderer(async (h) => {
329+
const shell = createAppShell(h.renderer, {
330+
terminal: { columns: 80, rows: 24 },
331+
run: "idle",
332+
});
333+
shell.prompt.value = "hello";
334+
shell.prompt.cursorOffset = 0;
335+
shellFocusTranscript(shell);
336+
expect(shell.prompt.focused).toBe(false);
337+
h.pressKey("k", { ctrl: true });
338+
expect(shell.prompt.value).toBe("");
339+
h.pressKey("y", { ctrl: true });
340+
expect(shell.prompt.value).toBe("hello");
341+
});
342+
});
325343
});

‎src/tui/shell/keys.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,33 @@ export function createShellKeyHandlers(
558558
shell.promptKillRing = breakKillSequence(shell.promptKillRing);
559559
}
560560

561+
// Textarea defaults only run while the prompt is focused. After Tab the
562+
// transcript holds focus, so call the same delete methods the default
563+
// bindings use. capturePromptKills records the diff. Do not keymap-bind
564+
// these: that would steal them from the focused textarea.
565+
if (!shell.prompt.focused) {
566+
if (key.ctrl && !key.meta && !key.option && keyName === "k") {
567+
key.preventDefault();
568+
shell.prompt.deleteToLineEnd();
569+
return;
570+
}
571+
if (key.ctrl && !key.meta && !key.option && keyName === "u") {
572+
key.preventDefault();
573+
shell.prompt.deleteToLineStart();
574+
return;
575+
}
576+
if (key.ctrl && !key.meta && !key.option && keyName === "w") {
577+
key.preventDefault();
578+
shell.prompt.deleteWordBackward();
579+
return;
580+
}
581+
if ((key.meta || key.option) && !key.ctrl && keyName === "d") {
582+
key.preventDefault();
583+
shell.prompt.deleteWordForward();
584+
return;
585+
}
586+
}
587+
561588
if (key.ctrl && !key.meta && !key.option && keyName === "y") {
562589
key.preventDefault();
563590
const yank = beginYank(shell.promptKillRing, shell.prompt.cursorOffset);

0 commit comments

Comments
 (0)