@@ -83,6 +83,10 @@ partial class FrmNavigateTo : Form
8383 /// </summary>
8484 public int minDirTreeSizeToWarn { get ; set ; } = 5000 ;
8585
86+ private bool tooManyResultsToHighlight { get ; set ; } = false ;
87+
88+ private bool lastCharCannotChangeResults { get ; set ; } = false ;
89+
8690 public FrmNavigateTo ( IScintillaGateway editor , INotepadPPGateway notepad )
8791 {
8892 this . editor = editor ;
@@ -180,6 +184,7 @@ public void FilterDataGrid(string filter)
180184 dataGridFileList . Rows . Clear ( ) ;
181185 if ( emptyFilter )
182186 {
187+ tooManyResultsToHighlight = FileList . Count >= FrmSettings . Settings . GetIntSetting ( Settings . maxResultsHighlightingEnabled ) ;
183188 FileList . ForEach ( file =>
184189 {
185190 DataGridViewRow newRow = new DataGridViewRow ( ) ;
@@ -198,6 +203,7 @@ public void FilterDataGrid(string filter)
198203 //backgroundWorker.CancelAsync(); // cancel the previous filtering
199204 //backgroundWorker.RunWorkerAsync(); // filter the file list (run BackgroundWorker_DoWork)
200205 FilterEverything ( filter ) ;
206+ tooManyResultsToHighlight = FilteredFileList . Count >= FrmSettings . Settings . GetIntSetting ( Settings . maxResultsHighlightingEnabled ) ;
201207
202208 FilteredFileList . ForEach ( file =>
203209 {
@@ -251,7 +257,7 @@ public void FilterEverything(string filter)//BackgroundWorker_DoWork(object send
251257
252258 if ( FrmSettings . Settings . GetBoolSetting ( Settings . searchInCurrentFolder ) )
253259 {
254- FilterCurrentDirectory ( nonFuzzyFilterFunc /*, e*/ ) ;
260+ FilterCurrentDirectory ( ) ;
255261 }
256262
257263 if ( FrmSettings . Settings . GetBoolSetting ( Settings . searchMenuCommands ) )
@@ -383,11 +389,12 @@ string[] SearchCurrentDirectory(DirectorySearchLevel searchLevel, long nextTimeT
383389 return filesInCurrentDirectory ?? new string [ 0 ] ;
384390 }
385391
386- void FilterCurrentDirectory ( Func < string , bool > filterFunc )
392+ void FilterCurrentDirectory ( )
387393 {
388394 string currentDirectory = notepad . GetCurrentFileDirectory ( ) ;
389395 if ( string . IsNullOrWhiteSpace ( currentDirectory ) )
390396 return ;
397+ Func < string , bool > filterFunc = Glob . CacheGlobFuncResultsForTopDirectory ( currentDirectory , glob . globFunctions ) ;
391398 bool userWantsSearchSubdirs = FrmSettings . Settings . GetBoolSetting ( Settings . searchInSubDirs ) ;
392399 DirectorySearchLevel searchLevel = userWantsSearchSubdirs
393400 ? DirectorySearchLevel . RecurseSubdirs
@@ -511,8 +518,34 @@ private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
511518
512519 private void SearchComboBoxKeyDown ( object sender , KeyEventArgs e )
513520 {
521+ lastCharCannotChangeResults = false ;
514522 switch ( e . KeyCode )
515523 {
524+ case Keys . Back :
525+ if ( ! e . Control )
526+ return ;
527+ // Ctrl+Backspace: delete the word (sequence of non-whitespace, non-punctuation chars)
528+ // ending at the current cursor position.
529+ var text = searchComboBox . Text ;
530+ int currentWordEnd = searchComboBox . SelectionStart ;
531+ int currentWordStart = currentWordEnd - 1 ;
532+ for ( ; currentWordStart >= 0 ; currentWordStart -- )
533+ {
534+ char c = text [ currentWordStart ] ;
535+ if ( Char . IsPunctuation ( c ) || Char . IsWhiteSpace ( c ) )
536+ break ;
537+ }
538+ if ( currentWordStart < currentWordEnd - 1 )
539+ currentWordStart ++ ;
540+ string textWithoutCurrentWord = currentWordStart > 0 ? text . Substring ( 0 , currentWordStart ) : "" ;
541+ textWithoutCurrentWord += currentWordEnd < text . Length ? text . Substring ( currentWordEnd ) : "" ;
542+ searchComboBox . Text = textWithoutCurrentWord ;
543+ searchComboBox . SelectionStart = currentWordStart ;
544+ searchComboBox . SelectionLength = 0 ;
545+ e . SuppressKeyPress = true ;
546+ e . Handled = true ;
547+ break ;
548+
516549 case Keys . Down :
517550 e . Handled = NavigateGridDown ( e . Shift ) ;
518551 break ;
@@ -541,6 +574,12 @@ private void SearchComboBoxKeyDown(object sender, KeyEventArgs e)
541574 e . Handled = true ;
542575 e . SuppressKeyPress = true ;
543576 break ;
577+
578+ case Keys . Space :
579+ // adding space can't change the results
580+ // unless the space is part of a character class in a glob (e.g. "[ ]" matches literal whitespace)
581+ lastCharCannotChangeResults = searchComboBox . Text . IndexOf ( '[' ) == - 1 ;
582+ break ;
544583 }
545584 }
546585
@@ -617,6 +656,8 @@ private bool NavigateGridDown(bool isShiftPressed)
617656
618657 private void SearchComboBoxTextChanged ( object sender , EventArgs e )
619658 {
659+ if ( lastCharCannotChangeResults )
660+ return ;
620661 int textLength = searchComboBox . Text . Length ;
621662 bool emptyText = string . IsNullOrWhiteSpace ( searchComboBox . Text ) ;
622663 int minLength = FrmSettings . Settings . GetIntSetting ( Settings . minTypeCharLimit ) ;
@@ -716,8 +757,10 @@ private void dataGridFileList_Resize(object sender, EventArgs e)
716757
717758 private void dataGridFileList_CellPainting ( object sender , DataGridViewCellPaintingEventArgs e )
718759 {
719- if ( e . Value == null ) return ;
720- if ( searchComboBox . Text . Length == 0 ) return ;
760+ if ( e . Value == null
761+ || searchComboBox . Text . Length == 0
762+ || tooManyResultsToHighlight )
763+ return ;
721764
722765 if ( e . RowIndex > - 1 && e . ColumnIndex > - 1 )
723766 {
0 commit comments