Skip to content

Commit 45b8181

Browse files
committed
Fix potential issue with index boundary in Delete command
1 parent 5578daa commit 45b8181

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Flow.Launcher/ViewModel/SelectBrowserViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ private void Add()
5353
[RelayCommand]
5454
private void Delete()
5555
{
56-
CustomBrowsers.RemoveAt(SelectedCustomBrowserIndex--);
56+
var currentIndex = SelectedCustomBrowserIndex;
57+
if (currentIndex >= 0 && currentIndex < CustomBrowsers.Count)
58+
{
59+
CustomBrowsers.RemoveAt(currentIndex);
60+
SelectedCustomBrowserIndex = currentIndex > 0 ? currentIndex - 1 : 0;
61+
}
5762
}
5863
}

Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.Linq;
6-
using System.Threading.Tasks;
76
using System.Windows;
8-
using System.Windows.Controls;
9-
using System.Windows.Documents;
107
using CommunityToolkit.Mvvm.Input;
118
using Flow.Launcher.Infrastructure.UserSettings;
129
using Flow.Launcher.Plugin;
13-
using ModernWpf.Controls;
1410

1511
namespace Flow.Launcher.ViewModel;
1612

@@ -115,6 +111,11 @@ private void Add()
115111
[RelayCommand]
116112
private void Delete()
117113
{
118-
CustomExplorers.RemoveAt(SelectedCustomExplorerIndex--);
114+
var currentIndex = SelectedCustomExplorerIndex;
115+
if (currentIndex >= 0 && currentIndex < CustomExplorers.Count)
116+
{
117+
CustomExplorers.RemoveAt(currentIndex);
118+
SelectedCustomExplorerIndex = currentIndex > 0 ? currentIndex - 1 : 0;
119+
}
119120
}
120121
}

0 commit comments

Comments
 (0)