Skip to content

Commit 00bb10c

Browse files
Jack251970jjw24
authored andcommitted
Fix ArgumentOutOfRangeException in WebSearch Plugin (#4041)
1 parent 1970a66 commit 00bb10c

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
@@ -91,9 +91,12 @@ private void CustomHotkeyEdit()
9191
if (window.ShowDialog() is not true) return;
9292

9393
var index = Settings.CustomPluginHotkeys.IndexOf(settingItem);
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
94+
if (index >= 0 && index < Settings.CustomPluginHotkeys.Count)
95+
{
96+
Settings.CustomPluginHotkeys[index] = new CustomPluginHotkey(window.Hotkey, window.ActionKeyword);
97+
HotKeyMapper.RemoveHotkey(settingItem.Hotkey); // remove origin hotkey
98+
HotKeyMapper.SetCustomQueryHotkey(Settings.CustomPluginHotkeys[index]); // set new hotkey
99+
}
97100
}
98101

99102
[RelayCommand]
@@ -154,7 +157,10 @@ private void CustomShortcutEdit()
154157
if (window.ShowDialog() is not true) return;
155158

156159
var index = Settings.CustomShortcuts.IndexOf(settingItem);
157-
Settings.CustomShortcuts[index] = new CustomShortcutModel(window.Key, window.Value);
160+
if (index >= 0 && index < Settings.CustomShortcuts.Count)
161+
{
162+
Settings.CustomShortcuts[index] = new CustomShortcutModel(window.Key, window.Value);
163+
}
158164
}
159165

160166
[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)