mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
put selection in a sensible place after deleting several cards
If the last selection was at the top, the new selection will be right above the last-selected item; otherwise, it will be right below it.
This commit is contained in:
parent
625d7d5a82
commit
b19a1707fb
1 changed files with 17 additions and 3 deletions
|
@ -1109,12 +1109,26 @@ where id in %s""" % ids2str(sf))
|
|||
return
|
||||
self.mw.checkpoint(_("Delete Notes"))
|
||||
self.model.beginReset()
|
||||
oldRow = self.form.tableView.selectionModel().currentIndex().row()
|
||||
# figure out where to place the cursor after the deletion
|
||||
curRow = self.form.tableView.selectionModel().currentIndex().row()
|
||||
selectedRows = [i.row() for i in
|
||||
self.form.tableView.selectionModel().selectedRows()]
|
||||
if min(selectedRows) < curRow < max(selectedRows):
|
||||
# last selection in middle; place one below last selected item
|
||||
move = sum(1 for i in selectedRows if i > curRow)
|
||||
newRow = curRow - move
|
||||
elif max(selectedRows) <= curRow:
|
||||
# last selection at bottom; place one below bottommost selection
|
||||
newRow = max(selectedRows) - len(nids) + 1
|
||||
else:
|
||||
# last selection at top; place one above topmost selection
|
||||
newRow = min(selectedRows) - 1
|
||||
self.col.remNotes(nids)
|
||||
self.onSearch(reset=False)
|
||||
if len(self.model.cards):
|
||||
new = min(oldRow, len(self.model.cards) - 1)
|
||||
self.model.focusedCard = self.model.cards[new]
|
||||
newRow = min(newRow, len(self.model.cards) - 1)
|
||||
newRow = max(newRow, 0)
|
||||
self.model.focusedCard = self.model.cards[newRow]
|
||||
self.model.endReset()
|
||||
self.mw.requireReset()
|
||||
tooltip(_("%s deleted.") % (ngettext("%d note", "%d notes", len(nids)) % len(nids)))
|
||||
|
|
Loading…
Reference in a new issue