From f0b7898f8971b89617c66d0716e5ed0627cae2dc Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 22 Dec 2022 22:04:39 +1100 Subject: [PATCH 1/7] fix quick access path search and autocomplete text --- .../Search/ResultManager.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 88bfecc14fb..6669cbf768a 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -49,12 +49,20 @@ public static Result CreateResult(Query query, SearchResult result) internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, int score = 0, bool windowsIndexed = false) { + var pathSearchActionKeyword = Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled + ? Settings.PathSearchActionKeyword + : Settings.SearchActionKeyword == Query.GlobalPluginWildcardSign + ? string.Empty + : Settings.SearchActionKeyword; + return new Result { Title = title, IcoPath = path, SubTitle = Path.GetDirectoryName(path), - AutoCompleteText = GetPathWithActionKeyword(path, ResultType.Folder, query.ActionKeyword), + AutoCompleteText = !Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled + ? $"{query.ActionKeyword} {title}" // Only Quick Access action keyword is used in this scenario + : GetPathWithActionKeyword(path, ResultType.Folder, pathSearchActionKeyword), TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData, CopyText = path, Action = c => @@ -73,7 +81,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string } } - Context.API.ChangeQuery(GetPathWithActionKeyword(path, ResultType.Folder, query.ActionKeyword)); + Context.API.ChangeQuery(GetPathWithActionKeyword(path, ResultType.Folder, pathSearchActionKeyword)); return false; }, From 5c1cc79751be790e8cddf02b93e787ce747faef6 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 22 Dec 2022 22:39:24 +1100 Subject: [PATCH 2/7] update GetPathWithActionKeyword --- .../Search/ResultManager.cs | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 6669cbf768a..224deb4173c 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -21,10 +21,13 @@ public static void Init(PluginInitContext context, Settings settings) Settings = settings; } - private static string GetPathWithActionKeyword(string path, ResultType type, string actionKeyword) + private static string GetPathWithActionKeyword(string path, ResultType type) { - // Query.ActionKeyword is string.Empty when Global Action Keyword ('*') is used - var keyword = actionKeyword != string.Empty ? actionKeyword + " " : string.Empty; + var keyword = Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled + ? $"{Settings.PathSearchActionKeyword} " + : Settings.SearchActionKeyword == Query.GlobalPluginWildcardSign + ? string.Empty // Query.ActionKeyword is string.Empty when Global Action Keyword ('*') is used + : $"{Settings.SearchActionKeyword} "; var formatted_path = path; @@ -49,12 +52,6 @@ public static Result CreateResult(Query query, SearchResult result) internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, int score = 0, bool windowsIndexed = false) { - var pathSearchActionKeyword = Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled - ? Settings.PathSearchActionKeyword - : Settings.SearchActionKeyword == Query.GlobalPluginWildcardSign - ? string.Empty - : Settings.SearchActionKeyword; - return new Result { Title = title, @@ -62,7 +59,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string SubTitle = Path.GetDirectoryName(path), AutoCompleteText = !Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled ? $"{query.ActionKeyword} {title}" // Only Quick Access action keyword is used in this scenario - : GetPathWithActionKeyword(path, ResultType.Folder, pathSearchActionKeyword), + : GetPathWithActionKeyword(path, ResultType.Folder), TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData, CopyText = path, Action = c => @@ -81,7 +78,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string } } - Context.API.ChangeQuery(GetPathWithActionKeyword(path, ResultType.Folder, pathSearchActionKeyword)); + Context.API.ChangeQuery(GetPathWithActionKeyword(path, ResultType.Folder)); return false; }, @@ -116,7 +113,7 @@ internal static Result CreateDriveSpaceDisplayResult(string path, string actionK { Title = title, SubTitle = subtitle, - AutoCompleteText = GetPathWithActionKeyword(path, ResultType.Folder, actionKeyword), + AutoCompleteText = GetPathWithActionKeyword(path, ResultType.Folder), IcoPath = path, Score = 500, ProgressBar = progressValue, @@ -197,7 +194,7 @@ internal static Result CreateOpenCurrentFolderResult(string path, string actionK Title = title, SubTitle = $"Use > to search within {subtitleFolderName}, " + $"* to search for file extensions or >* to combine both searches.", - AutoCompleteText = GetPathWithActionKeyword(folderPath, ResultType.Folder, actionKeyword), + AutoCompleteText = GetPathWithActionKeyword(folderPath, ResultType.Folder), IcoPath = folderPath, Score = 500, CopyText = folderPath, @@ -228,7 +225,7 @@ internal static Result CreateFileResult(string filePath, Query query, int score SubTitle = Path.GetDirectoryName(filePath), IcoPath = filePath, Preview = preview, - AutoCompleteText = GetPathWithActionKeyword(filePath, ResultType.File, query.ActionKeyword), + AutoCompleteText = GetPathWithActionKeyword(filePath, ResultType.File), TitleHighlightData = StringMatcher.FuzzySearch(query.Search, Path.GetFileName(filePath)).MatchData, Score = score, CopyText = filePath, From fc9805f29ed18efb7b52fc327d891e548e08cc95 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 22 Dec 2022 22:57:37 +1100 Subject: [PATCH 3/7] add GetAutoCompleteText method --- .../Search/ResultManager.cs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 224deb4173c..53e1de767a3 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -1,4 +1,4 @@ -using Flow.Launcher.Core.Resource; +using Flow.Launcher.Core.Resource; using Flow.Launcher.Infrastructure; using Flow.Launcher.Plugin.SharedCommands; using System; @@ -38,6 +38,13 @@ private static string GetPathWithActionKeyword(string path, ResultType type) return $"{keyword}{formatted_path}"; } + private static string GetAutoCompleteText(string title, Query query, string path, ResultType resultType) + { + return !Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled + ? $"{query.ActionKeyword} {title}" // Only Quick Access action keyword is used in this scenario + : GetPathWithActionKeyword(path, resultType); + } + public static Result CreateResult(Query query, SearchResult result) { return result.Type switch @@ -57,9 +64,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string Title = title, IcoPath = path, SubTitle = Path.GetDirectoryName(path), - AutoCompleteText = !Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled - ? $"{query.ActionKeyword} {title}" // Only Quick Access action keyword is used in this scenario - : GetPathWithActionKeyword(path, ResultType.Folder), + AutoCompleteText = GetAutoCompleteText(title, query, path, ResultType.Folder), TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData, CopyText = path, Action = c => @@ -219,14 +224,16 @@ internal static Result CreateFileResult(string filePath, Query query, int score PreviewImagePath = filePath, } : Result.PreviewInfo.Default; + var title = Path.GetFileName(filePath); + var result = new Result { - Title = Path.GetFileName(filePath), + Title = title, SubTitle = Path.GetDirectoryName(filePath), IcoPath = filePath, Preview = preview, - AutoCompleteText = GetPathWithActionKeyword(filePath, ResultType.File), - TitleHighlightData = StringMatcher.FuzzySearch(query.Search, Path.GetFileName(filePath)).MatchData, + AutoCompleteText = GetAutoCompleteText(title, query, filePath, ResultType.File), + TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData, Score = score, CopyText = filePath, Action = c => From 2174fc24cee3e6826d8affc0e02a222a105ec336 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 22 Dec 2022 23:20:37 +1100 Subject: [PATCH 4/7] update directory navigation with same action keyword --- .../Search/ResultManager.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 53e1de767a3..69df2764d0c 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -21,13 +21,22 @@ public static void Init(PluginInitContext context, Settings settings) Settings = settings; } - private static string GetPathWithActionKeyword(string path, ResultType type) + private static string GetPathWithActionKeyword(string path, ResultType type, string actionKeyword) { - var keyword = Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled + string keyword; + // Using Quick Access or Index Search action keywords to then navigate to directory + if (actionKeyword == Settings.PathSearchActionKeyword || actionKeyword == Settings.SearchActionKeyword) + { + keyword = actionKeyword == Settings.PathSearchActionKeyword ? $"{actionKeyword} " : string.Empty; + } + else + { + keyword = Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled ? $"{Settings.PathSearchActionKeyword} " : Settings.SearchActionKeyword == Query.GlobalPluginWildcardSign ? string.Empty // Query.ActionKeyword is string.Empty when Global Action Keyword ('*') is used : $"{Settings.SearchActionKeyword} "; + } var formatted_path = path; @@ -42,7 +51,7 @@ private static string GetAutoCompleteText(string title, Query query, string path { return !Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled ? $"{query.ActionKeyword} {title}" // Only Quick Access action keyword is used in this scenario - : GetPathWithActionKeyword(path, resultType); + : GetPathWithActionKeyword(path, resultType, query.ActionKeyword); } public static Result CreateResult(Query query, SearchResult result) @@ -83,7 +92,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string } } - Context.API.ChangeQuery(GetPathWithActionKeyword(path, ResultType.Folder)); + Context.API.ChangeQuery(GetPathWithActionKeyword(path, ResultType.Folder, query.ActionKeyword)); return false; }, @@ -118,7 +127,7 @@ internal static Result CreateDriveSpaceDisplayResult(string path, string actionK { Title = title, SubTitle = subtitle, - AutoCompleteText = GetPathWithActionKeyword(path, ResultType.Folder), + AutoCompleteText = GetPathWithActionKeyword(path, ResultType.Folder, actionKeyword), IcoPath = path, Score = 500, ProgressBar = progressValue, @@ -199,7 +208,7 @@ internal static Result CreateOpenCurrentFolderResult(string path, string actionK Title = title, SubTitle = $"Use > to search within {subtitleFolderName}, " + $"* to search for file extensions or >* to combine both searches.", - AutoCompleteText = GetPathWithActionKeyword(folderPath, ResultType.Folder), + AutoCompleteText = GetPathWithActionKeyword(folderPath, ResultType.Folder, actionKeyword), IcoPath = folderPath, Score = 500, CopyText = folderPath, From fac24285e04147c54873f950055582fcdffc65e8 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sat, 24 Dec 2022 22:50:50 +1100 Subject: [PATCH 5/7] add folder and file get path unit tests --- Flow.Launcher.Test/Plugins/ExplorerTest.cs | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/Flow.Launcher.Test/Plugins/ExplorerTest.cs b/Flow.Launcher.Test/Plugins/ExplorerTest.cs index e0cc9b4c2f1..94ee85b69e9 100644 --- a/Flow.Launcher.Test/Plugins/ExplorerTest.cs +++ b/Flow.Launcher.Test/Plugins/ExplorerTest.cs @@ -269,5 +269,65 @@ public void GivenDirectoryInfoSearch_WhenSearchPatternHotKeyIsSearchAll_ThenSear // Then Assert.AreEqual(expectedString, resultString); } + + [TestCase("c:\\somefolder\\someotherfolder", ResultType.Folder, "irrelevant", false, true, "c:\\somefolder\\someotherfolder\\")] + [TestCase("c:\\somefolder\\someotherfolder\\", ResultType.Folder, "irrelevant", true, true, "c:\\somefolder\\someotherfolder\\")] + [TestCase("c:\\somefolder\\someotherfolder", ResultType.Folder, "irrelevant", true, false, "p c:\\somefolder\\someotherfolder\\")] + [TestCase("c:\\somefolder\\someotherfolder\\", ResultType.Folder, "irrelevant", false, false, "c:\\somefolder\\someotherfolder\\")] + [TestCase("c:\\somefolder\\someotherfolder", ResultType.Folder, "p", true, false, "p c:\\somefolder\\someotherfolder\\")] + [TestCase("c:\\somefolder\\someotherfolder", ResultType.Folder, "", true, true, "c:\\somefolder\\someotherfolder\\")] + public void GivenFolderResult_WhenGetPath_ThenPathShouldBeExpectedString( + string path, + ResultType type, + string actionKeyword, + bool pathSearchKeywordEnabled, + bool searchActionKeywordEnabled, + string expectedResult) + { + // Given + var settings = new Settings() + { + PathSearchKeywordEnabled = pathSearchKeywordEnabled, + PathSearchActionKeyword = "p", + SearchActionKeywordEnabled = searchActionKeywordEnabled, + SearchActionKeyword = Query.GlobalPluginWildcardSign + }; + ResultManager.Init(new PluginInitContext(), settings); + + // When + var result = ResultManager.GetPathWithActionKeyword(path, type, actionKeyword); + + // Then + Assert.AreEqual(result, expectedResult); + } + + [TestCase("c:\\somefolder\\somefile", ResultType.File, "irrelevant", false, true, "e c:\\somefolder\\somefile")] + [TestCase("c:\\somefolder\\somefile", ResultType.File, "p", true, false, "p c:\\somefolder\\somefile")] + [TestCase("c:\\somefolder\\somefile", ResultType.File, "e", true, true, "e c:\\somefolder\\somefile")] + [TestCase("c:\\somefolder\\somefile", ResultType.File, "irrelevant", false, false, "e c:\\somefolder\\somefile")] + public void GivenFileResult_WhenGetPath_ThenPathShouldBeExpectedString( + string path, + ResultType type, + string actionKeyword, + bool pathSearchKeywordEnabled, + bool searchActionKeywordEnabled, + string expectedResult) + { + // Given + var settings = new Settings() + { + PathSearchKeywordEnabled = pathSearchKeywordEnabled, + PathSearchActionKeyword = "p", + SearchActionKeywordEnabled = searchActionKeywordEnabled, + SearchActionKeyword = "e" + }; + ResultManager.Init(new PluginInitContext(), settings); + + // When + var result = ResultManager.GetPathWithActionKeyword(path, type, actionKeyword); + + // Then + Assert.AreEqual(result, expectedResult); + } } } From f64ebdca957013f0950b3ac61b1b5e95dd7dad68 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sat, 24 Dec 2022 22:51:09 +1100 Subject: [PATCH 6/7] simplify get path method --- .../Search/ResultManager.cs | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 69df2764d0c..1d3a579967f 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -1,4 +1,4 @@ -using Flow.Launcher.Core.Resource; +using Flow.Launcher.Core.Resource; using Flow.Launcher.Infrastructure; using Flow.Launcher.Plugin.SharedCommands; using System; @@ -21,23 +21,22 @@ public static void Init(PluginInitContext context, Settings settings) Settings = settings; } - private static string GetPathWithActionKeyword(string path, ResultType type, string actionKeyword) + public static string GetPathWithActionKeyword(string path, ResultType type, string actionKeyword) { - string keyword; - // Using Quick Access or Index Search action keywords to then navigate to directory - if (actionKeyword == Settings.PathSearchActionKeyword || actionKeyword == Settings.SearchActionKeyword) - { - keyword = actionKeyword == Settings.PathSearchActionKeyword ? $"{actionKeyword} " : string.Empty; - } - else - { - keyword = Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled - ? $"{Settings.PathSearchActionKeyword} " - : Settings.SearchActionKeyword == Query.GlobalPluginWildcardSign - ? string.Empty // Query.ActionKeyword is string.Empty when Global Action Keyword ('*') is used - : $"{Settings.SearchActionKeyword} "; - } + // actionKeyword will be empty string if using global, query.ActionKeyword is "" + var usePathSearchActionKeyword = Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled; + + var pathSearchActionKeyword = Settings.PathSearchActionKeyword == Query.GlobalPluginWildcardSign + ? string.Empty + : $"{Settings.PathSearchActionKeyword} "; + + var searchActionKeyword = Settings.SearchActionKeyword == Query.GlobalPluginWildcardSign + ? string.Empty + : $"{Settings.SearchActionKeyword} "; + + var keyword = usePathSearchActionKeyword ? pathSearchActionKeyword : searchActionKeyword; + var formatted_path = path; if (type == ResultType.Folder) From 3f2b741dccb8eafcd58c712484ea6b6623d02c67 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 25 Dec 2022 04:58:37 +1100 Subject: [PATCH 7/7] add unit tests for get autocomplete result --- Flow.Launcher.Test/Plugins/ExplorerTest.cs | 64 +++++++++++++++++++ .../Search/ResultManager.cs | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Test/Plugins/ExplorerTest.cs b/Flow.Launcher.Test/Plugins/ExplorerTest.cs index 94ee85b69e9..36f0294a93e 100644 --- a/Flow.Launcher.Test/Plugins/ExplorerTest.cs +++ b/Flow.Launcher.Test/Plugins/ExplorerTest.cs @@ -329,5 +329,69 @@ public void GivenFileResult_WhenGetPath_ThenPathShouldBeExpectedString( // Then Assert.AreEqual(result, expectedResult); } + + [TestCase("somefolder", "c:\\somefolder\\", ResultType.Folder, "q", false, false, "q somefolder")] + [TestCase("somefolder", "c:\\somefolder\\", ResultType.Folder, "i", true, false, "p c:\\somefolder\\")] + [TestCase("somefolder", "c:\\somefolder\\", ResultType.Folder, "irrelevant", true, true, "c:\\somefolder\\")] + public void GivenQueryWithFolderTypeResult_WhenGetAutoComplete_ThenResultShouldBeExpectedString( + string title, + string path, + ResultType resultType, + string actionKeyword, + bool pathSearchKeywordEnabled, + bool searchActionKeywordEnabled, + string expectedResult) + { + // Given + var query = new Query() { ActionKeyword = actionKeyword }; + var settings = new Settings() + { + PathSearchKeywordEnabled = pathSearchKeywordEnabled, + PathSearchActionKeyword = "p", + SearchActionKeywordEnabled = searchActionKeywordEnabled, + SearchActionKeyword = Query.GlobalPluginWildcardSign, + QuickAccessActionKeyword = "q", + IndexSearchActionKeyword = "i" + }; + ResultManager.Init(new PluginInitContext(), settings); + + // When + var result = ResultManager.GetAutoCompleteText(title, query, path, resultType); + + // Then + Assert.AreEqual(result, expectedResult); + } + + [TestCase("somefile", "c:\\somefolder\\somefile", ResultType.File, "q", false, false, "q somefile")] + [TestCase("somefile", "c:\\somefolder\\somefile", ResultType.File, "i", true, false, "p c:\\somefolder\\somefile")] + [TestCase("somefile", "c:\\somefolder\\somefile", ResultType.File, "irrelevant", true, true, "c:\\somefolder\\somefile")] + public void GivenQueryWithFileTypeResult_WhenGetAutoComplete_ThenResultShouldBeExpectedString( + string title, + string path, + ResultType resultType, + string actionKeyword, + bool pathSearchKeywordEnabled, + bool searchActionKeywordEnabled, + string expectedResult) + { + // Given + var query = new Query() { ActionKeyword = actionKeyword }; + var settings = new Settings() + { + QuickAccessActionKeyword = "q", + IndexSearchActionKeyword = "i", + PathSearchActionKeyword = "p", + PathSearchKeywordEnabled = pathSearchKeywordEnabled, + SearchActionKeywordEnabled = searchActionKeywordEnabled, + SearchActionKeyword = Query.GlobalPluginWildcardSign + }; + ResultManager.Init(new PluginInitContext(), settings); + + // When + var result = ResultManager.GetAutoCompleteText(title, query, path, resultType); + + // Then + Assert.AreEqual(result, expectedResult); + } } } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index 1d3a579967f..1e35b787377 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -46,7 +46,7 @@ public static string GetPathWithActionKeyword(string path, ResultType type, stri return $"{keyword}{formatted_path}"; } - private static string GetAutoCompleteText(string title, Query query, string path, ResultType resultType) + public static string GetAutoCompleteText(string title, Query query, string path, ResultType resultType) { return !Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled ? $"{query.ActionKeyword} {title}" // Only Quick Access action keyword is used in this scenario