mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Switch to new row before deleting notes
The table now properly deselects deleted rows, but that takes effort and it's more convenient to have a selected row after deleting.
This commit is contained in:
parent
f54f15cd44
commit
18f0d026b5
3 changed files with 27 additions and 18 deletions
|
@ -9,13 +9,7 @@ import aqt
|
|||
import aqt.forms
|
||||
from anki._legacy import deprecated
|
||||
from anki.cards import Card, CardId
|
||||
from anki.collection import (
|
||||
Collection,
|
||||
Config,
|
||||
OpChanges,
|
||||
OpChangesWithCount,
|
||||
SearchNode,
|
||||
)
|
||||
from anki.collection import Collection, Config, OpChanges, SearchNode
|
||||
from anki.consts import *
|
||||
from anki.errors import NotFoundError
|
||||
from anki.lang import without_unicode_isolation
|
||||
|
@ -60,7 +54,6 @@ from aqt.utils import (
|
|||
saveState,
|
||||
showWarning,
|
||||
skip_if_selection_is_empty,
|
||||
tooltip,
|
||||
tr,
|
||||
)
|
||||
|
||||
|
@ -627,16 +620,8 @@ class Browser(QMainWindow):
|
|||
return
|
||||
|
||||
nids = self.table.get_selected_note_ids()
|
||||
|
||||
def after_remove(changes: OpChangesWithCount) -> None:
|
||||
tooltip(tr.browsing_cards_deleted(count=changes.count))
|
||||
# select the next card if there is one
|
||||
self.focusTo = self.editor.currentField
|
||||
self.table.to_next_row()
|
||||
|
||||
remove_notes(parent=self, note_ids=nids).success(
|
||||
after_remove
|
||||
).run_in_background()
|
||||
self.table.to_row_of_unselected_note()
|
||||
remove_notes(parent=self, note_ids=nids).run_in_background()
|
||||
|
||||
# legacy
|
||||
|
||||
|
|
|
@ -184,6 +184,11 @@ class DataModel(QAbstractTableModel):
|
|||
def get_note_ids(self, indices: List[QModelIndex]) -> Sequence[NoteId]:
|
||||
return self._state.get_note_ids(self.get_items(indices))
|
||||
|
||||
def get_note_id(self, index: QModelIndex) -> Optional[NoteId]:
|
||||
if nid_list := self._state.get_note_ids([self.get_item(index)]):
|
||||
return nid_list[0]
|
||||
return None
|
||||
|
||||
# Get row numbers from items
|
||||
|
||||
def get_item_row(self, item: ItemId) -> Optional[int]:
|
||||
|
|
|
@ -207,6 +207,25 @@ class Table:
|
|||
def to_last_row(self) -> None:
|
||||
self._move_current_to_row(self._model.len_rows() - 1)
|
||||
|
||||
def to_row_of_unselected_note(self) -> None:
|
||||
"""Select and set focus to a row whose note is not selected,
|
||||
starting with the nearest row below, then above the focused row.
|
||||
If that's not possible, clear selection.
|
||||
"""
|
||||
nids = self.get_selected_note_ids()
|
||||
for row in range(self._current().row(), self.len()):
|
||||
nid = self._model.get_note_id(self._model.index(row, 0))
|
||||
if nid is not None and nid not in nids:
|
||||
self._move_current_to_row(row)
|
||||
return
|
||||
for row in range(self._current().row() - 1, -1, -1):
|
||||
nid = self._model.get_note_id(self._model.index(row, 0))
|
||||
if nid is not None and nid not in nids:
|
||||
self._move_current_to_row(row)
|
||||
return
|
||||
self.clear_selection()
|
||||
self.clear_current()
|
||||
|
||||
def clear_current(self) -> None:
|
||||
self._view.selectionModel().setCurrentIndex(
|
||||
QModelIndex(), QItemSelectionModel.NoUpdate
|
||||
|
|
Loading…
Reference in a new issue