From 93ce99f8d95aebe04923534d7675a57b38224e45 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Tue, 23 Jan 2024 19:51:25 -0500 Subject: [PATCH 1/2] Avoid re-building context result is unchanged --- Flow.Launcher/ViewModel/MainViewModel.cs | 33 +++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 61bf0c4dc..676791790 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -34,6 +34,8 @@ namespace Flow.Launcher.ViewModel private bool _isQueryRunning; private Query _lastQuery; + private Result lastContextMenuResult = new Result(); + private List lastContextMenuResults = new List(); private string _queryTextBeforeLeaveResults; private readonly FlowLauncherJsonStorage _historyItemsStorage; @@ -650,9 +652,34 @@ namespace Flow.Launcher.ViewModel if (selected != null) // SelectedItem returns null if selection is empty. { - var results = PluginManager.GetContextMenusForPlugin(selected); - results.Add(ContextMenuTopMost(selected)); - results.Add(ContextMenuPluginInfo(selected.PluginID)); + List results; + if (selected == lastContextMenuResult) + { + // Use copy to keep the original results unchanged + results = lastContextMenuResults.ConvertAll(result => new Result + { + Title = result.Title, + SubTitle = result.SubTitle, + IcoPath = result.IcoPath, + PluginDirectory = result.PluginDirectory, + Action = result.Action, + ContextData = result.ContextData, + Glyph = result.Glyph, + OriginQuery = result.OriginQuery, + Score = result.Score, + AsyncAction = result.AsyncAction, + }); + } + else + { + results = PluginManager.GetContextMenusForPlugin(selected); + lastContextMenuResults = results; + lastContextMenuResult = selected; + results.Add(ContextMenuTopMost(selected)); + results.Add(ContextMenuPluginInfo(selected.PluginID)); + } + + if (!string.IsNullOrEmpty(query)) { From b25c160aefba88f76c8bd57adfa86b522c079d6d Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Tue, 23 Jan 2024 19:51:57 -0500 Subject: [PATCH 2/2] Clear cached context menu when hidden --- Flow.Launcher/ViewModel/MainViewModel.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 676791790..c4b13abb0 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1052,6 +1052,8 @@ namespace Flow.Launcher.ViewModel { // Trick for no delay MainWindowOpacity = 0; + lastContextMenuResult = new Result(); + lastContextMenuResults = new List(); if (!SelectedIsFromQueryResults()) {