mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 07:52:24 -04:00
ensure current card centered even if it was already visible
Otherwise if a user reviews a card while keeping Browse open, the card may not be centered if it was already in view.
This commit is contained in:
parent
0b43b1f641
commit
c5e56a5fe8
1 changed files with 3 additions and 3 deletions
|
@ -129,7 +129,7 @@ class Table:
|
|||
self.clear_selection()
|
||||
if (row := self._model.get_card_row(card_id)) is not None:
|
||||
self._view.selectRow(row)
|
||||
self._scroll_to_row(row)
|
||||
self._scroll_to_row(row, scroll_even_if_visible=True)
|
||||
|
||||
# Reset
|
||||
|
||||
|
@ -451,12 +451,12 @@ class Table:
|
|||
|
||||
# Move
|
||||
|
||||
def _scroll_to_row(self, row: int) -> None:
|
||||
def _scroll_to_row(self, row: int, scroll_even_if_visible: bool = False) -> None:
|
||||
"""Scroll vertically to row."""
|
||||
top_border = self._view.rowViewportPosition(row)
|
||||
bottom_border = top_border + self._view.rowHeight(0)
|
||||
visible = top_border >= 0 and bottom_border < self._view.viewport().height()
|
||||
if not visible:
|
||||
if not visible or scroll_even_if_visible:
|
||||
horizontal = self._view.horizontalScrollBar().value()
|
||||
self._view.scrollTo(self._model.index(row, 0), self._view.PositionAtCenter)
|
||||
self._view.horizontalScrollBar().setValue(horizontal)
|
||||
|
|
Loading…
Reference in a new issue