@@ -112,4 +112,98 @@ suite('Terminal UI Tests', () => {
112112 await vs . terminal . assertNotContains ( '3 4]' , 'Second line should not stick after cycling away with down arrow' )
113113 await vs . terminal . type ( Key . ESCAPE )
114114 } ) ;
115+
116+ test ( 'Test multi-line command cursor position' , async ( ) => {
117+ // Execute a multi-line command
118+ await vs . terminal . type ( 'a = 1\nb = 2' )
119+ await vs . terminal . type ( Key . RETURN )
120+ await vs . terminal . executeCommand ( 'clc' )
121+
122+ // Recall the multi-line command
123+ await vs . terminal . type ( Key . ARROW_UP )
124+
125+ // Cursor should be at the end of the command - verify position of cursor
126+ // Should be on line 1 (second line), at column 5 (after "b = 2")
127+ await vs . terminal . assertCursorPosition ( 1 , 5 , 'Cursor should be at end of multi-line command' )
128+ await vs . terminal . type ( Key . ESCAPE )
129+ } ) ;
130+
131+ test ( 'Test multi-line command left arrow navigation to upper lines' , async ( ) => {
132+ // Execute a multi-line command
133+ await vs . terminal . type ( 'x = 10\ny = 20\nz = 30' )
134+ await vs . terminal . type ( Key . RETURN )
135+ await vs . terminal . executeCommand ( 'clc' )
136+
137+ // Recall the multi-line command
138+ await vs . terminal . type ( Key . ARROW_UP )
139+
140+ // Move left to navigate from last line to first line
141+ // Start at end: "z = 30|"
142+ for ( let i = 0 ; i < 6 ; i ++ ) {
143+ await vs . terminal . type ( Key . ARROW_LEFT )
144+ }
145+ // Now at: "z = 30" -> should cross newline to second line
146+ await vs . terminal . type ( Key . ARROW_LEFT )
147+
148+ // Verify we're on second line at the end
149+ // Should be on line 1 (second line), at column 6 (after "y = 20")
150+ await vs . terminal . assertCursorPosition ( 1 , 6 , 'Cursor should be at end of second line after navigating left from third line' )
151+ await vs . terminal . type ( Key . ESCAPE )
152+ } ) ;
153+
154+ test ( 'Test multi-line command right arrow navigation to lower lines' , async ( ) => {
155+ // Execute a multi-line command
156+ await vs . terminal . type ( 'p = 1\nq = 2' )
157+ await vs . terminal . type ( Key . RETURN )
158+ await vs . terminal . executeCommand ( 'clc' )
159+
160+ // Recall the multi-line command and navigate to start
161+ await vs . terminal . type ( Key . ARROW_UP )
162+ await vs . terminal . type ( Key . HOME )
163+
164+ // Now at start of first line: "|p = 1"
165+ // Move right to end of first line
166+ for ( let i = 0 ; i < 5 ; i ++ ) {
167+ await vs . terminal . type ( Key . ARROW_RIGHT )
168+ }
169+
170+ // Now at: "p = 1|" -> next right should cross newline to second line
171+ await vs . terminal . type ( Key . ARROW_RIGHT )
172+
173+ // Verify we're on second line at the beginning
174+ // Should be on line 1 (second line), at column 0 (start of "q = 2")
175+ await vs . terminal . assertCursorPosition ( 1 , 0 , 'Cursor should be at start of second line after navigating right from first line' )
176+ await vs . terminal . type ( Key . ESCAPE )
177+ } ) ;
178+
179+ test ( 'Test multi-line command bidirectional navigation' , async ( ) => {
180+ // Execute a three-line command
181+ await vs . terminal . type ( 'line1\nline2\nline3' )
182+ await vs . terminal . type ( Key . RETURN )
183+ await vs . terminal . executeCommand ( 'clc' )
184+
185+ // Recall and navigate: end -> line2 -> line1 -> line2 -> line3
186+ await vs . terminal . type ( Key . ARROW_UP )
187+
188+ // Navigate to middle of second line using left arrows
189+ for ( let i = 0 ; i < 8 ; i ++ ) { // "line3" (5 chars) + newline + "li" (2 chars) = 8 left arrows
190+ await vs . terminal . type ( Key . ARROW_LEFT )
191+ }
192+
193+ // Verify position on line2
194+ // Should be on line 1 (second line), at column 2 (after "li")
195+ await vs . terminal . assertCursorPosition ( 1 , 2 , 'Cursor should be at position 2 on line 1 after navigating left' )
196+
197+ // Navigate back right to line3
198+ await vs . terminal . type ( Key . ARROW_RIGHT ) // move past 'n'
199+ await vs . terminal . type ( Key . ARROW_RIGHT ) // 'e'
200+ await vs . terminal . type ( Key . ARROW_RIGHT ) // '2'
201+ await vs . terminal . type ( Key . ARROW_RIGHT ) // cross newline to line3
202+
203+ // Verify we're back on line3
204+ // Should be on line 2 (third line), at column 0 (start of "line3")
205+ await vs . terminal . assertCursorPosition ( 2 , 0 , 'Cursor should be at start of line 2 after navigating right back' )
206+
207+ await vs . terminal . type ( Key . ESCAPE )
208+ } ) ;
115209} ) ;
0 commit comments