mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 00:36:38 -04:00
ensure we focus & select when focusedCard is set - fixes deletions
This commit is contained in:
parent
f06d27220c
commit
971a69fdbc
1 changed files with 17 additions and 14 deletions
|
@ -149,27 +149,30 @@ class DataModel(QAbstractTableModel):
|
||||||
sm.clear()
|
sm.clear()
|
||||||
# restore selection
|
# restore selection
|
||||||
items = QItemSelection()
|
items = QItemSelection()
|
||||||
focused = None
|
|
||||||
first = None
|
|
||||||
count = 0
|
count = 0
|
||||||
|
firstIdx = None
|
||||||
|
focusedIdx = None
|
||||||
for row, id in enumerate(self.cards):
|
for row, id in enumerate(self.cards):
|
||||||
|
# if the id matches the focused card, note the index
|
||||||
|
if self.focusedCard == id:
|
||||||
|
focusedIdx = self.index(row, 0)
|
||||||
|
items.select(focusedIdx, focusedIdx)
|
||||||
|
self.focusedCard = None
|
||||||
|
# if the card was previously selected, select again
|
||||||
if id in self.selectedCards:
|
if id in self.selectedCards:
|
||||||
count += 1
|
count += 1
|
||||||
idx = self.index(row, 0)
|
idx = self.index(row, 0)
|
||||||
items.select(idx, idx)
|
items.select(idx, idx)
|
||||||
if not first:
|
# note down the first card of the selection, in case we don't
|
||||||
first = idx
|
# have a focused card
|
||||||
# note idx of focused card
|
if not firstIdx:
|
||||||
if self.focusedCard:
|
firstIdx = idx
|
||||||
focused = idx
|
# focus previously focused or first in selection
|
||||||
# avoid further comparisons
|
idx = focusedIdx or firstIdx
|
||||||
self.focusedCard = None
|
|
||||||
# and focus previously focused or first in selection
|
|
||||||
focus = focused or first
|
|
||||||
tv = self.browser.form.tableView
|
tv = self.browser.form.tableView
|
||||||
if focus:
|
if idx:
|
||||||
tv.selectRow(focus.row())
|
tv.selectRow(idx.row())
|
||||||
tv.scrollTo(focus, tv.PositionAtCenter)
|
tv.scrollTo(idx, tv.PositionAtCenter)
|
||||||
if count < 500:
|
if count < 500:
|
||||||
# discard large selections; they're too slow
|
# discard large selections; they're too slow
|
||||||
sm.select(items, QItemSelectionModel.SelectCurrent |
|
sm.select(items, QItemSelectionModel.SelectCurrent |
|
||||||
|
|
Loading…
Reference in a new issue