@@ -212,6 +212,121 @@ public void TestAddLine()
212212 Test ( "1\n 2" , Keys ( '1' , _ . ShiftEnter , '2' ) ) ;
213213 }
214214
215+ [ TestMethod ]
216+ public void TestInsertLineAbove ( )
217+ {
218+ TestSetup ( KeyMode . Cmd ) ;
219+
220+ var continutationPromptLength = PSConsoleReadlineOptions . DefaultContinuationPrompt . Length ;
221+
222+ // Test case - start with single line, cursor at end
223+ Test ( "56\n 1234" , Keys ( "1234" , _ . CtrlEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( 0 , 0 ) ) , "56" ) ) ;
224+
225+ // Test case - start with single line, cursor in home position
226+ Test ( "56\n 1234" , Keys ( "1234" , _ . Home , _ . CtrlEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( 0 , 0 ) ) , "56" ) ) ;
227+
228+ // Test case - start with single line, cursor in middle
229+ Test ( "56\n 1234" , Keys ( "1234" ,
230+ _ . LeftArrow , _ . LeftArrow , _ . CtrlEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( 0 , 0 ) ) ,
231+ "56" ) ) ;
232+
233+
234+ // Test case - start with multi-line, cursor at end of second line (end of input)
235+ Test ( "1234\n 9ABC\n 5678" , Keys ( "1234" , _ . ShiftEnter , "5678" ,
236+ _ . CtrlEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 1 ) ) ,
237+ "9ABC" ) ) ;
238+
239+ // Test case - start with multi-line, cursor at beginning of second line
240+ Test ( "1234\n 9ABC\n 5678" , Keys ( "1234" , _ . ShiftEnter , "5678" ,
241+ _ . LeftArrow , _ . Home , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 1 ) ) ,
242+ _ . CtrlEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 1 ) ) ,
243+ "9ABC" ) ) ;
244+
245+ // Test case - start with multi-line, cursor at end of first line
246+ Test ( "9ABC\n 1234\n 5678" , Keys ( "1234" , _ . ShiftEnter , "5678" ,
247+ _ . UpArrow , _ . LeftArrow , _ . End , CheckThat ( ( ) => AssertCursorLeftTopIs ( 4 , 0 ) ) ,
248+ _ . CtrlEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( 0 , 0 ) ) ,
249+ "9ABC" ) ) ;
250+
251+ // Test case - start with multi-line, cursor at beginning of first line - temporarily having to press Home twice to
252+ // work around bug in home handler.
253+ Test ( "9ABC\n 1234\n 5678" , Keys ( "1234" , _ . ShiftEnter , "5678" ,
254+ _ . UpArrow , _ . LeftArrow , _ . Home , _ . Home , CheckThat ( ( ) => AssertCursorLeftTopIs ( 0 , 0 ) ) ,
255+ _ . CtrlEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( 0 , 0 ) ) ,
256+ "9ABC" ) ) ;
257+
258+ // Test case - insert multiple blank lines
259+ Test ( "1234\n 9ABC\n \n 5678" , Keys ( "1234" , _ . ShiftEnter , "5678" ,
260+ _ . CtrlEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 1 ) ) ,
261+ _ . CtrlEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 1 ) ) ,
262+ "9ABC" ) ) ;
263+ }
264+
265+ [ TestMethod ]
266+ public void TestInsertLineBelow ( )
267+ {
268+ TestSetup ( KeyMode . Cmd ) ;
269+
270+ var continutationPromptLength = PSConsoleReadlineOptions . DefaultContinuationPrompt . Length ;
271+
272+ // Test case - start with single line, cursor at end
273+ Test ( "1234\n 56" , Keys ( "1234" ,
274+ _ . CtrlShiftEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 1 ) ) ,
275+ "56" ) ) ;
276+
277+ // Test case - start with single line, cursor in home position
278+ Test ( "1234\n 56" , Keys ( "1234" ,
279+ _ . Home , _ . CtrlShiftEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 1 ) ) ,
280+ "56" ) ) ;
281+
282+ // Test case - start with single line, cursor in middle
283+ Test ( "1234\n 56" , Keys ( "1234" ,
284+ _ . LeftArrow , _ . LeftArrow , _ . CtrlShiftEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 1 ) ) ,
285+ "56" ) ) ;
286+
287+ // Test case - start with multi-line, cursor at end of second line (end of input)
288+ Test ( "1234\n 5678\n 9ABC" , Keys ( "1234" , _ . ShiftEnter , "5678" ,
289+ _ . CtrlShiftEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 2 ) ) ,
290+ "9ABC" ) ) ;
291+
292+ // Test case - start with multi-line, cursor at beginning of second line
293+ Test ( "1234\n 5678\n 9ABC" , Keys ( "1234" , _ . ShiftEnter , "5678" ,
294+ _ . LeftArrow , _ . Home , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 1 ) ) ,
295+ _ . CtrlShiftEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 2 ) ) ,
296+ "9ABC" ) ) ;
297+
298+ // Test case - start with multi-line, cursor at end of first line
299+ Test ( "1234\n 9ABC\n 5678" , Keys ( "1234" , _ . ShiftEnter , "5678" ,
300+ _ . UpArrow , _ . LeftArrow , _ . End , CheckThat ( ( ) => AssertCursorLeftTopIs ( 4 , 0 ) ) ,
301+ _ . CtrlShiftEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 1 ) ) ,
302+ "9ABC" ) ) ;
303+
304+ // Test case - start with multi-line, cursor at beginning of first line - temporarily having to press Home twice to
305+ // work around bug in home handler.
306+ Test ( "1234\n 9ABC\n 5678" , Keys ( "1234" , _ . ShiftEnter , "5678" ,
307+ _ . UpArrow , _ . LeftArrow , _ . Home , _ . Home , CheckThat ( ( ) => AssertCursorLeftTopIs ( 0 , 0 ) ) ,
308+ _ . CtrlShiftEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 1 ) ) ,
309+ "9ABC" ) ) ;
310+
311+ // Test case - insert multiple blank lines
312+ Test ( "1234\n 5678\n \n 9ABC" , Keys ( "1234" , _ . ShiftEnter , "5678" ,
313+ _ . CtrlShiftEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 2 ) ) ,
314+ _ . CtrlShiftEnter , CheckThat ( ( ) => AssertCursorLeftTopIs ( continutationPromptLength , 3 ) ) ,
315+ "9ABC" ) ) ;
316+ }
317+
318+ [ TestMethod ]
319+ public void TestMultilineHomeBugFixed ( )
320+ {
321+ TestSetup ( KeyMode . Cmd ) ;
322+
323+ // Going from second line to first line, press left arrow and then home.
324+ // That puts cursor in column 1 instead of 0. Bug? This could have something
325+ // to do with BeginningOfLine testing against i > 1 in multiline edit instead
326+ // of i > 0.
327+ Test ( "1234\n 9ABC" , Keys ( "1234" , _ . ShiftEnter , "9ABC" , _ . UpArrow , _ . LeftArrow , _ . Home , CheckThat ( ( ) => AssertCursorLeftTopIs ( 0 , 0 ) ) ) ) ;
328+ }
329+
215330 [ TestMethod ]
216331 public void TestIgnore ( )
217332 {
0 commit comments