@@ -79,7 +79,10 @@ const enum Constants {
7979 * terminal process. This period helps ensure the terminal has good initial dimensions to work
8080 * with if it's going to be a foreground terminal.
8181 */
82- WaitForContainerThreshold = 100
82+ WaitForContainerThreshold = 100 ,
83+
84+ DefaultCols = 80 ,
85+ DefaultRows = 30 ,
8386}
8487
8588let xtermConstructor : Promise < typeof XTermTerminal > | undefined ;
@@ -538,9 +541,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
538541 const editorOptions = this . _configurationService . getValue < IEditorOptions > ( 'editor' ) ;
539542
540543 const xterm = new Terminal ( {
541- // TODO: Replace null with undefined when https://github.com/xtermjs/xterm.js/issues/3329 is resolved
542- cols : this . _cols || null as any ,
543- rows : this . _rows || null as any ,
544+ cols : this . _cols || Constants . DefaultCols ,
545+ rows : this . _rows || Constants . DefaultRows ,
544546 altClickMovesCursor : config . altClickMovesCursor && editorOptions . multiCursorModifier === 'alt' ,
545547 scrollback : config . scrollback ,
546548 theme : this . _getXtermTheme ( ) ,
@@ -1058,6 +1060,11 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
10581060 this . _wrapperElement . classList . toggle ( 'active' , visible ) ;
10591061 }
10601062 if ( visible && this . _xterm && this . _xtermCore ) {
1063+ // Resize to re-evaluate dimensions, this will ensure when switching to a terminal it is
1064+ // using the most up to date dimensions (eg. when terminal is created in the background
1065+ // using cached dimensions of a split terminal).
1066+ this . _resize ( ) ;
1067+
10611068 // Trigger a manual scroll event which will sync the viewport and scroll bar. This is
10621069 // necessary if the number of rows in the terminal has decreased while it was in the
10631070 // background since scrollTop changes take no effect but the terminal's position does
@@ -1159,8 +1166,15 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
11591166 if ( this . _isDisposed ) {
11601167 return ;
11611168 }
1169+
1170+ // Re-evaluate dimensions if the container has been set since the xterm instance was created
1171+ if ( this . _container && this . _cols === 0 && this . _rows === 0 ) {
1172+ this . _initDimensions ( ) ;
1173+ this . _xterm ?. resize ( this . _cols || Constants . DefaultCols , this . _rows || Constants . DefaultRows ) ;
1174+ }
1175+
11621176 const hadIcon = ! ! this . shellLaunchConfig . icon ;
1163- await this . _processManager . createProcess ( this . _shellLaunchConfig , this . _cols , this . _rows , this . _accessibilityService . isScreenReaderOptimized ( ) ) . then ( error => {
1177+ await this . _processManager . createProcess ( this . _shellLaunchConfig , this . _cols || Constants . DefaultCols , this . _rows || Constants . DefaultRows , this . _accessibilityService . isScreenReaderOptimized ( ) ) . then ( error => {
11641178 if ( error ) {
11651179 this . _onProcessExit ( error ) ;
11661180 }
0 commit comments