Skip to content

Commit fe25764

Browse files
committed
Merge branch 'empty_query' of https://github.com/Jack251970/Flow.Launcher into empty_query
2 parents 2ab007b + ccb1bac commit fe25764

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public partial class MainViewModel : BaseModel, ISavable, IDisposable
3434
private bool _isQueryRunning;
3535
private Query _lastQuery;
3636
private string _queryTextBeforeLeaveResults;
37+
private string _ignoredQueryText = null;
3738

3839
private readonly FlowLauncherJsonStorage<History> _historyItemsStorage;
3940
private readonly FlowLauncherJsonStorage<UserSelectedRecord> _userSelectedRecordStorage;
@@ -736,6 +737,9 @@ private ResultsViewModel SelectedResults
736737
if (isReturningFromContextMenu)
737738
{
738739
_queryText = _queryTextBeforeLeaveResults;
740+
// When executing OnPropertyChanged, QueryTextBox_TextChanged1 and Query will be called
741+
// So we need to ignore it so that we will not call Query again
742+
_ignoredQueryText = _queryText;
739743
OnPropertyChanged(nameof(QueryText));
740744
QueryTextCursorMovedToEnd = true;
741745
}
@@ -1087,6 +1091,20 @@ public void QueryResults()
10871091

10881092
public void Query(bool searchDelay, bool isReQuery = false)
10891093
{
1094+
if (_ignoredQueryText != null)
1095+
{
1096+
if (_ignoredQueryText == QueryText)
1097+
{
1098+
_ignoredQueryText = null;
1099+
return;
1100+
}
1101+
else
1102+
{
1103+
// If _ignoredQueryText does not match current QueryText, we should still execute Query
1104+
_ignoredQueryText = null;
1105+
}
1106+
}
1107+
10901108
if (QueryResultsSelected())
10911109
{
10921110
_ = QueryResultsAsync(searchDelay, isReQuery);
@@ -1192,7 +1210,7 @@ private void QueryHistory()
11921210
OriginQuery = new Query { RawQuery = h.Query },
11931211
Action = _ =>
11941212
{
1195-
SelectedResults = Results;
1213+
App.API.BackToQueryResults();
11961214
App.API.ChangeQuery(h.Query);
11971215
return false;
11981216
}
@@ -1518,11 +1536,14 @@ private async Task BuildQueryAsync(IEnumerable<BaseBuiltinShortcutModel> builtIn
15181536
}
15191537
}
15201538

1539+
// Show expanded builtin shortcuts
15211540
if (queryChanged)
15221541
{
1523-
// show expanded builtin shortcuts
1524-
// use private field to avoid infinite recursion
1542+
// Use private field to avoid infinite recursion
15251543
_queryText = queryBuilderTmp.ToString();
1544+
// When executing OnPropertyChanged, QueryTextBox_TextChanged1 and Query will be called
1545+
// So we need to ignore it so that we will not call Query again
1546+
_ignoredQueryText = _queryText;
15261547
OnPropertyChanged(nameof(QueryText));
15271548
}
15281549
}
@@ -1704,10 +1725,7 @@ public async void Hide()
17041725
await CloseExternalPreviewAsync();
17051726
}
17061727

1707-
if (!QueryResultsSelected())
1708-
{
1709-
SelectedResults = Results;
1710-
}
1728+
BackToQueryResults();
17111729

17121730
switch (Settings.LastQueryMode)
17131731
{

0 commit comments

Comments
 (0)