From 9e44b2be7fe6c9939ed64c7beef85862b27b3a9b Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Mon, 19 Oct 2020 21:07:29 +0200 Subject: [PATCH] Turn update_search into its own method --- qt/aqt/browser.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index ce65bba69..5381e6fd7 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -774,25 +774,23 @@ class Browser(QMainWindow): prompt = self.form.searchEdit.lineEdit().text() # convert guide text before we save history - if prompt == self._searchPrompt: - txt = "deck:current " - else: - txt = prompt - - # update history - sh = self.mw.pm.profile["searchHistory"] - if txt in sh: - sh.remove(txt) - sh.insert(0, txt) - sh = sh[:30] - self.form.searchEdit.clear() - self.form.searchEdit.addItems(sh) - self.mw.pm.profile["searchHistory"] = sh + txt = "deck:current " if prompt == self._searchPrompt else prompt + self.update_history(txt) # keep track of search string so that we reuse identical search when # refreshing, rather than whatever is currently in the search field self.search_for(txt) + def update_history(self, search: str) -> None: + sh = self.mw.pm.profile["searchHistory"] + if search in sh: + sh.remove(search) + sh.insert(0, search) + sh = sh[:30] + self.form.searchEdit.clear() + self.form.searchEdit.addItems(sh) + self.mw.pm.profile["searchHistory"] = sh + def search_for(self, search: str, prompt: Optional[str] = None) -> None: self._lastSearchTxt = search self.form.searchEdit.lineEdit().setText(prompt or search)