From 88b3ae20d522a80c5e3c65b38c4b69bddbaadd56 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 04:06:19 +0000 Subject: [PATCH 1/5] Initial plan From e015a9876ac5035b43e276288a63700537625269 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 04:09:38 +0000 Subject: [PATCH 2/5] Fix ArgumentOutOfRangeException in WebSearch Plugin Edit Search Source Add bounds checking and fallback logic to handle cases where the search source reference is not found in the collection. This prevents the crash when editing a search source that may have been modified or removed from the collection. Co-authored-by: Jack251970 <53996452+Jack251970@users.noreply.github.com> --- .../SearchSourceSetting.xaml.cs | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs index acc2c1e5c2c..587475b9587 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs @@ -108,9 +108,29 @@ private void EditSearchSource() _context.API.AddActionKeyword(id, newKeyword); var index = _searchSources.IndexOf(_oldSearchSource); - _searchSources[index] = _searchSource; - - Close(); + + // If the old search source is not found by reference, try to find it by ActionKeyword + if (index == -1) + { + index = _searchSources.ToList().FindIndex(s => s.ActionKeyword == oldKeyword); + } + + // Only update if we found the item in the collection + if (index >= 0 && index < _searchSources.Count) + { + _searchSources[index] = _searchSource; + Close(); + } + else + { + var warning = _api.GetTranslation("flowlauncher_plugin_websearch_edit_failed"); + if (string.IsNullOrEmpty(warning)) + { + warning = "Failed to update search source. The item may have been removed."; + } + _context.API.ShowMsgBox(warning); + Close(); + } } else { From 6a7f96b2f8b8c313bc375ca43f9078bd54b9023c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 04:11:37 +0000 Subject: [PATCH 3/5] Add bounds checking to prevent IndexOutOfRange exceptions in hotkey settings Add defensive programming checks to CustomHotkeyEdit and CustomShortcutEdit methods to prevent potential IndexOutOfRangeException in rare edge cases where collection might be modified concurrently. Co-authored-by: Jack251970 <53996452+Jack251970@users.noreply.github.com> --- .../ViewModels/SettingsPaneHotkeyViewModel.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs index 3e7c3cb8361..2ec69e81a5f 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs @@ -89,9 +89,12 @@ private void CustomHotkeyEdit() if (window.ShowDialog() is not true) return; var index = Settings.CustomPluginHotkeys.IndexOf(settingItem); - Settings.CustomPluginHotkeys[index] = new CustomPluginHotkey(window.Hotkey, window.ActionKeyword); - HotKeyMapper.RemoveHotkey(settingItem.Hotkey); // remove origin hotkey - HotKeyMapper.SetCustomQueryHotkey(Settings.CustomPluginHotkeys[index]); // set new hotkey + if (index >= 0 && index < Settings.CustomPluginHotkeys.Count) + { + Settings.CustomPluginHotkeys[index] = new CustomPluginHotkey(window.Hotkey, window.ActionKeyword); + HotKeyMapper.RemoveHotkey(settingItem.Hotkey); // remove origin hotkey + HotKeyMapper.SetCustomQueryHotkey(Settings.CustomPluginHotkeys[index]); // set new hotkey + } } [RelayCommand] @@ -150,7 +153,10 @@ private void CustomShortcutEdit() if (window.ShowDialog() is not true) return; var index = Settings.CustomShortcuts.IndexOf(settingItem); - Settings.CustomShortcuts[index] = new CustomShortcutModel(window.Key, window.Value); + if (index >= 0 && index < Settings.CustomShortcuts.Count) + { + Settings.CustomShortcuts[index] = new CustomShortcutModel(window.Key, window.Value); + } } [RelayCommand] From c2f3e9e48bbaff621861429cf1c055b9bf9ac667 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 10 Oct 2025 12:20:13 +0800 Subject: [PATCH 4/5] Add localized error message for search source update Added a new localized string `flowlauncher_plugin_websearch_edit_failed` in `en.xaml` for handling errors when updating a search source. Updated `SearchSourceSetting.xaml.cs` to use this localized string and removed fallback logic for default error messages. --- Plugins/Flow.Launcher.Plugin.WebSearch/Languages/en.xaml | 1 + .../SearchSourceSetting.xaml.cs | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.WebSearch/Languages/en.xaml index c6a74a0470a..5d65e4462dd 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/Languages/en.xaml @@ -47,6 +47,7 @@ Please enter a URL Action keyword already exists, please enter a different one Success + Failed to update search source. The item may have been removed. Hint: You do not need to place custom images in this directory, if Flow's version is updated they will be lost. Flow will automatically copy any images outside of this directory across to WebSearch's custom image location. Web Searches diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs index 587475b9587..53b7b5a1d5c 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs @@ -124,10 +124,6 @@ private void EditSearchSource() else { var warning = _api.GetTranslation("flowlauncher_plugin_websearch_edit_failed"); - if (string.IsNullOrEmpty(warning)) - { - warning = "Failed to update search source. The item may have been removed."; - } _context.API.ShowMsgBox(warning); Close(); } From fc31cf37395a18f0c4f4bfd57c41186d7d8deb22 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 10 Oct 2025 12:21:49 +0800 Subject: [PATCH 5/5] Simplify search source update logic Removed fallback mechanism for locating a search source by `ActionKeyword` when not found by reference. The update now proceeds only if the search source is found by reference, streamlining the logic and reducing complexity. --- .../SearchSourceSetting.xaml.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs index 53b7b5a1d5c..9508d61a0cf 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs @@ -109,12 +109,6 @@ private void EditSearchSource() var index = _searchSources.IndexOf(_oldSearchSource); - // If the old search source is not found by reference, try to find it by ActionKeyword - if (index == -1) - { - index = _searchSources.ToList().FindIndex(s => s.ActionKeyword == oldKeyword); - } - // Only update if we found the item in the collection if (index >= 0 && index < _searchSources.Count) {