Revert "[PDFSidebarResizer] Refactor the clamping in _updateWidth"
				
					
				
			This reverts commit 9e4552d7920fcba13b3d74e1e180fc49180f4436 for causing the sidebar to become too narrow when the entire viewer is resized. **Steps to reproduce:** 1. Load the viewer. 2. Open the sidebar. 3. Resize the sidebar, making it wider. 4. Resize the entire viewer, i.e. the browser window, making it *narrower* than 400 pixels. **Expected result:** The sidebar width is clamped at 200 pixels. **Actual result:** The sidebar becomes too narrow. The cause of this bug is, in hindsight, quite obvious since the `clamp` helper function implicitly assumes that the `min`/`max` arguments are correctly sorted. At viewer widths *below* 400 pixels, that assumption is broken which explains the bug.
This commit is contained in:
		
							parent
							
								
									e51e9d1f33
								
							
						
					
					
						commit
						2594f0c738
					
				| @ -13,7 +13,7 @@ | |||||||
|  * limitations under the License. |  * limitations under the License. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| import { clamp, NullL10n } from "./ui_utils.js"; | import { NullL10n } from "./ui_utils.js"; | ||||||
| 
 | 
 | ||||||
| const SIDEBAR_WIDTH_VAR = "--sidebar-width"; | const SIDEBAR_WIDTH_VAR = "--sidebar-width"; | ||||||
| const SIDEBAR_MIN_WIDTH = 200; // pixels
 | const SIDEBAR_MIN_WIDTH = 200; // pixels
 | ||||||
| @ -88,17 +88,19 @@ class PDFSidebarResizer { | |||||||
|     } |     } | ||||||
|     // Prevent the sidebar from becoming too narrow, or from occupying more
 |     // Prevent the sidebar from becoming too narrow, or from occupying more
 | ||||||
|     // than half of the available viewer width.
 |     // than half of the available viewer width.
 | ||||||
|     const newWidth = clamp( |     const maxWidth = Math.floor(this.outerContainerWidth / 2); | ||||||
|       width, |     if (width > maxWidth) { | ||||||
|       SIDEBAR_MIN_WIDTH, |       width = maxWidth; | ||||||
|       Math.floor(this.outerContainerWidth / 2) |     } | ||||||
|     ); |     if (width < SIDEBAR_MIN_WIDTH) { | ||||||
|  |       width = SIDEBAR_MIN_WIDTH; | ||||||
|  |     } | ||||||
|     // Only update the UI when the sidebar width did in fact change.
 |     // Only update the UI when the sidebar width did in fact change.
 | ||||||
|     if (newWidth === this._width) { |     if (width === this._width) { | ||||||
|       return false; |       return false; | ||||||
|     } |     } | ||||||
|     this._width = newWidth; |     this._width = width; | ||||||
|     this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${newWidth}px`); |     this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`); | ||||||
|     return true; |     return true; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1006,7 +1006,6 @@ export { | |||||||
|   SpreadMode, |   SpreadMode, | ||||||
|   NullL10n, |   NullL10n, | ||||||
|   EventBus, |   EventBus, | ||||||
|   clamp, |  | ||||||
|   ProgressBar, |   ProgressBar, | ||||||
|   getPDFFileNameFromURL, |   getPDFFileNameFromURL, | ||||||
|   noContextMenuHandler, |   noContextMenuHandler, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user