Skip to content

Commit 3ddf0cf

Browse files
committed
match longest shortcut by default
1 parent c7bb633 commit 3ddf0cf

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ private void RegisterResultsUpdatedEvent()
176176
var token = e.Token == default ? _updateToken : e.Token;
177177

178178
PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query);
179-
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(e.Results, pair.Metadata, e.Query, token)))
179+
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(e.Results, pair.Metadata, e.Query,
180+
token)))
180181
{
181182
Log.Error("MainViewModel", "Unable to add item to Result Update Queue");
182183
}
@@ -190,7 +191,8 @@ private async Task ReloadPluginDataAsync()
190191
Hide();
191192

192193
await PluginManager.ReloadDataAsync().ConfigureAwait(false);
193-
Notification.Show(InternationalizationManager.Instance.GetTranslation("success"), InternationalizationManager.Instance.GetTranslation("completedSuccessfully"));
194+
Notification.Show(InternationalizationManager.Instance.GetTranslation("success"),
195+
InternationalizationManager.Instance.GetTranslation("completedSuccessfully"));
194196
}
195197

196198
[RelayCommand]
@@ -265,6 +267,7 @@ private void AutocompleteQuery()
265267
{
266268
autoCompleteText = $"{result.ActionKeywordAssigned} {defaultSuggestion}";
267269
}
270+
268271
autoCompleteText = SelectedResults.SelectedItem.QuerySuggestionText;
269272
}
270273

@@ -286,11 +289,13 @@ private async Task OpenResultAsync(string index)
286289
{
287290
results.SelectedIndex = int.Parse(index);
288291
}
292+
289293
var result = results.SelectedItem?.Result;
290294
if (result == null)
291295
{
292296
return;
293297
}
298+
294299
var hideWindow = await result.ExecuteAsync(new ActionContext
295300
{
296301
// not null means pressing modifier key + number, should ignore the modifier key
@@ -403,6 +408,7 @@ private async Task RegisterClockAndDateUpdateAsync()
403408
public bool GameModeStatus { get; set; } = false;
404409

405410
private string _queryText;
411+
406412
public string QueryText
407413
{
408414
get => _queryText;
@@ -426,6 +432,7 @@ private void IncreaseWidth()
426432
Settings.WindowSize += 100;
427433
Settings.WindowLeft -= 50;
428434
}
435+
429436
OnPropertyChanged();
430437
}
431438

@@ -441,6 +448,7 @@ private void DecreaseWidth()
441448
Settings.WindowLeft += 50;
442449
Settings.WindowSize -= 100;
443450
}
451+
444452
OnPropertyChanged();
445453
}
446454

@@ -520,18 +528,17 @@ public void ChangeQueryText(string queryText, bool isReQuery = false)
520528
{
521529
if (QueryText != queryText)
522530
{
523-
524531
// re-query is done in QueryText's setter method
525532
QueryText = queryText;
526533
// set to false so the subsequent set true triggers
527534
// PropertyChanged and MoveQueryTextToEnd is called
528535
QueryTextCursorMovedToEnd = false;
529-
530536
}
531537
else if (isReQuery)
532538
{
533539
Query(isReQuery: true);
534540
}
541+
535542
QueryTextCursorMovedToEnd = true;
536543
});
537544
}
@@ -601,8 +608,8 @@ public double MainWindowWidth
601608

602609
public string OpenResultCommandModifiers => Settings.OpenResultModifiers;
603610

604-
public string PreviewHotkey
605-
{
611+
public string PreviewHotkey
612+
{
606613
get
607614
{
608615
// TODO try to patch issue #1755
@@ -616,6 +623,7 @@ public string PreviewHotkey
616623
{
617624
Settings.PreviewHotkey = "F1";
618625
}
626+
619627
return Settings.PreviewHotkey;
620628
}
621629
}
@@ -684,7 +692,6 @@ private void QueryContextMenu()
684692
results.Add(ContextMenuTopMost(selected));
685693
results.Add(ContextMenuPluginInfo(selected.PluginID));
686694
}
687-
688695

689696

690697
if (!string.IsNullOrEmpty(query))
@@ -703,7 +710,6 @@ private void QueryContextMenu()
703710

704711
r.Score = match.Score;
705712
return true;
706-
707713
}).ToList();
708714
ContextMenu.AddResults(filtered, id);
709715
}
@@ -730,10 +736,7 @@ private void QueryHistory()
730736
Title = string.Format(title, h.Query),
731737
SubTitle = string.Format(time, h.ExecutedDateTime),
732738
IcoPath = "Images\\history.png",
733-
OriginQuery = new Query
734-
{
735-
RawQuery = h.Query
736-
},
739+
OriginQuery = new Query { RawQuery = h.Query },
737740
Action = _ =>
738741
{
739742
SelectedResults = Results;
@@ -870,20 +873,23 @@ async Task QueryTask(PluginPair plugin)
870873
// Task.Yield will force it to run in ThreadPool
871874
await Task.Yield();
872875

873-
IReadOnlyList<Result> results = await PluginManager.QueryForPluginAsync(plugin, query, currentCancellationToken);
876+
IReadOnlyList<Result> results =
877+
await PluginManager.QueryForPluginAsync(plugin, query, currentCancellationToken);
874878

875879
currentCancellationToken.ThrowIfCancellationRequested();
876880

877881
results ??= _emptyResult;
878882

879-
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(results, plugin.Metadata, query, currentCancellationToken)))
883+
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(results, plugin.Metadata, query,
884+
currentCancellationToken)))
880885
{
881886
Log.Error("MainViewModel", "Unable to add item to Result Update Queue");
882887
}
883888
}
884889
}
885890

886-
private Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel> customShortcuts, IEnumerable<BuiltinShortcutModel> builtInShortcuts)
891+
private Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel> customShortcuts,
892+
IEnumerable<BuiltinShortcutModel> builtInShortcuts)
887893
{
888894
if (string.IsNullOrWhiteSpace(queryText))
889895
{
@@ -893,7 +899,7 @@ private Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel>
893899
StringBuilder queryBuilder = new(queryText);
894900
StringBuilder queryBuilderTmp = new(queryText);
895901

896-
foreach (var shortcut in customShortcuts)
902+
foreach (var shortcut in customShortcuts.OrderByDescending(x => x.Key.Length))
897903
{
898904
if (queryBuilder.Equals(shortcut.Key))
899905
{
@@ -920,7 +926,9 @@ private Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel>
920926
}
921927
catch (Exception e)
922928
{
923-
Log.Exception($"{nameof(MainViewModel)}.{nameof(ConstructQuery)}|Error when expanding shortcut {shortcut.Key}", e);
929+
Log.Exception(
930+
$"{nameof(MainViewModel)}.{nameof(ConstructQuery)}|Error when expanding shortcut {shortcut.Key}",
931+
e);
924932
}
925933
}
926934
});
@@ -1065,6 +1073,7 @@ public async void Hide()
10651073
{
10661074
SelectedResults = Results;
10671075
}
1076+
10681077
switch (Settings.LastQueryMode)
10691078
{
10701079
case LastQueryMode.Empty:

0 commit comments

Comments
 (0)