@@ -40,28 +40,36 @@ function initResizable(treeview) {
4040 }
4141 }
4242
43- function constrainPanelWidths ( leftPanelWidth , rightPanelWidth ) {
43+ function constrainPanelWidths ( leftPanelWidth , rightPanelWidth , dragLeft ) {
4444 const contentWidth = container . width ( ) - leftPanelWidth - rightPanelWidth ;
4545 const minContentWidth = 250 ;
4646 const minPanelWidth = barWidth ;
4747 if ( contentWidth < minContentWidth ) // need to shrink panels
4848 {
4949 const deficit = minContentWidth - contentWidth ;
50- const shrinkRight = Math . min ( deficit , rightPanelWidth - minPanelWidth ) ;
51- rightPanelWidth -= shrinkRight ;
52- const remainingDeficit = deficit - shrinkRight ;
53- const shrinkLeft = Math . min ( remainingDeficit , leftPanelWidth - minPanelWidth ) ;
54- leftPanelWidth -= shrinkLeft ;
50+ if ( dragLeft ) { // dragging left handle -> try to keep right panel width
51+ const shrinkLeft = Math . min ( deficit , leftPanelWidth - minPanelWidth ) ;
52+ leftPanelWidth -= shrinkLeft ;
53+ const remainingDeficit = deficit - shrinkLeft ;
54+ const shrinkRight = Math . min ( remainingDeficit , rightPanelWidth - minPanelWidth ) ;
55+ rightPanelWidth -= shrinkRight ;
56+ } else { // dragging right handle -> try to keep left panel width
57+ const shrinkRight = Math . min ( deficit , rightPanelWidth - minPanelWidth ) ;
58+ rightPanelWidth -= shrinkRight ;
59+ const remainingDeficit = deficit - shrinkRight ;
60+ const shrinkLeft = Math . min ( remainingDeficit , leftPanelWidth - minPanelWidth ) ;
61+ leftPanelWidth -= shrinkLeft ;
62+ }
5563 } else {
5664 rightPanelWidth = pagenav . length ? Math . max ( minPanelWidth , rightPanelWidth ) : 0 ;
5765 leftPanelWidth = Math . max ( minPanelWidth , leftPanelWidth ) ;
5866 }
5967 return { leftPanelWidth, rightPanelWidth }
6068 }
6169
62- function updateWidths ( sidenavWidth , pagenavWidth )
70+ function updateWidths ( sidenavWidth , pagenavWidth , dragLeft )
6371 {
64- const widths = constrainPanelWidths ( sidenavWidth , pagenavWidth ) ;
72+ const widths = constrainPanelWidths ( sidenavWidth , pagenavWidth , dragLeft ) ;
6573 const widthStr = parseInt ( widths . leftPanelWidth ) + "px" ;
6674 content . css ( { marginLeft :widthStr } ) ;
6775 if ( fullSidebar ) {
@@ -78,18 +86,18 @@ function initResizable(treeview) {
7886 return widths ;
7987 }
8088
81- function resizeWidth ( ) {
89+ function resizeWidth ( dragLeft ) {
8290 const sidenavWidth = $ ( sidenav ) . outerWidth ( ) - barWidth ;
8391 const pagenavWidth = pagenav . length ? $ ( pagenav ) . outerWidth ( ) : 0 ;
84- const widths = updateWidths ( sidenavWidth , pagenavWidth ) ;
92+ const widths = updateWidths ( sidenavWidth , pagenavWidth , dragLeft ) ;
8593 Cookie . writeSetting ( RESIZE_COOKIE_NAME , widths . leftPanelWidth - barWidth ) ;
8694 if ( pagenav . length ) {
8795 Cookie . writeSetting ( PAGENAV_COOKIE_NAME , widths . rightPanelWidth ) ;
8896 }
8997 }
9098
9199 function restoreWidth ( sidenavWidth , pagenavWidth ) {
92- updateWidths ( sidenavWidth , pagenavWidth ) ;
100+ updateWidths ( sidenavWidth , pagenavWidth , false ) ;
93101 showHideNavBar ( ) ;
94102 }
95103
@@ -119,7 +127,7 @@ function initResizable(treeview) {
119127 contentHeight = windowHeight - headerHeight - 1 ;
120128 }
121129 content . css ( { height :contentHeight + "px" } ) ;
122- resizeWidth ( ) ;
130+ resizeWidth ( false ) ;
123131 showHideNavBar ( ) ;
124132 if ( location . hash . slice ( 1 ) ) {
125133 ( document . getElementById ( location . hash . slice ( 1 ) ) || document . body ) . scrollIntoView ( ) ;
@@ -137,7 +145,7 @@ function initResizable(treeview) {
137145 navtree = $ ( "#nav-tree" ) ;
138146 pagenav = $ ( "#page-nav" ) ;
139147 container = $ ( "#container" ) ;
140- $ ( ".side-nav-resizable" ) . resizable ( { resize : function ( e , ui ) { resizeWidth ( ) ; } } ) ;
148+ $ ( ".side-nav-resizable" ) . resizable ( { resize : function ( e , ui ) { resizeWidth ( true ) ; } } ) ;
141149 $ ( sidenav ) . resizable ( { minWidth : 0 } ) ;
142150 if ( pagenav . length ) {
143151 pagehandle = $ ( "#page-nav-resize-handle" ) ;
@@ -148,7 +156,7 @@ function initResizable(treeview) {
148156 const clientX = e . clientX || e . originalEvent . touches [ 0 ] . clientX ;
149157 let pagenavWidth = container [ 0 ] . offsetWidth - clientX + barWidth / 2 ;
150158 const sidenavWidth = sidenav . width ( ) ;
151- const widths = constrainPanelWidths ( sidenavWidth , pagenavWidth ) ;
159+ const widths = constrainPanelWidths ( sidenavWidth , pagenavWidth , false ) ;
152160 container . css ( { gridTemplateColumns :'auto ' + parseInt ( widths . rightPanelWidth ) + 'px' } ) ;
153161 pagenav . css ( { width :parseInt ( widths . rightPanelWidth - 1 ) + 'px' } ) ;
154162 content . css ( { marginLeft :parseInt ( widths . leftPanelWidth ) + 'px' } ) ;
@@ -164,7 +172,6 @@ function initResizable(treeview) {
164172 container . css ( { gridTemplateColumns :'auto' } ) ;
165173 }
166174 }
167- $ ( window ) . resize ( function ( ) { resizeHeight ( treeview ) ; } ) ;
168175 if ( treeview )
169176 {
170177 const width = parseInt ( Cookie . readSetting ( RESIZE_COOKIE_NAME , $TREEVIEW_WIDTH ) ) ;
@@ -180,6 +187,16 @@ function initResizable(treeview) {
180187 $ ( "#splitbar" ) . bind ( "dragstart" , _preventDefault ) . bind ( "selectstart" , _preventDefault ) ;
181188 }
182189 $ ( window ) . ready ( function ( ) {
190+ let lastWidth = - 1 ;
191+ let lastHeight = - 1 ;
192+ $ ( window ) . resize ( function ( ) {
193+ const newWidth = $ ( this ) . width ( ) , newHeight = $ ( this ) . height ( ) ;
194+ if ( newWidth != lastWidth || newHeight != lastHeight ) {
195+ resizeHeight ( treeview ) ;
196+ lastWidth = newWidth ;
197+ lastHeight = newHeight ;
198+ }
199+ } ) ;
183200 resizeHeight ( treeview ) ;
184201 $ ( window ) . resize ( function ( ) { resizeHeight ( treeview ) ; } ) ;
185202 content . scroll ( function ( ) {
0 commit comments