@@ -20,7 +20,7 @@ private static void InvertLines(int start, int count)
2020 buffer [ i ] . ForegroundColor = ( ConsoleColor ) ( ( int ) buffer [ i ] . ForegroundColor ^ 7 ) ;
2121 buffer [ i ] . BackgroundColor = ( ConsoleColor ) ( ( int ) buffer [ i ] . BackgroundColor ^ 7 ) ;
2222 }
23- _singleton . _console . WriteBufferLines ( buffer , ref start ) ;
23+ _singleton . _console . WriteBufferLines ( buffer , ref start , false ) ;
2424 }
2525
2626 /// <summary>
@@ -33,6 +33,13 @@ public static void CaptureScreen(ConsoleKeyInfo? key = null, object arg = null)
3333 int selectionTop = _singleton . _console . CursorTop ;
3434 int selectionHeight = 1 ;
3535 int currentY = selectionTop ;
36+ Internal . IConsole console = _singleton . _console ;
37+
38+ // We'll keep the current selection line (currentY) at least 4 lines
39+ // away from the top or bottom of the window.
40+ const int margin = 5 ;
41+ Func < bool > tooCloseToTop = ( ) => { return ( currentY - console . WindowTop ) < margin ; } ;
42+ Func < bool > tooCloseToBottom = ( ) => { return ( ( console . WindowTop + console . WindowHeight ) - currentY ) < margin ; } ;
3643
3744 // Current lines starts out selected
3845 InvertLines ( selectionTop , selectionHeight ) ;
@@ -42,7 +49,11 @@ public static void CaptureScreen(ConsoleKeyInfo? key = null, object arg = null)
4249 var k = ReadKey ( ) ;
4350 switch ( k . Key )
4451 {
52+ case ConsoleKey . K :
4553 case ConsoleKey . UpArrow :
54+ if ( tooCloseToTop ( ) )
55+ ScrollDisplayUpLine ( ) ;
56+
4657 if ( currentY > 0 )
4758 {
4859 currentY -= 1 ;
@@ -67,8 +78,12 @@ public static void CaptureScreen(ConsoleKeyInfo? key = null, object arg = null)
6778 }
6879 break ;
6980
81+ case ConsoleKey . J :
7082 case ConsoleKey . DownArrow :
71- if ( currentY < ( _singleton . _console . BufferHeight - 1 ) )
83+ if ( tooCloseToBottom ( ) )
84+ ScrollDisplayDownLine ( ) ;
85+
86+ if ( currentY < ( console . BufferHeight - 1 ) )
7287 {
7388 currentY += 1 ;
7489 if ( ( k . Modifiers & ConsoleModifiers . Shift ) == ConsoleModifiers . Shift )
@@ -103,6 +118,7 @@ public static void CaptureScreen(ConsoleKeyInfo? key = null, object arg = null)
103118 case ConsoleKey . Enter :
104119 InvertLines ( selectionTop , selectionHeight ) ;
105120 DumpScreenToClipboard ( selectionTop , selectionHeight ) ;
121+ ScrollDisplayToCursor ( ) ;
106122 return ;
107123
108124 case ConsoleKey . Escape :
@@ -124,6 +140,7 @@ public static void CaptureScreen(ConsoleKeyInfo? key = null, object arg = null)
124140 }
125141 }
126142 InvertLines ( selectionTop , selectionHeight ) ;
143+ ScrollDisplayToCursor ( ) ;
127144 }
128145
129146 private const string CmdColorTable = @"
0 commit comments