Skip to content

Commit 9c13416

Browse files
committed
Fixes Typo TermSeparator & remove the actionkeyword in Terms
1 parent df9cb4b commit 9c13416

File tree

7 files changed

+28
-43
lines changed

7 files changed

+28
-43
lines changed

Flow.Launcher.Core/Plugin/QueryBuilder.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,31 @@ public static class QueryBuilder
1010
public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalPlugins)
1111
{
1212
// replace multiple white spaces with one white space
13-
var terms = text.Split(new[] { Query.TermSeperater }, StringSplitOptions.RemoveEmptyEntries);
14-
if (terms.Length == 0)
13+
var textSplit = text.Split(Query.TermSeparator, StringSplitOptions.RemoveEmptyEntries);
14+
if (textSplit.Length == 0)
1515
{ // nothing was typed
1616
return null;
1717
}
1818

19-
var rawQuery = string.Join(Query.TermSeperater, terms);
19+
var rawQuery = string.Join(Query.TermSeparator, textSplit);
2020
string actionKeyword, search;
21-
string possibleActionKeyword = terms[0];
22-
List<string> actionParameters;
21+
string possibleActionKeyword = textSplit[0];
22+
string[] terms;
23+
2324
if (nonGlobalPlugins.TryGetValue(possibleActionKeyword, out var pluginPair) && !pluginPair.Metadata.Disabled)
2425
{ // use non global plugin for query
2526
actionKeyword = possibleActionKeyword;
26-
actionParameters = terms.Skip(1).ToList();
27-
search = actionParameters.Count > 0 ? rawQuery.Substring(actionKeyword.Length + 1) : string.Empty;
27+
search = textSplit.Length > 1 ? rawQuery[(actionKeyword.Length + 1)..] : string.Empty;
28+
terms = textSplit[1..];
2829
}
2930
else
3031
{ // non action keyword
3132
actionKeyword = string.Empty;
3233
search = rawQuery;
34+
terms = textSplit;
3335
}
3436

35-
var query = new Query
36-
{
37-
Terms = terms,
38-
RawQuery = rawQuery,
39-
ActionKeyword = actionKeyword,
40-
Search = search
41-
};
37+
var query = new Query(rawQuery, search, terms, actionKeyword);
4238

4339
return query;
4440
}

Flow.Launcher.Plugin/Query.cs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using JetBrains.Annotations;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45

@@ -23,53 +24,48 @@ public Query(string rawQuery, string search, string[] terms, string actionKeywor
2324
/// Raw query, this includes action keyword if it has
2425
/// We didn't recommend use this property directly. You should always use Search property.
2526
/// </summary>
26-
public string RawQuery { get; internal set; }
27+
public string RawQuery { get; internal init; }
2728

2829
/// <summary>
2930
/// Search part of a query.
3031
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
3132
/// Since we allow user to switch a exclusive plugin to generic plugin,
3233
/// so this property will always give you the "real" query part of the query
3334
/// </summary>
34-
public string Search { get; internal set; }
35+
public string Search { get; internal init; }
3536

3637
/// <summary>
3738
/// The raw query splited into a string array.
3839
/// </summary>
39-
public string[] Terms { get; set; }
40+
public string[] Terms { get; init; }
4041

4142
/// <summary>
4243
/// Query can be splited into multiple terms by whitespace
4344
/// </summary>
44-
public const string TermSeperater = " ";
45+
public const string TermSeparator = " ";
4546
/// <summary>
4647
/// User can set multiple action keywords seperated by ';'
4748
/// </summary>
48-
public const string ActionKeywordSeperater = ";";
49+
public const string ActionKeywordSeparator = ";";
4950

5051
/// <summary>
5152
/// '*' is used for System Plugin
5253
/// </summary>
5354
public const string GlobalPluginWildcardSign = "*";
5455

55-
public string ActionKeyword { get; set; }
56+
public string ActionKeyword { get; init; }
5657

5758
/// <summary>
5859
/// Return first search split by space if it has
5960
/// </summary>
6061
public string FirstSearch => SplitSearch(0);
6162

63+
private string _secondToEndSearch;
64+
6265
/// <summary>
6366
/// strings from second search (including) to last search
6467
/// </summary>
65-
public string SecondToEndSearch
66-
{
67-
get
68-
{
69-
var index = string.IsNullOrEmpty(ActionKeyword) ? 1 : 2;
70-
return string.Join(TermSeperater, Terms.Skip(index).ToArray());
71-
}
72-
}
68+
public string SecondToEndSearch => _secondToEndSearch ??= string.Join(' ', Terms.AsMemory(2));
7369

7470
/// <summary>
7571
/// Return second search split by space if it has
@@ -83,16 +79,9 @@ public string SecondToEndSearch
8379

8480
private string SplitSearch(int index)
8581
{
86-
try
87-
{
88-
return string.IsNullOrEmpty(ActionKeyword) ? Terms[index] : Terms[index + 1];
89-
}
90-
catch (IndexOutOfRangeException)
91-
{
92-
return string.Empty;
93-
}
82+
return index < Terms.Length ? Terms[index] : string.Empty;
9483
}
9584

9685
public override string ToString() => RawQuery;
9786
}
98-
}
87+
}

Flow.Launcher/ActionKeywords.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public ActionKeywords(string pluginId, Settings settings, PluginViewModel plugin
3030

3131
private void ActionKeyword_OnLoaded(object sender, RoutedEventArgs e)
3232
{
33-
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeperater, plugin.Metadata.ActionKeywords.ToArray());
33+
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeparator, plugin.Metadata.ActionKeywords.ToArray());
3434
tbAction.Focus();
3535
}
3636

Flow.Launcher/ViewModel/PluginViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public bool PluginState
2222
public Visibility ActionKeywordsVisibility => PluginPair.Metadata.ActionKeywords.Count == 1 ? Visibility.Visible : Visibility.Collapsed;
2323
public string InitilizaTime => PluginPair.Metadata.InitTime.ToString() + "ms";
2424
public string QueryTime => PluginPair.Metadata.AvgQueryTime + "ms";
25-
public string ActionKeywordsText => string.Join(Query.ActionKeywordSeperater, PluginPair.Metadata.ActionKeywords);
25+
public string ActionKeywordsText => string.Join(Query.ActionKeywordSeparator, PluginPair.Metadata.ActionKeywords);
2626
public int Priority => PluginPair.Metadata.Priority;
2727

2828
public void ChangeActionKeyword(string newActionKeyword, string oldActionKeyword)

Plugins/Flow.Launcher.Plugin.PluginIndicator/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ where keyword.StartsWith(query.Terms[0])
2727
IcoPath = metadata.IcoPath,
2828
Action = c =>
2929
{
30-
context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeperater}");
30+
context.API.ChangeQuery($"{keyword}{Plugin.Query.TermSeparator}");
3131
return false;
3232
}
3333
};

Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public List<Result> Query(Query query)
2525
{
2626
var termToSearch = query.Terms.Length <= 1
2727
? null
28-
: string.Join(Plugin.Query.TermSeperater, query.Terms.Skip(1)).ToLower();
28+
: string.Join(Plugin.Query.TermSeparator, query.Terms.Skip(1)).ToLower();
2929

3030
var processlist = processHelper.GetMatchingProcesses(termToSearch);
3131

Plugins/Flow.Launcher.Plugin.Shell/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state)
297297

298298
private void OnWinRPressed()
299299
{
300-
context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeperater}");
300+
context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeparator}");
301301

302302
// show the main window and set focus to the query box
303303
Window mainWindow = Application.Current.MainWindow;

0 commit comments

Comments
 (0)