Fix potential issue with index boundary in Delete command

This commit is contained in:
Jack251970 2025-05-21 18:37:52 +08:00
parent 5578daaa3e
commit 45b81811f7
2 changed files with 12 additions and 6 deletions

View file

@ -53,6 +53,11 @@ public partial class SelectBrowserViewModel : BaseModel
[RelayCommand]
private void Delete()
{
CustomBrowsers.RemoveAt(SelectedCustomBrowserIndex--);
var currentIndex = SelectedCustomBrowserIndex;
if (currentIndex >= 0 && currentIndex < CustomBrowsers.Count)
{
CustomBrowsers.RemoveAt(currentIndex);
SelectedCustomBrowserIndex = currentIndex > 0 ? currentIndex - 1 : 0;
}
}
}

View file

@ -3,14 +3,10 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using ModernWpf.Controls;
namespace Flow.Launcher.ViewModel;
@ -115,6 +111,11 @@ public partial class SelectFileManagerViewModel : BaseModel
[RelayCommand]
private void Delete()
{
CustomExplorers.RemoveAt(SelectedCustomExplorerIndex--);
var currentIndex = SelectedCustomExplorerIndex;
if (currentIndex >= 0 && currentIndex < CustomExplorers.Count)
{
CustomExplorers.RemoveAt(currentIndex);
SelectedCustomExplorerIndex = currentIndex > 0 ? currentIndex - 1 : 0;
}
}
}