@@ -101,12 +101,69 @@ public FrmNavigateTo(IScintillaGateway editor, INotepadPPGateway notepad)
101101 lastKeyPressTimer . Tick += OnSearchTimerTick ;
102102 nonFuzzyFilterFunc = null ;
103103 InitializeComponent ( ) ;
104+ LoadSearchHistory ( ) ;
104105 ReloadFileList ( ) ;
105106 this . notepad . ReloadMenuItems ( ) ;
106107 FormStyle . ApplyStyle ( this , true , notepad . IsDarkModeEnabled ( ) ) ;
107108 FilterDataGrid ( "" ) ;
108109 }
109110
111+ private void LoadSearchHistory ( )
112+ {
113+ try
114+ {
115+ string hist = FrmSettings . Settings . GetSetting ( Settings . searchHistory ) ;
116+ if ( ! string . IsNullOrEmpty ( hist ) )
117+ {
118+ // items are stored as a pipe-separated list
119+ var items = hist . Split ( new [ ] { '|' } , StringSplitOptions . RemoveEmptyEntries ) ;
120+ // insert in order so most recent is first
121+ foreach ( var it in items )
122+ {
123+ if ( ! searchComboBox . Items . Contains ( it ) )
124+ searchComboBox . Items . Add ( it ) ;
125+ }
126+ }
127+ }
128+ catch ( Exception ex )
129+ {
130+ MessageBox . Show ( ex . ToString ( ) ,
131+ @"Could not load search history" ,
132+ MessageBoxButtons . OK ,
133+ MessageBoxIcon . Error ) ;
134+ }
135+ }
136+
137+ public void SaveSearchHistory ( )
138+ {
139+ try
140+ {
141+ // store up to 20 entries to keep INI small
142+ int max = 20 ;
143+ var list = new List < string > ( ) ;
144+ foreach ( var o in searchComboBox . Items )
145+ {
146+ if ( o == null ) continue ;
147+ string s = o . ToString ( ) ;
148+ if ( string . IsNullOrWhiteSpace ( s ) ) continue ;
149+ if ( ! list . Contains ( s ) ) list . Add ( s ) ;
150+ if ( list . Count >= max ) break ;
151+ }
152+ // serialize as pipe-separated
153+ string serial = string . Join ( "|" , list ) ;
154+ FrmSettings . Settings . SetSetting ( Settings . searchHistory , serial ) ;
155+ FrmSettings . Settings . SetIntSetting ( Settings . searchHistoryLength , serial . Length ) ;
156+ }
157+ catch ( Exception ex )
158+ {
159+ MessageBox . Show ( ex . ToString ( ) ,
160+ @"Could not save search history" ,
161+ MessageBoxButtons . OK ,
162+ MessageBoxIcon . Error ) ;
163+ }
164+ }
165+
166+
110167 /// <summary>
111168 /// reload the list of files that are currently open in Notepad++
112169 /// </summary>
@@ -710,11 +767,19 @@ private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
710767
711768 private void SwitchToFile ( string path , bool isTab = true )
712769 {
713- notepad . SwitchToFile ( path , isTab ) ;
714- HideWindow ( ! FrmSettings . Settings . GetBoolSetting ( Settings . keepDlgOpen ) ) ;
715770 string fileName = Path . GetFileName ( notepad . GetCurrentFilePath ( ) ) ;
716771 searchComboBox . Items . Remove ( fileName ) ;
717772 searchComboBox . Items . Insert ( 0 , fileName ) ;
773+ string currentSearchString = searchComboBox . Text ;
774+ // save also search string
775+ if ( ! String . IsNullOrEmpty ( currentSearchString ) )
776+ {
777+ searchComboBox . Items . Remove ( currentSearchString ) ;
778+ searchComboBox . Items . Insert ( 0 , currentSearchString ) ;
779+ }
780+
781+ notepad . SwitchToFile ( path , isTab ) ;
782+ HideWindow ( ! FrmSettings . Settings . GetBoolSetting ( Settings . keepDlgOpen ) ) ;
718783 }
719784
720785 private void HideWindow ( bool disabled = true )
0 commit comments