From 0c5f22f4ae7be0b1e5ffcb1d5a8dddd9f73930f0 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 11 Apr 2020 15:54:52 +1000 Subject: [PATCH] avoid adjusting position if selected row is visible https://anki.tenderapp.com/discussions/beta-testing/1868-anki-2124-beta#comment_48227037 --- qt/aqt/browser.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index b69ef465b..83b02d733 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -255,12 +255,17 @@ class DataModel(QAbstractTableModel): idx = focusedIdx or firstIdx tv = self.browser.form.tableView if idx: - tv.selectRow(idx.row()) + row = idx.row() + pos = tv.rowViewportPosition(row) + visible = pos >= 0 and pos < tv.viewport().height() + tv.selectRow(row) + # we save and then restore the horizontal scroll position because # scrollTo() also scrolls horizontally which is confusing - h = tv.horizontalScrollBar().value() - tv.scrollTo(idx, tv.PositionAtCenter) - tv.horizontalScrollBar().setValue(h) + if not visible: + h = tv.horizontalScrollBar().value() + tv.scrollTo(idx, tv.PositionAtCenter) + tv.horizontalScrollBar().setValue(h) if count < 500: # discard large selections; they're too slow sm.select(