@@ -79,20 +79,24 @@ describe("Editor component", () => {
7979 assert . strictEqual ( editor . getText ( ) , "first" ) ;
8080 } ) ;
8181
82- it ( "restores draft on Down arrow after browsing history " , ( ) => {
82+ it ( "jumps to start before entering history from a non-empty draft " , ( ) => {
8383 const editor = new Editor ( createTestTUI ( ) , defaultEditorTheme ) ;
8484
8585 editor . addToHistory ( "prompt" ) ;
8686 editor . setText ( "draft" ) ;
8787 editor . handleInput ( "\x1b[D" ) ;
8888 editor . handleInput ( "\x1b[D" ) ;
8989
90- editor . handleInput ( "\x1b[A" ) ; // Up - shows "prompt"
90+ editor . handleInput ( "\x1b[A" ) ; // Up - jumps to start before history browsing
91+ assert . strictEqual ( editor . getText ( ) , "draft" ) ;
92+ assert . deepStrictEqual ( editor . getCursor ( ) , { line : 0 , col : 0 } ) ;
93+
94+ editor . handleInput ( "\x1b[A" ) ; // Up at start - shows "prompt"
9195 assert . strictEqual ( editor . getText ( ) , "prompt" ) ;
9296
9397 editor . handleInput ( "\x1b[B" ) ; // Down - restores draft
9498 assert . strictEqual ( editor . getText ( ) , "draft" ) ;
95- assert . deepStrictEqual ( editor . getCursor ( ) , { line : 0 , col : 3 } ) ;
99+ assert . deepStrictEqual ( editor . getCursor ( ) , { line : 0 , col : 0 } ) ;
96100 } ) ;
97101
98102 it ( "navigates forward through history with Down arrow" , ( ) => {
@@ -104,6 +108,7 @@ describe("Editor component", () => {
104108 editor . setText ( "draft" ) ;
105109
106110 // Go to oldest
111+ editor . handleInput ( "\x1b[A" ) ; // start of draft
107112 editor . handleInput ( "\x1b[A" ) ; // third
108113 editor . handleInput ( "\x1b[A" ) ; // second
109114 editor . handleInput ( "\x1b[A" ) ; // first
0 commit comments