@@ -61,6 +61,7 @@ class RenderData
6161 } ;
6262 private int _initialX ;
6363 private int _initialY ;
64+ private bool _waitingToRender ;
6465
6566 private ConsoleColor _initialForeground ;
6667 private ConsoleColor _initialBackground ;
@@ -112,6 +113,7 @@ private void Render()
112113 _tokens = null ;
113114 _ast = null ;
114115 _parseErrors = null ;
116+ _waitingToRender = true ;
115117 return ;
116118 }
117119
@@ -816,6 +818,7 @@ void UpdateColorsIfNecessary(string newColor)
816818 // TODO: set WindowTop if necessary
817819
818820 _lastRenderTime . Restart ( ) ;
821+ _waitingToRender = false ;
819822 }
820823
821824 private static string Spaces ( int cnt )
@@ -980,37 +983,44 @@ private void RecomputeInitialCoords()
980983
981984 private void MoveCursor ( int newCursor )
982985 {
983- // In case the buffer was resized
984- RecomputeInitialCoords ( ) ;
985- _previousRender . bufferWidth = _console . BufferWidth ;
986- _previousRender . bufferHeight = _console . BufferHeight ;
987-
988- var point = ConvertOffsetToPoint ( newCursor ) ;
989- if ( point . Y < 0 )
986+ // Only update screen cursor if the buffer is fully rendered.
987+ if ( ! _waitingToRender )
990988 {
991- Ding ( ) ;
992- return ;
993- }
989+ // In case the buffer was resized
990+ RecomputeInitialCoords ( ) ;
991+ _previousRender . bufferWidth = _console . BufferWidth ;
992+ _previousRender . bufferHeight = _console . BufferHeight ;
994993
995- if ( point . Y == _console . BufferHeight )
996- {
997- // The cursor top exceeds the buffer height, so adjust the initial cursor
998- // position and the to-be-set cursor position for scrolling up the buffer.
999- _initialY -= 1 ;
1000- point . Y -= 1 ;
994+ var point = ConvertOffsetToPoint ( newCursor ) ;
995+ if ( point . Y < 0 )
996+ {
997+ Ding ( ) ;
998+ return ;
999+ }
10011000
1002- // Insure the cursor is on the last line of the buffer prior
1003- // to issuing a newline to scroll the buffer.
1004- _console . SetCursorPosition ( point . X , point . Y ) ;
1001+ if ( point . Y == _console . BufferHeight )
1002+ {
1003+ // The cursor top exceeds the buffer height, so adjust the initial cursor
1004+ // position and the to-be-set cursor position for scrolling up the buffer.
1005+ _initialY -= 1 ;
1006+ point . Y -= 1 ;
10051007
1006- // Scroll up the buffer by 1 line.
1007- _console . Write ( "\n " ) ;
1008- }
1009- else
1010- {
1011- _console . SetCursorPosition ( point . X , point . Y ) ;
1008+ // Insure the cursor is on the last line of the buffer prior
1009+ // to issuing a newline to scroll the buffer.
1010+ _console . SetCursorPosition ( point . X , point . Y ) ;
1011+
1012+ // Scroll up the buffer by 1 line.
1013+ _console . Write ( "\n " ) ;
1014+ }
1015+ else
1016+ {
1017+ _console . SetCursorPosition ( point . X , point . Y ) ;
1018+ }
10121019 }
10131020
1021+ // While waiting to render, and a keybinding has occured that is moving the cursor,
1022+ // converting offset to point could potentially result in an invalid screen position,
1023+ // but the insertion point should reflect the move.
10141024 _current = newCursor ;
10151025 }
10161026
0 commit comments