@@ -64,10 +64,12 @@ const document = (typeof window !== 'undefined') ? window.document : null;
6464const WRITE_BUFFER_PAUSE_THRESHOLD = 5 ;
6565
6666/**
67- * The number of writes to perform in a single batch before allowing the
68- * renderer to catch up with a 0ms setTimeout.
67+ * The max number of ms to spend on writes before allowing the renderer to
68+ * catch up with a 0ms setTimeout. A value of < 33 to keep us close to
69+ * 30fps, and a value of < 16 to try to run at 60fps. Of course, the real FPS
70+ * depends on the time it takes for the renderer to draw the frame.
6971 */
70- const WRITE_BATCH_SIZE = 300 ;
72+ const WRITE_TIMEOUT_MS = 12 ;
7173
7274const MINIMUM_COLS = 2 ; // Less than 2 can mess with wide chars
7375const MINIMUM_ROWS = 1 ;
@@ -738,6 +740,11 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
738740 this . mouseHelper = new MouseHelper ( this . renderer ) ;
739741 // apply mouse event classes set by escape codes before terminal was attached
740742 this . element . classList . toggle ( 'enable-mouse-events' , this . mouseEvents ) ;
743+ if ( this . mouseEvents ) {
744+ this . selectionManager . disable ( ) ;
745+ } else {
746+ this . selectionManager . enable ( ) ;
747+ }
741748
742749 if ( this . options . screenReaderMode ) {
743750 // Note that this must be done *after* the renderer is created in order to
@@ -1343,19 +1350,20 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
13431350 }
13441351 }
13451352
1346- protected _innerWrite ( ) : void {
1353+ protected _innerWrite ( bufferOffset : number = 0 ) : void {
13471354 // Ensure the terminal isn't disposed
13481355 if ( this . _isDisposed ) {
13491356 this . writeBuffer = [ ] ;
13501357 }
13511358
1352- const writeBatch = this . writeBuffer . splice ( 0 , WRITE_BATCH_SIZE ) ;
1353- while ( writeBatch . length > 0 ) {
1354- const data = writeBatch . shift ( ) ;
1359+ const startTime = Date . now ( ) ;
1360+ while ( this . writeBuffer . length > bufferOffset ) {
1361+ const data = this . writeBuffer [ bufferOffset ] ;
1362+ bufferOffset ++ ;
13551363
13561364 // If XOFF was sent in order to catch up with the pty process, resume it if
1357- // the writeBuffer is empty to allow more data to come in.
1358- if ( this . _xoffSentToCatchUp && writeBatch . length === 0 && this . writeBuffer . length === 0 ) {
1365+ // we reached the end of the writeBuffer to allow more data to come in.
1366+ if ( this . _xoffSentToCatchUp && this . writeBuffer . length === bufferOffset ) {
13591367 this . handler ( C0 . DC1 ) ;
13601368 this . _xoffSentToCatchUp = false ;
13611369 }
@@ -1373,12 +1381,17 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
13731381
13741382 this . updateRange ( this . buffer . y ) ;
13751383 this . refresh ( this . _refreshStart , this . _refreshEnd ) ;
1384+
1385+ if ( Date . now ( ) - startTime >= WRITE_TIMEOUT_MS ) {
1386+ break ;
1387+ }
13761388 }
1377- if ( this . writeBuffer . length > 0 ) {
1389+ if ( this . writeBuffer . length > bufferOffset ) {
13781390 // Allow renderer to catch up before processing the next batch
1379- setTimeout ( ( ) => this . _innerWrite ( ) , 0 ) ;
1391+ setTimeout ( ( ) => this . _innerWrite ( bufferOffset ) , 0 ) ;
13801392 } else {
13811393 this . _writeInProgress = false ;
1394+ this . writeBuffer = [ ] ;
13821395 }
13831396 }
13841397
0 commit comments