diff --git a/Editors/MetaDataEditor/AnimationMeta/MetaEditor/Commands/DeleteEntryCommand.cs b/Editors/MetaDataEditor/AnimationMeta/MetaEditor/Commands/DeleteEntryCommand.cs index b5274cdf..269acbaf 100644 --- a/Editors/MetaDataEditor/AnimationMeta/MetaEditor/Commands/DeleteEntryCommand.cs +++ b/Editors/MetaDataEditor/AnimationMeta/MetaEditor/Commands/DeleteEntryCommand.cs @@ -7,26 +7,14 @@ internal class DeleteEntryCommand : IUiCommand { public void Execute(MetaDataEditorViewModel controller) { - if (controller.ParsedFile == null) return; - - // Get all selected items from the UI tags - var itemsToRemove = controller.Tags - .Where(x => x.IsSelected) - .Select(x => x._input) - .ToList(); - - if (!itemsToRemove.Any()) return; - - // Batch remove all selected tags - foreach (var item in itemsToRemove) - { - controller.ParsedFile.Attributes.Remove(item); - } + var itemToRemove = controller.SelectedAttribute; + if (itemToRemove == null || controller.ParsedFile == null) + return; + controller.ParsedFile.Attributes.Remove(itemToRemove); controller.UpdateView(); - - // Select the first item by default after deletion controller.SelectedTag = controller.Tags.FirstOrDefault(); } + } } diff --git a/Editors/MetaDataEditor/AnimationMeta/MetaEditor/Commands/MoveEntryCommand.cs b/Editors/MetaDataEditor/AnimationMeta/MetaEditor/Commands/MoveEntryCommand.cs index 1f8ffc1a..d111d822 100644 --- a/Editors/MetaDataEditor/AnimationMeta/MetaEditor/Commands/MoveEntryCommand.cs +++ b/Editors/MetaDataEditor/AnimationMeta/MetaEditor/Commands/MoveEntryCommand.cs @@ -7,96 +7,39 @@ internal class MoveEntryCommand : IUiCommand { public void ExecuteUp(MetaDataEditorViewModel controller) { - if (controller.ParsedFile == null) return; - - var itemsToMove = controller.Tags - .Where(x => x.IsSelected) - .Select(x => x._input) - .ToList(); - - if (!itemsToMove.Any()) return; - - var attributes = controller.ParsedFile.Attributes; - - // Sort ascending to move top items first, preventing them from jumping over each other - var sortedItems = itemsToMove.OrderBy(x => attributes.IndexOf(x)).ToList(); - bool moved = false; - - foreach (var item in sortedItems) - { - var currentIndex = attributes.IndexOf(item); - if (currentIndex > 0) - { - // If the item above is also in the selection, keep them as a block - var itemAbove = attributes[currentIndex - 1]; - if (!itemsToMove.Contains(itemAbove)) - { - attributes.RemoveAt(currentIndex); - attributes.Insert(currentIndex - 1, item); - moved = true; - } - } - } - - if (moved) - { - controller.UpdateView(); - - // Restore selection state for the moved items - foreach (var tag in controller.Tags.Where(t => itemsToMove.Contains(t._input))) - { - tag.IsSelected = true; - } - - controller.SelectedTag = controller.Tags.FirstOrDefault(x => x.IsSelected); - } + var itemToMove = controller.SelectedAttribute; + if (itemToMove == null || controller.ParsedFile == null) + return; + + var currentIndex = controller.ParsedFile.Attributes.IndexOf(itemToMove); + if (currentIndex == 0) + return; + + controller.ParsedFile.Attributes.Remove(itemToMove); + controller.ParsedFile.Attributes.Insert(currentIndex - 1, itemToMove); + controller.UpdateView(); + controller.SelectedTag = controller.Tags + .Where(x => x._input == itemToMove) + .FirstOrDefault(); } public void ExecuteDown(MetaDataEditorViewModel controller) { - if (controller.ParsedFile == null) return; - - var itemsToMove = controller.Tags - .Where(x => x.IsSelected) - .Select(x => x._input) - .ToList(); - - if (!itemsToMove.Any()) return; - - var attributes = controller.ParsedFile.Attributes; - - // Sort descending to move bottom items first - var sortedItems = itemsToMove.OrderByDescending(x => attributes.IndexOf(x)).ToList(); - bool moved = false; - - foreach (var item in sortedItems) - { - var currentIndex = attributes.IndexOf(item); - if (currentIndex < attributes.Count - 1) - { - // If the item below is also in the selection, keep them as a block - var itemBelow = attributes[currentIndex + 1]; - if (!itemsToMove.Contains(itemBelow)) - { - attributes.RemoveAt(currentIndex); - attributes.Insert(currentIndex + 1, item); - moved = true; - } - } - } + var itemToMove = controller.SelectedAttribute; + if (itemToMove == null || controller.ParsedFile == null) + return; - if (moved) - { - controller.UpdateView(); + var currentIndex = controller.ParsedFile.Attributes.IndexOf(itemToMove); + if (currentIndex == controller.ParsedFile.Attributes.Count -1) + return; - // Restore selection state for the moved items - foreach (var tag in controller.Tags.Where(t => itemsToMove.Contains(t._input))) - { - tag.IsSelected = true; - } + controller.ParsedFile.Attributes.Remove(itemToMove); + controller.ParsedFile.Attributes.Insert(currentIndex + 1, itemToMove); + controller.UpdateView(); + controller.SelectedTag = controller.Tags + .Where(x => x._input == itemToMove) + .FirstOrDefault(); - controller.SelectedTag = controller.Tags.FirstOrDefault(x => x.IsSelected); - } } } }