Skip to content

Commit 282f486

Browse files
committed
Fix query input check issue
1 parent ccfc6fd commit 282f486

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

Flow.Launcher.Core/Plugin/QueryBuilder.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using Flow.Launcher.Plugin;
44

55
namespace Flow.Launcher.Core.Plugin
66
{
77
public static class QueryBuilder
88
{
9-
public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalPlugins)
9+
public static Query Build(string input, string text, Dictionary<string, PluginPair> nonGlobalPlugins)
1010
{
1111
// replace multiple white spaces with one white space
1212
var terms = text.Split(Query.TermSeparator, StringSplitOptions.RemoveEmptyEntries);
@@ -21,13 +21,15 @@ public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalP
2121
string[] searchTerms;
2222

2323
if (nonGlobalPlugins.TryGetValue(possibleActionKeyword, out var pluginPair) && !pluginPair.Metadata.Disabled)
24-
{ // use non global plugin for query
24+
{
25+
// use non global plugin for query
2526
actionKeyword = possibleActionKeyword;
2627
search = terms.Length > 1 ? rawQuery[(actionKeyword.Length + 1)..].TrimStart() : string.Empty;
2728
searchTerms = terms[1..];
2829
}
2930
else
30-
{ // non action keyword
31+
{
32+
// non action keyword
3133
actionKeyword = string.Empty;
3234
search = rawQuery.TrimStart();
3335
searchTerms = terms;
@@ -36,10 +38,11 @@ public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalP
3638
return new Query ()
3739
{
3840
Search = search,
41+
Input = input,
3942
RawQuery = rawQuery,
4043
SearchTerms = searchTerms,
4144
ActionKeyword = actionKeyword
4245
};
4346
}
4447
}
45-
}
48+
}

Flow.Launcher.Plugin/Query.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ namespace Flow.Launcher.Plugin
88
public class Query
99
{
1010
/// <summary>
11-
/// Raw query, this includes action keyword if it has
11+
/// Input text in query box.
12+
/// We didn't recommend use this property directly. You should always use Search property.
13+
/// </summary>
14+
public string Input { get; internal init; }
15+
16+
/// <summary>
17+
/// Raw query, this includes action keyword if it has.
18+
/// It has handled buildin custom hotkeys and user custom hotkeys, and it trims the whitespace.
1219
/// We didn't recommend use this property directly. You should always use Search property.
1320
/// </summary>
1421
public string RawQuery { get; internal init; }

Flow.Launcher.Test/QueryBuilderTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void ExclusivePluginQueryTest()
1616
{">", new PluginPair {Metadata = new PluginMetadata {ActionKeywords = new List<string> {">"}}}}
1717
};
1818

19-
Query q = QueryBuilder.Build("> ping google.com -n 20 -6", nonGlobalPlugins);
19+
Query q = QueryBuilder.Build("> ping google.com -n 20 -6", "> ping google.com -n 20 -6", nonGlobalPlugins);
2020

2121
ClassicAssert.AreEqual("> ping google.com -n 20 -6", q.RawQuery);
2222
ClassicAssert.AreEqual("ping google.com -n 20 -6", q.Search, "Search should not start with the ActionKeyword.");
@@ -39,7 +39,7 @@ public void ExclusivePluginQueryIgnoreDisabledTest()
3939
{">", new PluginPair {Metadata = new PluginMetadata {ActionKeywords = new List<string> {">"}, Disabled = true}}}
4040
};
4141

42-
Query q = QueryBuilder.Build("> ping google.com -n 20 -6", nonGlobalPlugins);
42+
Query q = QueryBuilder.Build("> ping google.com -n 20 -6", "> ping google.com -n 20 -6", nonGlobalPlugins);
4343

4444
ClassicAssert.AreEqual("> ping google.com -n 20 -6", q.Search);
4545
ClassicAssert.AreEqual(q.Search, q.RawQuery, "RawQuery should be equal to Search.");
@@ -51,7 +51,7 @@ public void ExclusivePluginQueryIgnoreDisabledTest()
5151
[Test]
5252
public void GenericPluginQueryTest()
5353
{
54-
Query q = QueryBuilder.Build("file.txt file2 file3", new Dictionary<string, PluginPair>());
54+
Query q = QueryBuilder.Build("file.txt file2 file3", "file.txt file2 file3", new Dictionary<string, PluginPair>());
5555

5656
ClassicAssert.AreEqual("file.txt file2 file3", q.Search);
5757
ClassicAssert.AreEqual("", q.ActionKeyword);

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ private void OnKeyDown(object sender, KeyEventArgs e)
401401
&& QueryTextBox.CaretIndex == QueryTextBox.Text.Length)
402402
{
403403
var queryWithoutActionKeyword =
404-
QueryBuilder.Build(QueryTextBox.Text.Trim(), PluginManager.NonGlobalPlugins)?.Search;
404+
QueryBuilder.Build(QueryTextBox.Text, QueryTextBox.Text.Trim(), PluginManager.NonGlobalPlugins)?.Search;
405405

406406
if (FilesFolders.IsLocationPathString(queryWithoutActionKeyword))
407407
{

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ private void LoadContextMenu()
380380
[RelayCommand]
381381
private void Backspace(object index)
382382
{
383-
var query = QueryBuilder.Build(QueryText.Trim(), PluginManager.NonGlobalPlugins);
383+
var query = QueryBuilder.Build(QueryText, QueryText.Trim(), PluginManager.NonGlobalPlugins);
384384

385385
// GetPreviousExistingDirectory does not require trailing '\', otherwise will return empty string
386386
var path = FilesFolders.GetPreviousExistingDirectory((_) => true, query.Search.TrimEnd('\\'));
@@ -1262,7 +1262,7 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
12621262
{
12631263
// Check if the query has changed because query can be changed so fast that
12641264
// token of the query between two queries has not been created yet
1265-
if (query.RawQuery != QueryText)
1265+
if (query.Input != QueryText && query.RawQuery != QueryText.Trim())
12661266
{
12671267
Infrastructure.Logger.Log.Debug(ClassName, $"Cancel for QueryText 0: {query.RawQuery}");
12681268
return;
@@ -1476,7 +1476,7 @@ private Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel>
14761476
// Applying builtin shortcuts
14771477
BuildQuery(builtInShortcuts, queryBuilder, queryBuilderTmp);
14781478

1479-
return QueryBuilder.Build(queryBuilder.ToString().Trim(), PluginManager.NonGlobalPlugins);
1479+
return QueryBuilder.Build(queryText, queryBuilder.ToString().Trim(), PluginManager.NonGlobalPlugins);
14801480
}
14811481

14821482
private void BuildQuery(IEnumerable<BaseBuiltinShortcutModel> builtInShortcuts,

0 commit comments

Comments
 (0)