diff --git a/app/playlists.py b/app/playlists.py index 5c72ab8..6b32213 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -5,9 +5,10 @@ from typing import Any, Callable, cast, Optional, TYPE_CHECKING from PyQt6.QtCore import ( QAbstractItemModel, QEvent, + QItemSelection, QModelIndex, QObject, - QItemSelection, + QPoint, QSize, Qt, QTimer, @@ -838,12 +839,28 @@ class PlaylistTab(QTableView): log.debug(f"get_selected_rows() returned: {result=}") return result - def hide_played_sections(self) -> None: + def get_top_visible_row(self) -> int: """ - Scroll played sections off screen + Get the viewport of the table view """ - self.scroll_to_top(self.get_base_model().active_section_header()) + index = self.indexAt(QPoint(0, 0)) + + if index.isValid(): + return index.row() + else: + # If no index is found, it means the table might be empty or scrolled beyond content + return -1 + + def hide_played_sections(self) -> None: + """ + Scroll played sections off screen, but only if current top row is above + the active header + """ + + active_header_row = self.get_base_model().active_section_header() + if self.get_top_visible_row() < active_header_row: + self.scroll_to_top(active_header_row) def _import_from_audacity(self, row_number: int) -> None: """