Merge pull request #2585 from Flow-Launcher/longest-shortcut

match longest shortcut by default
This commit is contained in:
Jeremy Wu 2024-03-27 14:12:36 +11:00 committed by GitHub
commit 7161603856
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -176,7 +176,8 @@ namespace Flow.Launcher.ViewModel
var token = e.Token == default ? _updateToken : e.Token;
PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query);
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(e.Results, pair.Metadata, e.Query, token)))
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(e.Results, pair.Metadata, e.Query,
token)))
{
Log.Error("MainViewModel", "Unable to add item to Result Update Queue");
}
@ -190,7 +191,8 @@ namespace Flow.Launcher.ViewModel
Hide();
await PluginManager.ReloadDataAsync().ConfigureAwait(false);
Notification.Show(InternationalizationManager.Instance.GetTranslation("success"), InternationalizationManager.Instance.GetTranslation("completedSuccessfully"));
Notification.Show(InternationalizationManager.Instance.GetTranslation("success"),
InternationalizationManager.Instance.GetTranslation("completedSuccessfully"));
}
[RelayCommand]
@ -265,6 +267,7 @@ namespace Flow.Launcher.ViewModel
{
autoCompleteText = $"{result.ActionKeywordAssigned} {defaultSuggestion}";
}
autoCompleteText = SelectedResults.SelectedItem.QuerySuggestionText;
}
@ -286,11 +289,13 @@ namespace Flow.Launcher.ViewModel
{
results.SelectedIndex = int.Parse(index);
}
var result = results.SelectedItem?.Result;
if (result == null)
{
return;
}
var hideWindow = await result.ExecuteAsync(new ActionContext
{
// not null means pressing modifier key + number, should ignore the modifier key
@ -414,6 +419,7 @@ namespace Flow.Launcher.ViewModel
public bool GameModeStatus { get; set; } = false;
private string _queryText;
public string QueryText
{
get => _queryText;
@ -437,6 +443,7 @@ namespace Flow.Launcher.ViewModel
Settings.WindowSize += 100;
Settings.WindowLeft -= 50;
}
OnPropertyChanged();
}
@ -452,6 +459,7 @@ namespace Flow.Launcher.ViewModel
Settings.WindowLeft += 50;
Settings.WindowSize -= 100;
}
OnPropertyChanged();
}
@ -531,18 +539,17 @@ namespace Flow.Launcher.ViewModel
{
if (QueryText != queryText)
{
// re-query is done in QueryText's setter method
QueryText = queryText;
// set to false so the subsequent set true triggers
// PropertyChanged and MoveQueryTextToEnd is called
QueryTextCursorMovedToEnd = false;
}
else if (isReQuery)
{
Query(isReQuery: true);
}
QueryTextCursorMovedToEnd = true;
});
}
@ -612,8 +619,8 @@ namespace Flow.Launcher.ViewModel
public string OpenResultCommandModifiers => Settings.OpenResultModifiers;
public string PreviewHotkey
{
public string PreviewHotkey
{
get
{
// TODO try to patch issue #1755
@ -627,6 +634,7 @@ namespace Flow.Launcher.ViewModel
{
Settings.PreviewHotkey = "F1";
}
return Settings.PreviewHotkey;
}
}
@ -695,7 +703,6 @@ namespace Flow.Launcher.ViewModel
results.Add(ContextMenuTopMost(selected));
results.Add(ContextMenuPluginInfo(selected.PluginID));
}
if (!string.IsNullOrEmpty(query))
@ -714,7 +721,6 @@ namespace Flow.Launcher.ViewModel
r.Score = match.Score;
return true;
}).ToList();
ContextMenu.AddResults(filtered, id);
}
@ -741,10 +747,7 @@ namespace Flow.Launcher.ViewModel
Title = string.Format(title, h.Query),
SubTitle = string.Format(time, h.ExecutedDateTime),
IcoPath = "Images\\history.png",
OriginQuery = new Query
{
RawQuery = h.Query
},
OriginQuery = new Query { RawQuery = h.Query },
Action = _ =>
{
SelectedResults = Results;
@ -881,20 +884,23 @@ namespace Flow.Launcher.ViewModel
// Task.Yield will force it to run in ThreadPool
await Task.Yield();
IReadOnlyList<Result> results = await PluginManager.QueryForPluginAsync(plugin, query, currentCancellationToken);
IReadOnlyList<Result> results =
await PluginManager.QueryForPluginAsync(plugin, query, currentCancellationToken);
currentCancellationToken.ThrowIfCancellationRequested();
results ??= _emptyResult;
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(results, plugin.Metadata, query, currentCancellationToken)))
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(results, plugin.Metadata, query,
currentCancellationToken)))
{
Log.Error("MainViewModel", "Unable to add item to Result Update Queue");
}
}
}
private Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel> customShortcuts, IEnumerable<BuiltinShortcutModel> builtInShortcuts)
private Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel> customShortcuts,
IEnumerable<BuiltinShortcutModel> builtInShortcuts)
{
if (string.IsNullOrWhiteSpace(queryText))
{
@ -904,7 +910,8 @@ namespace Flow.Launcher.ViewModel
StringBuilder queryBuilder = new(queryText);
StringBuilder queryBuilderTmp = new(queryText);
foreach (var shortcut in customShortcuts)
// Sorting order is important here, the reason is for matching longest shortcut by default
foreach (var shortcut in customShortcuts.OrderByDescending(x => x.Key.Length))
{
if (queryBuilder.Equals(shortcut.Key))
{
@ -931,7 +938,9 @@ namespace Flow.Launcher.ViewModel
}
catch (Exception e)
{
Log.Exception($"{nameof(MainViewModel)}.{nameof(ConstructQuery)}|Error when expanding shortcut {shortcut.Key}", e);
Log.Exception(
$"{nameof(MainViewModel)}.{nameof(ConstructQuery)}|Error when expanding shortcut {shortcut.Key}",
e);
}
}
});
@ -1076,6 +1085,7 @@ namespace Flow.Launcher.ViewModel
{
SelectedResults = Results;
}
switch (Settings.LastQueryMode)
{
case LastQueryMode.Empty: