Merge pull request #1222 from RumovZ/browser-card

Change handling of browser's card parameter
This commit is contained in:
Damien Elmes 2021-06-08 09:32:43 +10:00 committed by GitHub
commit df600c094a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 21 deletions

View File

@ -80,8 +80,9 @@ class Browser(QMainWindow):
search: Optional[Tuple[Union[str, SearchNode]]] = None,
) -> None:
"""
card : try to search for its note and select it
search: set and perform search; caller must ensure validity
card -- try to select the provided card after executing "search" or
"deck:current" (if "search" was None)
search -- set and perform search; caller must ensure validity
"""
QMainWindow.__init__(self, None, Qt.Window)
@ -241,9 +242,12 @@ class Browser(QMainWindow):
if search is not None:
self.search_for_terms(*search)
self.form.searchEdit.setFocus()
elif card:
self.show_single_card(card)
if card is not None:
if search is None:
# implicitly assume 'card' is in the current deck
self._default_search(card)
self.form.searchEdit.setFocus()
self.table.select_single_card(card.id)
# Searching
######################################################################
@ -261,13 +265,11 @@ class Browser(QMainWindow):
self.form.searchEdit.addItems(self.mw.pm.profile["searchHistory"])
if search is not None:
self.search_for_terms(*search)
elif card:
self.show_single_card(card)
else:
self.search_for(
self.col.build_search_string(SearchNode(deck="current")), ""
)
self._default_search(card)
self.form.searchEdit.setFocus()
if card:
self.table.select_single_card(card.id)
# search triggered by user
@ensure_editor_saved
@ -330,17 +332,11 @@ class Browser(QMainWindow):
self.form.searchEdit.setEditText(search)
self.onSearchActivated()
def show_single_card(self, card: Card) -> None:
if card.nid:
def on_show_single_card() -> None:
self.card = card
search = self.col.build_search_string(SearchNode(nid=card.nid))
def _default_search(self, card: Optional[Card] = None) -> None:
search = self.col.build_search_string(SearchNode(deck="current"))
if card is not None:
search = gui_hooks.default_search(search, card)
self.search_for(search, "")
self.table.select_single_card(card.id)
self.editor.call_after_note_saved(on_show_single_card)
def onReset(self) -> None:
self.sidebar.refresh()

View File

@ -129,6 +129,8 @@ class Table:
self.clear_selection()
if (row := self._model.get_card_row(card_id)) is not None:
self._view.selectRow(row)
# editor may pop up and hide the row later on
QTimer.singleShot(100, lambda: self._scroll_to_row(row))
# Reset