@@ -122,6 +122,14 @@ public void UpdateConsoleInfo(IConsole console)
122
122
cursorLeft = console . CursorLeft ;
123
123
cursorTop = console . CursorTop ;
124
124
}
125
+
126
+ public void UpdateConsoleInfo ( int bWidth , int bHeight , int cLeft , int cTop )
127
+ {
128
+ bufferWidth = bWidth ;
129
+ bufferHeight = bHeight ;
130
+ cursorLeft = cLeft ;
131
+ cursorTop = cTop ;
132
+ }
125
133
}
126
134
127
135
internal readonly struct RenderDataOffset
@@ -212,9 +220,9 @@ private void RenderWithPredictionQueryPaused()
212
220
213
221
private void Render ( )
214
222
{
215
- // If there are a bunch of keys queued up, skip rendering if we've rendered
216
- // recently.
217
- if ( _queuedKeys . Count > 10 && ( _lastRenderTime . ElapsedMilliseconds < 50 ) )
223
+ // If there are a bunch of keys queued up, skip rendering if we've rendered very recently.
224
+ long elapsedMs = _lastRenderTime . ElapsedMilliseconds ;
225
+ if ( _queuedKeys . Count > 10 && elapsedMs < 50 )
218
226
{
219
227
// We won't render, but most likely the tokens will be different, so make
220
228
// sure we don't use old tokens, also allow garbage to get collected.
@@ -225,6 +233,20 @@ private void Render()
225
233
return ;
226
234
}
227
235
236
+ // If we've rendered very recently, skip the terminal window resizing check as it's unlikely
237
+ // to happen in such a short time interval.
238
+ // We try to avoid unnecessary resizing check because it requires getting the cursor position
239
+ // which would force a network round trip in an environment where front-end xtermjs talking to
240
+ // a server-side PTY via websocket. Without querying for cursor position, content written on
241
+ // the server side could be buffered, which is much more performant.
242
+ // See the following 2 GitHub issues for more context:
243
+ // - https://github.com/PowerShell/PSReadLine/issues/3879#issuecomment-2573996070
244
+ // - https://github.com/PowerShell/PowerShell/issues/24696
245
+ if ( elapsedMs < 50 )
246
+ {
247
+ _handlePotentialResizing = false ;
248
+ }
249
+
228
250
ForceRender ( ) ;
229
251
}
230
252
@@ -928,7 +950,7 @@ void UpdateColorsIfNecessary(string newColor)
928
950
_console . SetCursorPosition ( point . X , point . Y ) ;
929
951
_console . CursorVisible = true ;
930
952
931
- _previousRender . UpdateConsoleInfo ( _console ) ;
953
+ _previousRender . UpdateConsoleInfo ( bufferWidth , bufferHeight , point . X , point . Y ) ;
932
954
_previousRender . initialY = _initialY ;
933
955
934
956
// TODO: set WindowTop if necessary
0 commit comments