@@ -766,10 +766,8 @@ def setupSearch(self):
766
766
self .form .searchEdit .addItems (
767
767
[self ._searchPrompt ] + self .mw .pm .profile ["searchHistory" ]
768
768
)
769
- self ._lastSearchTxt = "is:current"
770
- self .search ()
769
+ self .search_for ("is:current" , self ._searchPrompt )
771
770
# then replace text for easily showing the deck
772
- self .form .searchEdit .lineEdit ().setText (self ._searchPrompt )
773
771
self .form .searchEdit .lineEdit ().selectAll ()
774
772
self .form .searchEdit .setFocus ()
775
773
@@ -778,26 +776,30 @@ def onSearchActivated(self):
778
776
self .editor .saveNow (self ._onSearchActivated )
779
777
780
778
def _onSearchActivated (self ):
779
+ # grab search text and normalize
780
+ prompt = self .form .searchEdit .lineEdit ().text ()
781
+
781
782
# convert guide text before we save history
782
- if self . form . searchEdit . lineEdit (). text () == self ._searchPrompt :
783
- self .form . searchEdit . lineEdit (). setText ( "deck:current " )
783
+ txt = "deck:current " if prompt == self ._searchPrompt else prompt
784
+ self .update_history ( txt )
784
785
785
- # grab search text and normalize
786
- txt = self .form .searchEdit .lineEdit ().text ()
786
+ # keep track of search string so that we reuse identical search when
787
+ # refreshing, rather than whatever is currently in the search field
788
+ self .search_for (txt )
787
789
788
- # update history
790
+ def update_history ( self , search : str ) -> None :
789
791
sh = self .mw .pm .profile ["searchHistory" ]
790
- if txt in sh :
791
- sh .remove (txt )
792
- sh .insert (0 , txt )
792
+ if search in sh :
793
+ sh .remove (search )
794
+ sh .insert (0 , search )
793
795
sh = sh [:30 ]
794
796
self .form .searchEdit .clear ()
795
797
self .form .searchEdit .addItems (sh )
796
798
self .mw .pm .profile ["searchHistory" ] = sh
797
799
798
- # keep track of search string so that we reuse identical search when
799
- # refreshing, rather than whatever is currently in the search field
800
- self ._lastSearchTxt = txt
800
+ def search_for ( self , search : str , prompt : Optional [ str ] = None ) -> None :
801
+ self . _lastSearchTxt = search
802
+ self .form . searchEdit . lineEdit (). setText ( prompt or search )
801
803
self .search ()
802
804
803
805
# search triggered programmatically. caller must have saved note first.
@@ -1787,13 +1789,13 @@ def selectNotes(self):
1787
1789
1788
1790
def _selectNotes (self ):
1789
1791
nids = self .selectedNotes ()
1790
- # bypass search history
1791
- self ._lastSearchTxt = "nid:" + "," .join ([str (x ) for x in nids ])
1792
- self .form .searchEdit .lineEdit ().setText (self ._lastSearchTxt )
1793
1792
# clear the selection so we don't waste energy preserving it
1794
1793
tv = self .form .tableView
1795
1794
tv .selectionModel ().clear ()
1796
- self .search ()
1795
+
1796
+ search = "nid:" + "," .join ([str (x ) for x in nids ])
1797
+ self .search_for (search )
1798
+
1797
1799
tv .selectAll ()
1798
1800
1799
1801
def invertSelection (self ):
@@ -2016,10 +2018,7 @@ def _onTagDupes(self, res):
2016
2018
tooltip (_ ("Notes tagged." ))
2017
2019
2018
2020
def dupeLinkClicked (self , link ):
2019
- self .form .searchEdit .lineEdit ().setText (link )
2020
- # manually, because we've already saved
2021
- self ._lastSearchTxt = link
2022
- self .search ()
2021
+ self .search_for (link )
2023
2022
self .onNote ()
2024
2023
2025
2024
# Jumping
0 commit comments