99using System . Net ;
1010using System . Reflection ;
1111using System . Reflection . Emit ;
12+ using System . Runtime . CompilerServices ;
1213using System . Text ;
1314using System . Text . RegularExpressions ;
15+ using System . Threading ;
1416using System . Windows . Controls ;
1517using System . Windows . Documents ;
1618using System . Windows . Forms ;
@@ -67,6 +69,12 @@ partial class FrmNavigateTo : Form
6769
6870 private Glob glob { get ; set ; }
6971
72+ const int lastKeyPressTimerInterval = 250 ;
73+
74+ private System . Timers . Timer lastKeyPressTimer ;
75+
76+ private long lastKeypressTicks ;
77+
7078 /// <summary>
7179 /// function used to filter filenames when not using fuzzy matchin
7280 /// </summary>
@@ -85,8 +93,6 @@ partial class FrmNavigateTo : Form
8593
8694 private bool tooManyResultsToHighlight { get ; set ; } = false ;
8795
88- private bool lastCharCannotChangeResults { get ; set ; } = false ;
89-
9096 public FrmNavigateTo ( IScintillaGateway editor , INotepadPPGateway notepad )
9197 {
9298 this . editor = editor ;
@@ -102,6 +108,11 @@ public FrmNavigateTo(IScintillaGateway editor, INotepadPPGateway notepad)
102108 //backgroundWorker.WorkerSupportsCancellation = true;
103109 //backgroundWorker.DoWork += BackgroundWorker_DoWork;
104110 glob = new Glob ( ) ;
111+ lastKeyPressTimer = new System . Timers . Timer ( ) ;
112+ lastKeyPressTimer . AutoReset = false ;
113+ lastKeyPressTimer . Interval = lastKeyPressTimerInterval ;
114+ lastKeyPressTimer . Elapsed += LastKeyPressTimer_Elapsed ;
115+ lastKeypressTicks = 0 ;
105116 nonFuzzyFilterFunc = null ;
106117 InitializeComponent ( ) ;
107118 ReloadFileList ( ) ;
@@ -518,7 +529,6 @@ private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
518529
519530 private void SearchComboBoxKeyDown ( object sender , KeyEventArgs e )
520531 {
521- lastCharCannotChangeResults = false ;
522532 switch ( e . KeyCode )
523533 {
524534 case Keys . Back :
@@ -574,12 +584,6 @@ private void SearchComboBoxKeyDown(object sender, KeyEventArgs e)
574584 e . Handled = true ;
575585 e . SuppressKeyPress = true ;
576586 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 ;
583587 }
584588 }
585589
@@ -656,23 +660,33 @@ private bool NavigateGridDown(bool isShiftPressed)
656660
657661 private void SearchComboBoxTextChanged ( object sender , EventArgs e )
658662 {
659- if ( lastCharCannotChangeResults )
660- return ;
661- int textLength = searchComboBox . Text . Length ;
662- bool emptyText = string . IsNullOrWhiteSpace ( searchComboBox . Text ) ;
663- int minLength = FrmSettings . Settings . GetIntSetting ( Settings . minTypeCharLimit ) ;
663+ lastKeyPressTimer . Start ( ) ;
664+ lastKeypressTicks = System . DateTime . UtcNow . Ticks ;
665+ }
664666
665- if ( emptyText )
666- ReloadFileList ( ) ;
667- if ( textLength > minLength || emptyText )
668- {
669- FilterDataGrid ( searchComboBox . Text ) ;
670- }
667+ private void LastKeyPressTimer_Elapsed ( object sender , EventArgs e )
668+ {
669+ Invoke ( new Action ( ( ) =>
670+ {
671+ // allow keypresses more recent than the interval, because we can't rely on precise timing of this event firing
672+ if ( System . DateTime . UtcNow . Ticks <= lastKeypressTicks + System . TimeSpan . TicksPerMillisecond * lastKeyPressTimerInterval / 10 )
673+ return ;
674+ int textLength = searchComboBox . Text . Length ;
675+ bool emptyText = string . IsNullOrWhiteSpace ( searchComboBox . Text ) ;
676+ int minLength = FrmSettings . Settings . GetIntSetting ( Settings . minTypeCharLimit ) ;
677+
678+ if ( emptyText )
679+ ReloadFileList ( ) ;
680+ if ( textLength > minLength || emptyText )
681+ {
682+ FilterDataGrid ( searchComboBox . Text ) ;
683+ }
671684
672- if ( FrmSettings . Settings . GetBoolSetting ( Settings . selectFirstRowOnFilter ) )
673- {
674- SelectFirstRow ( ) ;
675- }
685+ if ( FrmSettings . Settings . GetBoolSetting ( Settings . selectFirstRowOnFilter ) )
686+ {
687+ SelectFirstRow ( ) ;
688+ }
689+ } ) ) ;
676690 }
677691
678692 private void SelectFirstRow ( )
0 commit comments