Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions Flow.Launcher.Test/Plugins/ExplorerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,129 @@ 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);
}

[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);
}
}
}
34 changes: 27 additions & 7 deletions Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +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)
{
// 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)
Expand All @@ -35,6 +46,13 @@ private static string GetPathWithActionKeyword(string path, ResultType type, str
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
Expand All @@ -54,7 +72,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string
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 =>
Expand Down Expand Up @@ -202,14 +220,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, 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 =>
Expand Down