@@ -805,23 +805,29 @@ void UpdateColorsIfNecessary(string newColor)
805
805
_initialY -= 1 ;
806
806
point . Y -= 1 ;
807
807
}
808
- else if ( point . Y == - 1 )
808
+ else if ( point . Y < 0 )
809
809
{
810
- // This could only happen in two cases:
810
+ // This could happen in at least 3 cases:
811
811
//
812
812
// 1. when you are adding characters to the first line in the buffer (top = 0) to make the logical line
813
813
// wrap to one extra physical line. This would cause the buffer to scroll up and push the line being
814
814
// edited up-off the buffer.
815
- // 2. when you are deleting characters backwards from the first line in the buffer without changing the
815
+ // 2. when you are deleting characters (Backspace) from the first line in the buffer without changing the
816
816
// number of physical lines (either editing the same logical line or causing the current logical line
817
817
// to merge in the previous but still span to the current physical line). The cursor is supposed to
818
818
// appear in the previous line (which is off the buffer).
819
+ // 3. Both 'bck-i-search' and 'fwd-i-search' may find a history command with multi-line text, and the
820
+ // matching string in the text, where the cursor is supposed to be moved to, will be scrolled up-off
821
+ // the buffer after rendering.
819
822
//
820
- // In these case, we move the cursor to the upper- left-most position of the window , where it's closest to
821
- // the previous editing position, and update '_current' appropriately .
823
+ // In these case, we move the cursor to the left-most position of the first line , where it's closest to
824
+ // the real position it should be in the ideal world .
822
825
823
- _current += ( bufferWidth - point . X ) ;
826
+ // First update '_current' to the index of the first character that appears on the line 0,
827
+ // then we call 'ConvertOffsetToPoint' again to get the right cursor position to use.
824
828
point . X = point . Y = 0 ;
829
+ _current = ConvertLineAndColumnToOffset ( point ) ;
830
+ point = ConvertOffsetToPoint ( _current ) ;
825
831
}
826
832
827
833
_console . SetCursorPosition ( point . X , point . Y ) ;
0 commit comments