mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
Turn update_search into its own method
This commit is contained in:
parent
450e85d36d
commit
9e44b2be7f
1 changed files with 12 additions and 14 deletions
|
@ -774,25 +774,23 @@ class Browser(QMainWindow):
|
||||||
prompt = self.form.searchEdit.lineEdit().text()
|
prompt = self.form.searchEdit.lineEdit().text()
|
||||||
|
|
||||||
# convert guide text before we save history
|
# convert guide text before we save history
|
||||||
if prompt == self._searchPrompt:
|
txt = "deck:current " if prompt == self._searchPrompt else prompt
|
||||||
txt = "deck:current "
|
self.update_history(txt)
|
||||||
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
|
|
||||||
|
|
||||||
# keep track of search string so that we reuse identical search when
|
# keep track of search string so that we reuse identical search when
|
||||||
# refreshing, rather than whatever is currently in the search field
|
# refreshing, rather than whatever is currently in the search field
|
||||||
self.search_for(txt)
|
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:
|
def search_for(self, search: str, prompt: Optional[str] = None) -> None:
|
||||||
self._lastSearchTxt = search
|
self._lastSearchTxt = search
|
||||||
self.form.searchEdit.lineEdit().setText(prompt or search)
|
self.form.searchEdit.lineEdit().setText(prompt or search)
|
||||||
|
|
Loading…
Reference in a new issue