@@ -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
}
@@ -59,6 +62,7 @@ export function showSerial() {
59
62
60
63
// update type is used to indicate which button was clicked
61
64
function updatePageLayout ( updateType ) {
65
+ // If both are visible, show the separator
62
66
if ( isEditorVisible ( ) && isSerialVisible ( ) ) {
63
67
pageSeparator . classList . add ( 'active' ) ;
64
68
} else {
@@ -72,6 +76,7 @@ function updatePageLayout(updateType) {
72
76
73
77
// Mobile layout, so only show one or the other
74
78
if ( mainContent . offsetWidth < 768 ) {
79
+ // Prioritize based on the update type
75
80
if ( updateType == UPDATE_TYPE_EDITOR && isEditorVisible ( ) ) {
76
81
serialPage . classList . remove ( 'active' ) ;
77
82
} else if ( updateType == UPDATE_TYPE_SERIAL && isSerialVisible ( ) ) {
@@ -108,13 +113,40 @@ function updatePageLayout(updateType) {
108
113
}
109
114
110
115
function refitTerminal ( ) {
116
+ // Custom function to replace the terminal refit function as it was a bit buggy
117
+
111
118
// Re-fitting the terminal requires a full re-layout of the DOM which can be tricky to time right.
112
119
// see https://www.macarthur.me/posts/when-dom-updates-appear-to-be-asynchronous
113
120
window . requestAnimationFrame ( ( ) => {
114
121
window . requestAnimationFrame ( ( ) => {
115
122
window . requestAnimationFrame ( ( ) => {
116
- if ( state . fitter ) {
117
- state . fitter . fit ( ) ;
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 footerBarHeight = document . getElementById ( 'footer-bar' ) . offsetHeight ;
134
+ let serialBarHeight = document . getElementById ( 'serial-bar' ) . offsetHeight ;
135
+ let viewportHeight = window . innerHeight ;
136
+ let terminalHeight = viewportHeight - headerHeight - footerBarHeight - 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 ;
144
+ }
145
+ if ( rows < MINIMUM_ROWS ) {
146
+ rows = MINIMUM_ROWS ;
147
+ }
148
+ screen . style . width = ( cols * TERMINAL_COL_WIDTH ) + 'px' ;
149
+ screen . style . height = ( rows * TERMINAL_ROW_HEIGHT ) + 'px' ;
118
150
}
119
151
} ) ;
120
152
} ) ;
@@ -130,8 +162,7 @@ function fixViewportHeight(e) {
130
162
}
131
163
132
164
// Resize the panes when the separator is moved
133
- function resize ( e ) {
134
- console . log ( "Resized" ) ;
165
+ function resizePanels ( e ) {
135
166
const w = mainContent . offsetWidth ;
136
167
const gap = pageSeparator . offsetWidth ;
137
168
const ratio = e . clientX / w ;
@@ -182,12 +213,12 @@ function loadPanelSettings() {
182
213
}
183
214
184
215
function stopResize ( e ) {
185
- window . removeEventListener ( 'mousemove' , resize , false ) ;
216
+ window . removeEventListener ( 'mousemove' , resizePanels , false ) ;
186
217
window . removeEventListener ( 'mouseup' , stopResize , false ) ;
187
218
}
188
219
189
220
pageSeparator . addEventListener ( 'mousedown' , async function ( e ) {
190
- window . addEventListener ( 'mousemove' , resize , false ) ;
221
+ window . addEventListener ( 'mousemove' , resizePanels , false ) ;
191
222
window . addEventListener ( 'mouseup' , stopResize , false ) ;
192
223
} ) ;
193
224
0 commit comments