From 0364fafdf0d57f6eca1396eccf84029d66d4ce3d Mon Sep 17 00:00:00 2001 From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sat, 3 Jan 2026 12:16:30 +0800 Subject: [PATCH 1/2] Recycle items for result list box --- Flow.Launcher/ResultListBox.xaml | 2 +- Flow.Launcher/ResultListBox.xaml.cs | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher/ResultListBox.xaml b/Flow.Launcher/ResultListBox.xaml index e815c873595..825d92d1875 100644 --- a/Flow.Launcher/ResultListBox.xaml +++ b/Flow.Launcher/ResultListBox.xaml @@ -27,7 +27,7 @@ Style="{DynamicResource BaseListboxStyle}" VirtualizingPanel.ScrollUnit="Item" VirtualizingStackPanel.IsVirtualizing="True" - VirtualizingStackPanel.VirtualizationMode="Standard" + VirtualizingStackPanel.VirtualizationMode="Recycling" Visibility="{Binding Visibility}" mc:Ignorable="d"> diff --git a/Flow.Launcher/ResultListBox.xaml.cs b/Flow.Launcher/ResultListBox.xaml.cs index fcc73e9ce1b..f78793bc8ba 100644 --- a/Flow.Launcher/ResultListBox.xaml.cs +++ b/Flow.Launcher/ResultListBox.xaml.cs @@ -12,7 +12,7 @@ public partial class ResultListBox { protected Lock _lock = new(); private Point _lastpos; - private ListBoxItem curItem = null; + private ResultViewModel _currentResult = null; public ResultListBox() { InitializeComponent(); @@ -60,9 +60,12 @@ private void OnMouseEnter(object sender, MouseEventArgs e) { lock (_lock) { - curItem = (ListBoxItem)sender; - var p = e.GetPosition((IInputElement)sender); - _lastpos = p; + if (sender is FrameworkElement { DataContext: ResultViewModel result }) + { + _currentResult = result; + var p = e.GetPosition((IInputElement)sender); + _lastpos = p; + } } } @@ -82,9 +85,9 @@ private void ListBox_PreviewMouseDown(object sender, MouseButtonEventArgs e) { lock (_lock) { - if (curItem != null) + if (_currentResult != null && sender is ListBox listBox) { - curItem.IsSelected = true; + listBox.SelectedItem = _currentResult; } } } From e9fb8c5330ff64f84f3134a95dd46bc7d79ff217 Mon Sep 17 00:00:00 2001 From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sun, 18 Jan 2026 12:09:04 +0800 Subject: [PATCH 2/2] Fix order of hotkey numbers --- .../OpenResultHotkeyVisibilityConverter.cs | 12 +++++++++++- Flow.Launcher/Converters/OrdinalConverter.cs | 17 ++++++++++++++--- Flow.Launcher/ResultListBox.xaml | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/Converters/OpenResultHotkeyVisibilityConverter.cs b/Flow.Launcher/Converters/OpenResultHotkeyVisibilityConverter.cs index 7ab13190a3a..b031dc41cad 100644 --- a/Flow.Launcher/Converters/OpenResultHotkeyVisibilityConverter.cs +++ b/Flow.Launcher/Converters/OpenResultHotkeyVisibilityConverter.cs @@ -17,7 +17,17 @@ public object Convert(object value, Type targetType, object parameter, CultureIn if (value is ListBoxItem listBoxItem && ItemsControl.ItemsControlFromItemContainer(listBoxItem) is ListBox listBox) - number = listBox.ItemContainerGenerator.IndexFromContainer(listBoxItem) + 1; + { + var dataItem = listBoxItem.DataContext; + if (dataItem != null) + { + var index = listBox.Items.IndexOf(dataItem); + if (index >= 0) + { + number = index + 1; + } + } + } return number <= MaxVisibleHotkeys ? Visibility.Visible : Visibility.Collapsed; } diff --git a/Flow.Launcher/Converters/OrdinalConverter.cs b/Flow.Launcher/Converters/OrdinalConverter.cs index 9aed2e07ba3..c07f46a1c01 100644 --- a/Flow.Launcher/Converters/OrdinalConverter.cs +++ b/Flow.Launcher/Converters/OrdinalConverter.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using System.Windows.Controls; using System.Windows.Data; @@ -15,9 +15,20 @@ public object Convert(object value, Type targetType, object parameter, CultureIn return 0; } - var res = listBox.ItemContainerGenerator.IndexFromContainer(listBoxItem) + 1; - return res == 10 ? 0 : res; // 10th item => HOTKEY+0 + var dataItem = listBoxItem.DataContext; + if (dataItem == null) + { + return 0; + } + var index = listBox.Items.IndexOf(dataItem); + if (index < 0) + { + return 0; + } + + var res = index + 1; + return res == 10 ? 0 : res; // 10th item => HOTKEY+0 } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new InvalidOperationException(); diff --git a/Flow.Launcher/ResultListBox.xaml b/Flow.Launcher/ResultListBox.xaml index 825d92d1875..e8e5d8d2130 100644 --- a/Flow.Launcher/ResultListBox.xaml +++ b/Flow.Launcher/ResultListBox.xaml @@ -82,7 +82,7 @@ - +