@@ -15,6 +15,9 @@ const SETTING_TERMINAL_VISIBLE = "terminal-visible";
1515const UPDATE_TYPE_EDITOR = 1 ;
1616const UPDATE_TYPE_SERIAL = 2 ;
1717
18+ const MINIMUM_COLS = 2 ;
19+ const MINIMUM_ROWS = 1 ;
20+
1821function isEditorVisible ( ) {
1922 return editorPage . classList . contains ( 'active' ) ;
2023}
@@ -59,6 +62,7 @@ export function showSerial() {
5962
6063// update type is used to indicate which button was clicked
6164function updatePageLayout ( updateType ) {
65+ // If both are visible, show the separator
6266 if ( isEditorVisible ( ) && isSerialVisible ( ) ) {
6367 pageSeparator . classList . add ( 'active' ) ;
6468 } else {
@@ -72,6 +76,7 @@ function updatePageLayout(updateType) {
7276
7377 // Mobile layout, so only show one or the other
7478 if ( mainContent . offsetWidth < 768 ) {
79+ // Prioritize based on the update type
7580 if ( updateType == UPDATE_TYPE_EDITOR && isEditorVisible ( ) ) {
7681 serialPage . classList . remove ( 'active' ) ;
7782 } else if ( updateType == UPDATE_TYPE_SERIAL && isSerialVisible ( ) ) {
@@ -108,13 +113,40 @@ function updatePageLayout(updateType) {
108113}
109114
110115function refitTerminal ( ) {
116+ // Custom function to replace the terminal refit function as it was a bit buggy
117+
111118 // Re-fitting the terminal requires a full re-layout of the DOM which can be tricky to time right.
112119 // see https://www.macarthur.me/posts/when-dom-updates-appear-to-be-asynchronous
113120 window . requestAnimationFrame ( ( ) => {
114121 window . requestAnimationFrame ( ( ) => {
115122 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' ;
118150 }
119151 } ) ;
120152 } ) ;
@@ -130,8 +162,7 @@ function fixViewportHeight(e) {
130162}
131163
132164// Resize the panes when the separator is moved
133- function resize ( e ) {
134- console . log ( "Resized" ) ;
165+ function resizePanels ( e ) {
135166 const w = mainContent . offsetWidth ;
136167 const gap = pageSeparator . offsetWidth ;
137168 const ratio = e . clientX / w ;
@@ -182,12 +213,12 @@ function loadPanelSettings() {
182213}
183214
184215function stopResize ( e ) {
185- window . removeEventListener ( 'mousemove' , resize , false ) ;
216+ window . removeEventListener ( 'mousemove' , resizePanels , false ) ;
186217 window . removeEventListener ( 'mouseup' , stopResize , false ) ;
187218}
188219
189220pageSeparator . addEventListener ( 'mousedown' , async function ( e ) {
190- window . addEventListener ( 'mousemove' , resize , false ) ;
221+ window . addEventListener ( 'mousemove' , resizePanels , false ) ;
191222 window . addEventListener ( 'mouseup' , stopResize , false ) ;
192223} ) ;
193224
0 commit comments