|
9 | 9 | using System.Net; |
10 | 10 | using System.Reflection; |
11 | 11 | using System.Reflection.Emit; |
| 12 | +using System.Runtime.CompilerServices; |
12 | 13 | using System.Text; |
13 | 14 | using System.Text.RegularExpressions; |
| 15 | +using System.Threading; |
14 | 16 | using System.Windows.Controls; |
15 | 17 | using System.Windows.Documents; |
16 | 18 | using System.Windows.Forms; |
@@ -67,6 +69,12 @@ partial class FrmNavigateTo : Form |
67 | 69 |
|
68 | 70 | private Glob glob { get; set; } |
69 | 71 |
|
| 72 | + const int lastKeyPressTimerInterval = 250; |
| 73 | + |
| 74 | + private System.Timers.Timer lastKeyPressTimer; |
| 75 | + |
| 76 | + private long lastKeypressTicks; |
| 77 | + |
70 | 78 | /// <summary> |
71 | 79 | /// function used to filter filenames when not using fuzzy matchin |
72 | 80 | /// </summary> |
@@ -102,6 +110,11 @@ public FrmNavigateTo(IScintillaGateway editor, INotepadPPGateway notepad) |
102 | 110 | //backgroundWorker.WorkerSupportsCancellation = true; |
103 | 111 | //backgroundWorker.DoWork += BackgroundWorker_DoWork; |
104 | 112 | glob = new Glob(); |
| 113 | + lastKeyPressTimer = new System.Timers.Timer(); |
| 114 | + lastKeyPressTimer.AutoReset = false; |
| 115 | + lastKeyPressTimer.Interval = lastKeyPressTimerInterval; |
| 116 | + lastKeyPressTimer.Elapsed += LastKeyPressTimer_Elapsed; |
| 117 | + lastKeypressTicks = 0; |
105 | 118 | nonFuzzyFilterFunc = null; |
106 | 119 | InitializeComponent(); |
107 | 120 | ReloadFileList(); |
@@ -576,9 +589,11 @@ private void SearchComboBoxKeyDown(object sender, KeyEventArgs e) |
576 | 589 | break; |
577 | 590 |
|
578 | 591 | 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; |
| 592 | + // adding space can't change the results unless: |
| 593 | + // - the space is part of a character class in a glob (e.g. "[ ]" matches literal whitespace) |
| 594 | + // - the space would push the number of chars in the search box over the min char limit |
| 595 | + int minLength = FrmSettings.Settings.GetIntSetting(Settings.minTypeCharLimit); |
| 596 | + lastCharCannotChangeResults = searchComboBox.Text.Length != minLength && searchComboBox.Text.IndexOf('[') == -1; |
582 | 597 | break; |
583 | 598 | } |
584 | 599 | } |
@@ -658,21 +673,33 @@ private void SearchComboBoxTextChanged(object sender, EventArgs e) |
658 | 673 | { |
659 | 674 | if (lastCharCannotChangeResults) |
660 | 675 | return; |
661 | | - int textLength = searchComboBox.Text.Length; |
662 | | - bool emptyText = string.IsNullOrWhiteSpace(searchComboBox.Text); |
663 | | - int minLength = FrmSettings.Settings.GetIntSetting(Settings.minTypeCharLimit); |
| 676 | + lastKeyPressTimer.Start(); |
| 677 | + lastKeypressTicks = System.DateTime.UtcNow.Ticks; |
| 678 | + } |
664 | 679 |
|
665 | | - if (emptyText) |
666 | | - ReloadFileList(); |
667 | | - if (textLength > minLength || emptyText) |
668 | | - { |
669 | | - FilterDataGrid(searchComboBox.Text); |
670 | | - } |
| 680 | + private void LastKeyPressTimer_Elapsed(object sender, EventArgs e) |
| 681 | + { |
| 682 | + Invoke(new Action(() => |
| 683 | + { |
| 684 | + // allow keypresses more recent than the interval, because we can't rely on precise timing of this event firing |
| 685 | + if (System.DateTime.UtcNow.Ticks <= lastKeypressTicks + System.TimeSpan.TicksPerMillisecond * lastKeyPressTimerInterval / 4) |
| 686 | + return; |
| 687 | + int textLength = searchComboBox.Text.Length; |
| 688 | + bool emptyText = string.IsNullOrWhiteSpace(searchComboBox.Text); |
| 689 | + int minLength = FrmSettings.Settings.GetIntSetting(Settings.minTypeCharLimit); |
| 690 | + |
| 691 | + if (emptyText) |
| 692 | + ReloadFileList(); |
| 693 | + if (textLength > minLength || emptyText) |
| 694 | + { |
| 695 | + FilterDataGrid(searchComboBox.Text); |
| 696 | + } |
671 | 697 |
|
672 | | - if (FrmSettings.Settings.GetBoolSetting(Settings.selectFirstRowOnFilter)) |
673 | | - { |
674 | | - SelectFirstRow(); |
675 | | - } |
| 698 | + if (FrmSettings.Settings.GetBoolSetting(Settings.selectFirstRowOnFilter)) |
| 699 | + { |
| 700 | + SelectFirstRow(); |
| 701 | + } |
| 702 | + })); |
676 | 703 | } |
677 | 704 |
|
678 | 705 | private void SelectFirstRow() |
|
0 commit comments