Speed up to_row_of_unselected_note()
Skip rows between selected rows and return fetched note ids.
This commit is contained in:
parent
a592c5b3a9
commit
46ffbb936d
@ -619,8 +619,7 @@ class Browser(QMainWindow):
|
|||||||
if focus != self.form.tableView:
|
if focus != self.form.tableView:
|
||||||
return
|
return
|
||||||
|
|
||||||
nids = self.table.get_selected_note_ids()
|
nids = self.table.to_row_of_unselected_note()
|
||||||
self.table.to_row_of_unselected_note()
|
|
||||||
remove_notes(parent=self, note_ids=nids).run_in_background()
|
remove_notes(parent=self, note_ids=nids).run_in_background()
|
||||||
|
|
||||||
# legacy
|
# legacy
|
||||||
|
@ -213,24 +213,37 @@ class Table:
|
|||||||
def to_last_row(self) -> None:
|
def to_last_row(self) -> None:
|
||||||
self._move_current_to_row(self._model.len_rows() - 1)
|
self._move_current_to_row(self._model.len_rows() - 1)
|
||||||
|
|
||||||
def to_row_of_unselected_note(self) -> None:
|
def to_row_of_unselected_note(self) -> Sequence[NoteId]:
|
||||||
"""Select and set focus to a row whose note is not selected,
|
"""Select and set focus to a row whose note is not selected, trying
|
||||||
starting with the nearest row below, then above the focused row.
|
the rows below the bottomost, then above the topmost selected row.
|
||||||
If that's not possible, clear selection.
|
If that's not possible, clear selection.
|
||||||
|
Return previously selected note ids.
|
||||||
"""
|
"""
|
||||||
nids = self.get_selected_note_ids()
|
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))
|
bottom = max(r.row() for r in self._selected()) + 1
|
||||||
if nid is not None and nid not in nids:
|
for row in range(bottom, self.len()):
|
||||||
self._move_current_to_row(row)
|
index = self._model.index(row, 0)
|
||||||
return
|
if self._model.get_row(index).is_deleted:
|
||||||
for row in range(self._current().row() - 1, -1, -1):
|
continue
|
||||||
nid = self._model.get_note_id(self._model.index(row, 0))
|
if self._model.get_note_id(index) in nids:
|
||||||
if nid is not None and nid not in nids:
|
continue
|
||||||
self._move_current_to_row(row)
|
self._move_current_to_row(row)
|
||||||
return
|
return nids
|
||||||
|
|
||||||
|
top = min(r.row() for r in self._selected()) - 1
|
||||||
|
for row in range(top, -1, -1):
|
||||||
|
index = self._model.index(row, 0)
|
||||||
|
if self._model.get_row(index).is_deleted:
|
||||||
|
continue
|
||||||
|
if self._model.get_note_id(index) in nids:
|
||||||
|
continue
|
||||||
|
self._move_current_to_row(row)
|
||||||
|
return nids
|
||||||
|
|
||||||
self._reset_selection()
|
self._reset_selection()
|
||||||
self.browser.on_row_changed()
|
self.browser.on_row_changed()
|
||||||
|
return nids
|
||||||
|
|
||||||
def clear_current(self) -> None:
|
def clear_current(self) -> None:
|
||||||
self._view.selectionModel().setCurrentIndex(
|
self._view.selectionModel().setCurrentIndex(
|
||||||
|
Loading…
Reference in New Issue
Block a user