Skip to content

Commit

Permalink
Merge pull request #2174 from JohnTheGr8/requery_enhancements
Browse files Browse the repository at this point in the history
Improvements for re-queries
  • Loading branch information
jjw24 committed Jun 13, 2023
2 parents 1b68d09 + f22ce37 commit 0047d8a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
7 changes: 7 additions & 0 deletions Flow.Launcher.Plugin/Query.cs
Expand Up @@ -26,6 +26,13 @@ public Query(string rawQuery, string search, string[] terms, string[] searchTerm
/// </summary>
public string RawQuery { get; internal init; }

/// <summary>
/// Determines whether the query was forced to execute again.
/// For example, the value will be true when the user presses Ctrl + R.
/// When this property is true, plugins handling this query should avoid serving cached results.
/// </summary>
public bool IsReQuery { get; internal set; } = false;

/// <summary>
/// Search part of a query.
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
Expand Down
4 changes: 4 additions & 0 deletions Flow.Launcher/MainWindow.xaml
Expand Up @@ -86,6 +86,10 @@
Key="O"
Command="{Binding LoadContextMenuCommand}"
Modifiers="Ctrl" />
<KeyBinding
Key="R"
Command="{Binding ReQueryCommand}"
Modifiers="Ctrl" />
<KeyBinding
Key="H"
Command="{Binding LoadHistoryCommand}"
Expand Down
25 changes: 18 additions & 7 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Expand Up @@ -205,6 +205,15 @@ private void LoadHistory()
}
}

[RelayCommand]
private void ReQuery()
{
if (SelectedIsFromQueryResults())
{
QueryResults(isReQuery: true);
}
}

[RelayCommand]
private void LoadContextMenu()
{
Expand Down Expand Up @@ -495,8 +504,8 @@ private void UpdatePreview()
/// but we don't want to move cursor to end when query is updated from TextBox
/// </summary>
/// <param name="queryText"></param>
/// <param name="reQuery">Force query even when Query Text doesn't change</param>
public void ChangeQueryText(string queryText, bool reQuery = false)
/// <param name="isReQuery">Force query even when Query Text doesn't change</param>
public void ChangeQueryText(string queryText, bool isReQuery = false)
{
Application.Current.Dispatcher.Invoke(() =>
{
Expand All @@ -510,9 +519,9 @@ public void ChangeQueryText(string queryText, bool reQuery = false)
QueryTextCursorMovedToEnd = false;
}
else if (reQuery)
else if (isReQuery)
{
Query();
Query(isReQuery: true);
}
QueryTextCursorMovedToEnd = true;
});
Expand Down Expand Up @@ -612,11 +621,11 @@ public string PreviewHotkey

#region Query

public void Query()
public void Query(bool isReQuery = false)
{
if (SelectedIsFromQueryResults())
{
QueryResults();
QueryResults(isReQuery);
}
else if (ContextMenuSelected())
{
Expand Down Expand Up @@ -716,7 +725,7 @@ private void QueryHistory()

private readonly IReadOnlyList<Result> _emptyResult = new List<Result>();

private async void QueryResults()
private async void QueryResults(bool isReQuery = false)
{
_updateSource?.Cancel();

Expand Down Expand Up @@ -747,6 +756,8 @@ private async void QueryResults()
if (currentCancellationToken.IsCancellationRequested)
return;

// Update the query's IsReQuery property to true if this is a re-query
query.IsReQuery = isReQuery;

// handle the exclusiveness of plugin using action keyword
RemoveOldQueryResults(query);
Expand Down

0 comments on commit 0047d8a

Please sign in to comment.