mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #1706 from Flow-Launcher/fix_quickaccess_autocomplete
Fix quick access path search and autocomplete text
This commit is contained in:
commit
6607acbcce
2 changed files with 151 additions and 7 deletions
|
|
@ -269,5 +269,129 @@ namespace Flow.Launcher.Test.Plugins
|
|||
// 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);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,22 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
Settings = settings;
|
||||
}
|
||||
|
||||
private static string GetPathWithActionKeyword(string path, ResultType type, string actionKeyword)
|
||||
public static string GetPathWithActionKeyword(string path, ResultType type, string actionKeyword)
|
||||
{
|
||||
// Query.ActionKeyword is string.Empty when Global Action Keyword ('*') is used
|
||||
var keyword = actionKeyword != string.Empty ? actionKeyword + " " : string.Empty;
|
||||
// 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)
|
||||
|
|
@ -35,6 +46,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
return $"{keyword}{formatted_path}";
|
||||
}
|
||||
|
||||
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
|
||||
: GetPathWithActionKeyword(path, resultType, query.ActionKeyword);
|
||||
}
|
||||
|
||||
public static Result CreateResult(Query query, SearchResult result)
|
||||
{
|
||||
return result.Type switch
|
||||
|
|
@ -54,7 +72,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
Title = title,
|
||||
IcoPath = path,
|
||||
SubTitle = Path.GetDirectoryName(path),
|
||||
AutoCompleteText = GetPathWithActionKeyword(path, ResultType.Folder, query.ActionKeyword),
|
||||
AutoCompleteText = GetAutoCompleteText(title, query, path, ResultType.Folder),
|
||||
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData,
|
||||
CopyText = path,
|
||||
Action = c =>
|
||||
|
|
@ -202,14 +220,16 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
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, query.ActionKeyword),
|
||||
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 =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue