Skip to content
Merged
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
32 changes: 25 additions & 7 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public partial class MainViewModel : BaseModel, ISavable, IDisposable
private bool _isQueryRunning;
private Query _lastQuery;
private string _queryTextBeforeLeaveResults;
private string _ignoredQueryText = null;

private readonly FlowLauncherJsonStorage<History> _historyItemsStorage;
private readonly FlowLauncherJsonStorage<UserSelectedRecord> _userSelectedRecordStorage;
Expand Down Expand Up @@ -730,6 +731,9 @@ private ResultsViewModel SelectedResults
if (isReturningFromContextMenu)
{
_queryText = _queryTextBeforeLeaveResults;
// When executing OnPropertyChanged, QueryTextBox_TextChanged1 and Query will be called
// So we need to ignore it so that we will not call Query again
_ignoredQueryText = _queryText;
OnPropertyChanged(nameof(QueryText));
QueryTextCursorMovedToEnd = true;
}
Expand Down Expand Up @@ -1076,6 +1080,20 @@ private bool QueryResultsPreviewed()

public void Query(bool searchDelay, bool isReQuery = false)
{
if (_ignoredQueryText != null)
{
if (_ignoredQueryText == QueryText)
{
_ignoredQueryText = null;
return;
}
else
{
// If _ignoredQueryText does not match current QueryText, we should still execute Query
_ignoredQueryText = null;
}
}

if (QueryResultsSelected())
{
_ = QueryResultsAsync(searchDelay, isReQuery);
Expand Down Expand Up @@ -1170,7 +1188,7 @@ private void QueryHistory()
OriginQuery = new Query { RawQuery = h.Query },
Action = _ =>
{
SelectedResults = Results;
App.API.BackToQueryResults();
App.API.ChangeQuery(h.Query);
return false;
}
Expand Down Expand Up @@ -1414,11 +1432,14 @@ private async Task BuildQueryAsync(IEnumerable<BaseBuiltinShortcutModel> builtIn
}
}

// Show expanded builtin shortcuts
if (queryChanged)
{
// show expanded builtin shortcuts
// use private field to avoid infinite recursion
// Use private field to avoid infinite recursion
_queryText = queryBuilderTmp.ToString();
// When executing OnPropertyChanged, QueryTextBox_TextChanged1 and Query will be called
// So we need to ignore it so that we will not call Query again
_ignoredQueryText = _queryText;
OnPropertyChanged(nameof(QueryText));
}
}
Expand Down Expand Up @@ -1600,10 +1621,7 @@ public async void Hide()
await CloseExternalPreviewAsync();
}

if (!QueryResultsSelected())
{
SelectedResults = Results;
}
BackToQueryResults();

switch (Settings.LastQueryMode)
{
Expand Down
Loading