File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { describe , expect , test } from "bun:test" ;
22import { defined } from "../../testkit/defined.js" ;
33import { withTestRenderer } from "./harness" ;
4+ import { shellFocusTranscript } from "./shell/chrome" ;
45import { createAppShell } from "./shell/index" ;
56import {
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} ) ;
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments