@@ -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
@@ -414,6 +419,7 @@ private async Task RegisterClockAndDateUpdateAsync()
414419 public bool GameModeStatus { get ; set ; } = false ;
415420
416421 private string _queryText ;
422+
417423 public string QueryText
418424 {
419425 get => _queryText ;
@@ -437,6 +443,7 @@ private void IncreaseWidth()
437443 Settings . WindowSize += 100 ;
438444 Settings . WindowLeft -= 50 ;
439445 }
446+
440447 OnPropertyChanged ( ) ;
441448 }
442449
@@ -452,6 +459,7 @@ private void DecreaseWidth()
452459 Settings . WindowLeft += 50 ;
453460 Settings . WindowSize -= 100 ;
454461 }
462+
455463 OnPropertyChanged ( ) ;
456464 }
457465
@@ -531,18 +539,17 @@ public void ChangeQueryText(string queryText, bool isReQuery = false)
531539 {
532540 if ( QueryText != queryText )
533541 {
534-
535542 // re-query is done in QueryText's setter method
536543 QueryText = queryText ;
537544 // set to false so the subsequent set true triggers
538545 // PropertyChanged and MoveQueryTextToEnd is called
539546 QueryTextCursorMovedToEnd = false ;
540-
541547 }
542548 else if ( isReQuery )
543549 {
544550 Query ( isReQuery : true ) ;
545551 }
552+
546553 QueryTextCursorMovedToEnd = true ;
547554 } ) ;
548555 }
@@ -612,8 +619,8 @@ public double MainWindowWidth
612619
613620 public string OpenResultCommandModifiers => Settings . OpenResultModifiers ;
614621
615- public string PreviewHotkey
616- {
622+ public string PreviewHotkey
623+ {
617624 get
618625 {
619626 // TODO try to patch issue #1755
@@ -627,6 +634,7 @@ public string PreviewHotkey
627634 {
628635 Settings . PreviewHotkey = "F1" ;
629636 }
637+
630638 return Settings . PreviewHotkey ;
631639 }
632640 }
@@ -695,7 +703,6 @@ private void QueryContextMenu()
695703 results . Add ( ContextMenuTopMost ( selected ) ) ;
696704 results . Add ( ContextMenuPluginInfo ( selected . PluginID ) ) ;
697705 }
698-
699706
700707
701708 if ( ! string . IsNullOrEmpty ( query ) )
@@ -714,7 +721,6 @@ private void QueryContextMenu()
714721
715722 r . Score = match . Score ;
716723 return true ;
717-
718724 } ) . ToList ( ) ;
719725 ContextMenu . AddResults ( filtered , id ) ;
720726 }
@@ -741,10 +747,7 @@ private void QueryHistory()
741747 Title = string . Format ( title , h . Query ) ,
742748 SubTitle = string . Format ( time , h . ExecutedDateTime ) ,
743749 IcoPath = "Images\\ history.png" ,
744- OriginQuery = new Query
745- {
746- RawQuery = h . Query
747- } ,
750+ OriginQuery = new Query { RawQuery = h . Query } ,
748751 Action = _ =>
749752 {
750753 SelectedResults = Results ;
@@ -881,20 +884,23 @@ async Task QueryTask(PluginPair plugin)
881884 // Task.Yield will force it to run in ThreadPool
882885 await Task . Yield ( ) ;
883886
884- IReadOnlyList < Result > results = await PluginManager . QueryForPluginAsync ( plugin , query , currentCancellationToken ) ;
887+ IReadOnlyList < Result > results =
888+ await PluginManager . QueryForPluginAsync ( plugin , query , currentCancellationToken ) ;
885889
886890 currentCancellationToken . ThrowIfCancellationRequested ( ) ;
887891
888892 results ??= _emptyResult ;
889893
890- if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( results , plugin . Metadata , query , currentCancellationToken ) ) )
894+ if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( results , plugin . Metadata , query ,
895+ currentCancellationToken ) ) )
891896 {
892897 Log . Error ( "MainViewModel" , "Unable to add item to Result Update Queue" ) ;
893898 }
894899 }
895900 }
896901
897- private Query ConstructQuery ( string queryText , IEnumerable < CustomShortcutModel > customShortcuts , IEnumerable < BuiltinShortcutModel > builtInShortcuts )
902+ private Query ConstructQuery ( string queryText , IEnumerable < CustomShortcutModel > customShortcuts ,
903+ IEnumerable < BuiltinShortcutModel > builtInShortcuts )
898904 {
899905 if ( string . IsNullOrWhiteSpace ( queryText ) )
900906 {
@@ -904,7 +910,8 @@ private Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel>
904910 StringBuilder queryBuilder = new ( queryText ) ;
905911 StringBuilder queryBuilderTmp = new ( queryText ) ;
906912
907- foreach ( var shortcut in customShortcuts )
913+ // Sorting order is important here, the reason is for matching longest shortcut by default
914+ foreach ( var shortcut in customShortcuts . OrderByDescending ( x => x . Key . Length ) )
908915 {
909916 if ( queryBuilder . Equals ( shortcut . Key ) )
910917 {
@@ -931,7 +938,9 @@ private Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel>
931938 }
932939 catch ( Exception e )
933940 {
934- Log . Exception ( $ "{ nameof ( MainViewModel ) } .{ nameof ( ConstructQuery ) } |Error when expanding shortcut { shortcut . Key } ", e ) ;
941+ Log . Exception (
942+ $ "{ nameof ( MainViewModel ) } .{ nameof ( ConstructQuery ) } |Error when expanding shortcut { shortcut . Key } ",
943+ e ) ;
935944 }
936945 }
937946 } ) ;
@@ -1076,6 +1085,7 @@ public async void Hide()
10761085 {
10771086 SelectedResults = Results ;
10781087 }
1088+
10791089 switch ( Settings . LastQueryMode )
10801090 {
10811091 case LastQueryMode . Empty :
0 commit comments