From 89bd28232a466cc2d205e66c2ba7c89257b42e8b Mon Sep 17 00:00:00 2001 From: Benjamin Popp Date: Thu, 7 May 2020 11:01:56 -0500 Subject: [PATCH] Bugfix: limit range during drag interactions don't allow the user to drag before the first position or after the last position. --- src/HexManiac.Core/ViewModels/DexReorderTab.cs | 2 +- src/HexManiac.WPF/Controls/DexReorderView.xaml.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/HexManiac.Core/ViewModels/DexReorderTab.cs b/src/HexManiac.Core/ViewModels/DexReorderTab.cs index 0235cb5e..f33d28d5 100644 --- a/src/HexManiac.Core/ViewModels/DexReorderTab.cs +++ b/src/HexManiac.Core/ViewModels/DexReorderTab.cs @@ -120,7 +120,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels { } public void HandleMove(int originalIndex, int newIndex) { - if (originalIndex == newIndex || originalIndex >= Elements.Count || newIndex >= Elements.Count) return; + if (originalIndex == newIndex) return; var element = Elements[originalIndex]; Elements.RemoveAt(originalIndex); Elements.Insert(newIndex, element); diff --git a/src/HexManiac.WPF/Controls/DexReorderView.xaml.cs b/src/HexManiac.WPF/Controls/DexReorderView.xaml.cs index 7fda68cf..33679bd4 100644 --- a/src/HexManiac.WPF/Controls/DexReorderView.xaml.cs +++ b/src/HexManiac.WPF/Controls/DexReorderView.xaml.cs @@ -35,6 +35,8 @@ namespace HavenSoft.HexManiac.WPF.Controls { var newTileIndex = newTileY * tileWidth + newTileX; var viewModel = (DexReorderTab)DataContext; + oldTileIndex = Math.Min(Math.Max(0, oldTileIndex), Container.Items.Count - 1); + newTileIndex = Math.Min(Math.Max(0, newTileIndex), Container.Items.Count - 1); viewModel.HandleMove(oldTileIndex, newTileIndex); for (int i = oldTileIndex; i < newTileIndex; i++) {