@@ -15,6 +15,9 @@ const SETTING_TERMINAL_VISIBLE = "terminal-visible";
15
15
const UPDATE_TYPE_EDITOR = 1 ;
16
16
const UPDATE_TYPE_SERIAL = 2 ;
17
17
18
+ const MINIMUM_COLS = 2 ;
19
+ const MINIMUM_ROWS = 1 ;
20
+
18
21
function isEditorVisible ( ) {
19
22
return editorPage . classList . contains ( 'active' ) ;
20
23
}
@@ -110,41 +113,40 @@ function updatePageLayout(updateType) {
110
113
}
111
114
112
115
function refitTerminal ( ) {
116
+ // Custom function to replace the terminal refit function as it was a bit buggy
117
+
113
118
// Re-fitting the terminal requires a full re-layout of the DOM which can be tricky to time right.
114
119
// see https://www.macarthur.me/posts/when-dom-updates-appear-to-be-asynchronous
115
120
window . requestAnimationFrame ( ( ) => {
116
121
window . requestAnimationFrame ( ( ) => {
117
122
window . requestAnimationFrame ( ( ) => {
118
- if ( state . fitter ) {
119
- // We need to get the main viewport height and calculate what the size of the terminal pane should be
120
-
121
- // Get the height of the header, footer, and serial bar to determine the height of the terminal
122
- let siteHeader = document . getElementById ( 'site-header' ) ;
123
- let mobileHeader = document . getElementById ( 'mobile-header' ) ;
124
- let headerHeight = siteHeader . offsetHeight ;
125
- if ( siteHeader . style . display === 'none' ) {
126
- headerHeight = mobileHeader . offsetHeight ;
123
+ const TERMINAL_ROW_HEIGHT = state . terminal . _core . _renderService . dimensions . css . cell . height ;
124
+ const TERMINAL_COL_WIDTH = state . terminal . _core . _renderService . dimensions . css . cell . width ;
125
+
126
+ // Get the height of the header, footer, and serial bar to determine the height of the terminal
127
+ let siteHeader = document . getElementById ( 'site-header' ) ;
128
+ let mobileHeader = document . getElementById ( 'mobile-header' ) ;
129
+ let headerHeight = siteHeader . offsetHeight ;
130
+ if ( siteHeader . style . display === 'none' ) {
131
+ headerHeight = mobileHeader . offsetHeight ;
132
+ }
133
+ let foorterBarHeight = document . getElementById ( 'footer-bar' ) . offsetHeight ;
134
+ let serialBarHeight = document . getElementById ( 'serial-bar' ) . offsetHeight ;
135
+ let viewportHeight = window . innerHeight ;
136
+ let terminalHeight = viewportHeight - headerHeight - foorterBarHeight - serialBarHeight ;
137
+ let terminalWidth = document . getElementById ( 'serial-page' ) . offsetWidth ;
138
+ let screen = document . querySelector ( '.xterm-screen' ) ;
139
+ if ( screen ) {
140
+ let cols = Math . floor ( terminalWidth / TERMINAL_COL_WIDTH ) ;
141
+ let rows = Math . floor ( terminalHeight / TERMINAL_ROW_HEIGHT ) ;
142
+ if ( cols < MINIMUM_COLS ) {
143
+ cols = MINIMUM_COLS ;
127
144
}
128
- let foorterBarHeight = document . getElementById ( 'footer-bar' ) . offsetHeight ;
129
- let serialBarHeight = document . getElementById ( 'serial-bar' ) . offsetHeight ;
130
- let viewportHeight = window . innerHeight ;
131
- let terminalHeight = viewportHeight - headerHeight - foorterBarHeight - serialBarHeight ;
132
-
133
- // Fit the terminal to the new size (works good for growing)
134
- state . fitter . fit ( ) ;
135
-
136
- // Fix the terminal screen height if it's too big
137
- let screen = document . querySelector ( '.xterm-screen' ) ;
138
- if ( screen && ( terminalHeight < screen . offsetHeight ) ) {
139
- // xterm-screen is 17px per row and 9px per column
140
- let rows = Math . floor ( terminalHeight / 17 ) ;
141
- if ( rows < 0 ) {
142
- rows = 0 ;
143
- }
144
- if ( rows < state . fitter . proposeDimensions ( ) . rows ) {
145
- screen . style . height = ( rows * 17 ) + 'px' ;
146
- }
145
+ if ( rows < MINIMUM_ROWS ) {
146
+ rows = MINIMUM_ROWS ;
147
147
}
148
+ screen . style . width = ( cols * TERMINAL_COL_WIDTH ) + 'px' ;
149
+ screen . style . height = ( rows * TERMINAL_ROW_HEIGHT ) + 'px' ;
148
150
}
149
151
} ) ;
150
152
} ) ;
0 commit comments