File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
packages/cli/src/ui/components Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -543,4 +543,30 @@ describe('InputPrompt', () => {
543543 expect ( props . buffer . newline ) . toHaveBeenCalled ( ) ;
544544 unmount ( ) ;
545545 } ) ;
546+
547+ it ( 'should clear the buffer on Ctrl+C if it has text' , async ( ) => {
548+ props . buffer . setText ( 'some text to clear' ) ;
549+ const { stdin, unmount } = render ( < InputPrompt { ...props } /> ) ;
550+ await wait ( ) ;
551+
552+ stdin . write ( '\x03' ) ; // Ctrl+C character
553+ await wait ( ) ;
554+
555+ expect ( props . buffer . setText ) . toHaveBeenCalledWith ( '' ) ;
556+ expect ( mockCompletion . resetCompletionState ) . toHaveBeenCalled ( ) ;
557+ expect ( props . onSubmit ) . not . toHaveBeenCalled ( ) ;
558+ unmount ( ) ;
559+ } ) ;
560+
561+ it ( 'should NOT clear the buffer on Ctrl+C if it is empty' , async ( ) => {
562+ props . buffer . text = '' ;
563+ const { stdin, unmount } = render ( < InputPrompt { ...props } /> ) ;
564+ await wait ( ) ;
565+
566+ stdin . write ( '\x03' ) ; // Ctrl+C character
567+ await wait ( ) ;
568+
569+ expect ( props . buffer . setText ) . not . toHaveBeenCalled ( ) ;
570+ unmount ( ) ;
571+ } ) ;
546572} ) ;
Original file line number Diff line number Diff line change @@ -356,6 +356,16 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
356356 }
357357 if ( key . ctrl && key . name === 'e' ) {
358358 buffer . move ( 'end' ) ;
359+ buffer . moveToOffset ( cpLen ( buffer . text ) ) ;
360+ return ;
361+ }
362+ // Ctrl+C (Clear input)
363+ if ( key . ctrl && key . name === 'c' ) {
364+ if ( buffer . text . length > 0 ) {
365+ buffer . setText ( '' ) ;
366+ resetCompletionState ( ) ;
367+ return ;
368+ }
359369 return ;
360370 }
361371
@@ -397,6 +407,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
397407 handleSubmitAndClear ,
398408 shellHistory ,
399409 handleClipboardImage ,
410+ resetCompletionState ,
400411 ] ,
401412 ) ;
402413
You can’t perform that action at this time.
0 commit comments