Skip to content

Commit b297f3d

Browse files
authored
Fix ArgumentOutOfRangeException in WebSearch Plugin (#4041)
1 parent 5ae159d commit b297f3d

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ private void CustomHotkeyEdit()
8989
if (window.ShowDialog() is not true) return;
9090

9191
var index = Settings.CustomPluginHotkeys.IndexOf(settingItem);
92-
Settings.CustomPluginHotkeys[index] = new CustomPluginHotkey(window.Hotkey, window.ActionKeyword);
93-
HotKeyMapper.RemoveHotkey(settingItem.Hotkey); // remove origin hotkey
94-
HotKeyMapper.SetCustomQueryHotkey(Settings.CustomPluginHotkeys[index]); // set new hotkey
92+
if (index >= 0 && index < Settings.CustomPluginHotkeys.Count)
93+
{
94+
Settings.CustomPluginHotkeys[index] = new CustomPluginHotkey(window.Hotkey, window.ActionKeyword);
95+
HotKeyMapper.RemoveHotkey(settingItem.Hotkey); // remove origin hotkey
96+
HotKeyMapper.SetCustomQueryHotkey(Settings.CustomPluginHotkeys[index]); // set new hotkey
97+
}
9598
}
9699

97100
[RelayCommand]
@@ -150,7 +153,10 @@ private void CustomShortcutEdit()
150153
if (window.ShowDialog() is not true) return;
151154

152155
var index = Settings.CustomShortcuts.IndexOf(settingItem);
153-
Settings.CustomShortcuts[index] = new CustomShortcutModel(window.Key, window.Value);
156+
if (index >= 0 && index < Settings.CustomShortcuts.Count)
157+
{
158+
Settings.CustomShortcuts[index] = new CustomShortcutModel(window.Key, window.Value);
159+
}
154160
}
155161

156162
[RelayCommand]

Plugins/Flow.Launcher.Plugin.WebSearch/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<system:String x:Key="flowlauncher_plugin_websearch_input_url">Please enter a URL</system:String>
4848
<system:String x:Key="flowlauncher_plugin_websearch_action_keyword_exist">Action keyword already exists, please enter a different one</system:String>
4949
<system:String x:Key="flowlauncher_plugin_websearch_succeed">Success</system:String>
50+
<system:String x:Key="flowlauncher_plugin_websearch_edit_failed">Failed to update search source. The item may have been removed.</system:String>
5051
<system:String x:Key="flowlauncher_plugin_websearch_iconpath_hint">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.</system:String>
5152

5253
<system:String x:Key="flowlauncher_plugin_websearch_plugin_name">Web Searches</system:String>

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,19 @@ private void EditSearchSource()
108108
_context.API.AddActionKeyword(id, newKeyword);
109109

110110
var index = _searchSources.IndexOf(_oldSearchSource);
111-
_searchSources[index] = _searchSource;
112-
113-
Close();
111+
112+
// Only update if we found the item in the collection
113+
if (index >= 0 && index < _searchSources.Count)
114+
{
115+
_searchSources[index] = _searchSource;
116+
Close();
117+
}
118+
else
119+
{
120+
var warning = _api.GetTranslation("flowlauncher_plugin_websearch_edit_failed");
121+
_context.API.ShowMsgBox(warning);
122+
Close();
123+
}
114124
}
115125
else
116126
{

0 commit comments

Comments
 (0)