Skip to content

Commit 1381748

Browse files
authored
Merge branch 'dev' into improve_update
2 parents 381334f + a2a8c50 commit 1381748

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
@@ -35,6 +35,7 @@ public partial class MainViewModel : BaseModel, ISavable, IDisposable
3535
private Query _progressQuery; // Used for QueryResultAsync
3636
private Query _updateQuery; // Used for ResultsUpdated
3737
private string _queryTextBeforeLeaveResults;
38+
private string _ignoredQueryText = null;
3839

3940
private readonly FlowLauncherJsonStorage<History> _historyItemsStorage;
4041
private readonly FlowLauncherJsonStorage<UserSelectedRecord> _userSelectedRecordStorage;
@@ -734,6 +735,9 @@ private ResultsViewModel SelectedResults
734735
if (isReturningFromContextMenu)
735736
{
736737
_queryText = _queryTextBeforeLeaveResults;
738+
// When executing OnPropertyChanged, QueryTextBox_TextChanged1 and Query will be called
739+
// So we need to ignore it so that we will not call Query again
740+
_ignoredQueryText = _queryText;
737741
OnPropertyChanged(nameof(QueryText));
738742
QueryTextCursorMovedToEnd = true;
739743
}
@@ -1080,6 +1084,20 @@ private bool QueryResultsPreviewed()
10801084

10811085
public void Query(bool searchDelay, bool isReQuery = false)
10821086
{
1087+
if (_ignoredQueryText != null)
1088+
{
1089+
if (_ignoredQueryText == QueryText)
1090+
{
1091+
_ignoredQueryText = null;
1092+
return;
1093+
}
1094+
else
1095+
{
1096+
// If _ignoredQueryText does not match current QueryText, we should still execute Query
1097+
_ignoredQueryText = null;
1098+
}
1099+
}
1100+
10831101
if (QueryResultsSelected())
10841102
{
10851103
_ = QueryResultsAsync(searchDelay, isReQuery);
@@ -1174,7 +1192,7 @@ private void QueryHistory()
11741192
OriginQuery = new Query { RawQuery = h.Query },
11751193
Action = _ =>
11761194
{
1177-
SelectedResults = Results;
1195+
App.API.BackToQueryResults();
11781196
App.API.ChangeQuery(h.Query);
11791197
return false;
11801198
}
@@ -1433,11 +1451,14 @@ private async Task BuildQueryAsync(IEnumerable<BaseBuiltinShortcutModel> builtIn
14331451
}
14341452
}
14351453

1454+
// Show expanded builtin shortcuts
14361455
if (queryChanged)
14371456
{
1438-
// show expanded builtin shortcuts
1439-
// use private field to avoid infinite recursion
1457+
// Use private field to avoid infinite recursion
14401458
_queryText = queryBuilderTmp.ToString();
1459+
// When executing OnPropertyChanged, QueryTextBox_TextChanged1 and Query will be called
1460+
// So we need to ignore it so that we will not call Query again
1461+
_ignoredQueryText = _queryText;
14411462
OnPropertyChanged(nameof(QueryText));
14421463
}
14431464
}
@@ -1616,10 +1637,7 @@ public async void Hide()
16161637
await CloseExternalPreviewAsync();
16171638
}
16181639

1619-
if (!QueryResultsSelected())
1620-
{
1621-
SelectedResults = Results;
1622-
}
1640+
BackToQueryResults();
16231641

16241642
switch (Settings.LastQueryMode)
16251643
{

0 commit comments

Comments
 (0)