diff --git a/negpy/desktop/view/sidebar/files.py b/negpy/desktop/view/sidebar/files.py index d056b5a7..9abd26c2 100644 --- a/negpy/desktop/view/sidebar/files.py +++ b/negpy/desktop/view/sidebar/files.py @@ -549,6 +549,9 @@ def _init_ui(self) -> None: layout.addWidget(self.library_section) layout.addWidget(self.frames_section) + # Absorbs the surplus when every section is collapsed — otherwise Qt spreads it + # into the gaps between the rows above. Stretch 0 leaves an open section its share. + layout.addStretch(0) self._rebalance_sections() # Applied after list_view exists — the filter prunes selection against the view. diff --git a/tests/test_session_panel.py b/tests/test_session_panel.py index b067c590..c9187087 100644 --- a/tests/test_session_panel.py +++ b/tests/test_session_panel.py @@ -71,6 +71,19 @@ def test_a_collapsed_section_keeps_only_its_header(panel): assert browser.layout().stretch(browser.layout().indexOf(browser.frames_section)) > 0 +def test_collapsing_both_sections_keeps_the_panel_top_aligned(panel, qapp): + """With nothing expanded the leftover height must not spread into the gaps (#754).""" + browser = panel.file_browser + browser.library_section.toggle_button.setChecked(False) + browser.frames_section.toggle_button.setChecked(False) + + browser.resize(300, 900) + browser.show() + qapp.processEvents() + + assert browser.frames_section.y() < 200 # ~115 stacked, ~707 spread + + def test_expanding_a_section_gives_it_back_a_share(panel): browser = panel.file_browser browser.frames_section.toggle_button.setChecked(False)