@@ -74,6 +74,7 @@ export default class TerminalComponent {
7474 this . parsedAppKeybindingsVersion = - 1 ;
7575 this . boundNativeSelectionMenuHandler = null ;
7676 this . visibleScrollbarWidth = undefined ;
77+ this . lastRequestedServerSize = null ;
7778
7879 this . init ( ) ;
7980 }
@@ -809,7 +810,7 @@ export default class TerminalComponent {
809810
810811 // Focus terminal and ensure it's ready
811812 this . terminal . focus ( ) ;
812- this . fit ( ) ;
813+ void this . fitAndResizeTerminal ( true ) ;
813814
814815 if ( ! settled ) {
815816 settled = true ;
@@ -872,6 +873,9 @@ export default class TerminalComponent {
872873 */
873874 async resizeTerminal ( cols , rows ) {
874875 if ( ! this . pid || ! this . serverMode ) return ;
876+ const resizeKey = `${ cols } x${ rows } ` ;
877+ if ( this . lastRequestedServerSize === resizeKey ) return ;
878+ this . lastRequestedServerSize = resizeKey ;
875879
876880 try {
877881 await new Promise ( ( resolve , reject ) => {
@@ -887,6 +891,9 @@ export default class TerminalComponent {
887891 ) ;
888892 } ) ;
889893 } catch ( error ) {
894+ if ( this . lastRequestedServerSize === resizeKey ) {
895+ this . lastRequestedServerSize = null ;
896+ }
890897 console . error ( "Failed to resize terminal:" , error ) ;
891898 }
892899 }
@@ -900,6 +907,27 @@ export default class TerminalComponent {
900907 }
901908 }
902909
910+ /**
911+ * Fit the client and immediately synchronize dimensions to the PTY.
912+ * @param {boolean } forceServerSync Sync even when fitting kept the same size
913+ */
914+ async fitAndResizeTerminal ( forceServerSync = false ) {
915+ if ( ! this . terminal || ! this . fitAddon ) return ;
916+
917+ const previousCols = this . terminal . cols ;
918+ const previousRows = this . terminal . rows ;
919+ this . fit ( ) ;
920+
921+ if (
922+ this . serverMode &&
923+ ( forceServerSync ||
924+ this . terminal . cols !== previousCols ||
925+ this . terminal . rows !== previousRows )
926+ ) {
927+ await this . resizeTerminal ( this . terminal . cols , this . terminal . rows ) ;
928+ }
929+ }
930+
903931 /**
904932 * Write data to terminal
905933 * @param {string } data - Data to write
@@ -1009,7 +1037,9 @@ export default class TerminalComponent {
10091037 updateScrollbarVisibility ( visible ) {
10101038 if ( ! this . terminal ) return ;
10111039
1012- const overviewRuler = { ...this . terminal . options . overviewRuler } ;
1040+ const overviewRuler = {
1041+ ...( this . terminal . options . overviewRuler ?? { } ) ,
1042+ } ;
10131043 if ( visible === false ) {
10141044 if (
10151045 ! this . terminal . element ?. classList . contains ( "terminal-scrollbar-hidden" )
@@ -1032,7 +1062,7 @@ export default class TerminalComponent {
10321062
10331063 requestAnimationFrame ( ( ) => {
10341064 if ( ! this . terminal ) return ;
1035- this . fitAddon ?. fit ( ) ;
1065+ void this . fitAndResizeTerminal ( ) ;
10361066 } ) ;
10371067 }
10381068
0 commit comments