From f670cc831fc0cd83d1fcf4e378dc3ab0247cf9d8 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 4 Mar 2023 07:56:44 +0000 Subject: [PATCH] Don't add more than 10000 search results --- Terminal.Gui/Windows/FileDialog2.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Windows/FileDialog2.cs b/Terminal.Gui/Windows/FileDialog2.cs index a1c9f278d..b3e162046 100644 --- a/Terminal.Gui/Windows/FileDialog2.cs +++ b/Terminal.Gui/Windows/FileDialog2.cs @@ -25,6 +25,16 @@ namespace Terminal.Gui { private const string HeaderModified = "Modified"; private const string HeaderType = "Type"; + /// + /// The maximum number of results that will be collected + /// when searching before stopping. + /// + /// + /// This prevents performance issues e.g. when searching + /// root of file system for a common letter (e.g. 'e'). + /// + public int MaxSearchResults {get;set;} = 10000; + /// /// True if the file/folder must exist already to be selected. /// This prevents user from entering the name of something that @@ -1444,6 +1454,12 @@ namespace Terminal.Gui { if (f.Name.Contains (searchTerms)) { lock (oLockFound) { found.Add (f); + + if(found.Count >= Parent.MaxSearchResults) + { + finished = true; + return; + } } } @@ -1567,7 +1583,7 @@ namespace Terminal.Gui { } } internal class SpinnerLabel : Label { - private Rune [] runes = new Rune [] { '|', '/', '\u2500', '/', '\u2500', '\\' }; + private Rune [] runes = new Rune [] { '|', '/', '\u2500', '\\'}; private int currentIdx = 0; private DateTime lastRender = DateTime.MinValue;