@@ -7,96 +7,39 @@ internal class MoveEntryCommand : IUiCommand
77 {
88 public void ExecuteUp ( MetaDataEditorViewModel controller )
99 {
10- if ( controller . ParsedFile == null ) return ;
11-
12- var itemsToMove = controller . Tags
13- . Where ( x => x . IsSelected )
14- . Select ( x => x . _input )
15- . ToList ( ) ;
16-
17- if ( ! itemsToMove . Any ( ) ) return ;
18-
19- var attributes = controller . ParsedFile . Attributes ;
20-
21- // Sort ascending to move top items first, preventing them from jumping over each other
22- var sortedItems = itemsToMove . OrderBy ( x => attributes . IndexOf ( x ) ) . ToList ( ) ;
23- bool moved = false ;
24-
25- foreach ( var item in sortedItems )
26- {
27- var currentIndex = attributes . IndexOf ( item ) ;
28- if ( currentIndex > 0 )
29- {
30- // If the item above is also in the selection, keep them as a block
31- var itemAbove = attributes [ currentIndex - 1 ] ;
32- if ( ! itemsToMove . Contains ( itemAbove ) )
33- {
34- attributes . RemoveAt ( currentIndex ) ;
35- attributes . Insert ( currentIndex - 1 , item ) ;
36- moved = true ;
37- }
38- }
39- }
40-
41- if ( moved )
42- {
43- controller . UpdateView ( ) ;
44-
45- // Restore selection state for the moved items
46- foreach ( var tag in controller . Tags . Where ( t => itemsToMove . Contains ( t . _input ) ) )
47- {
48- tag . IsSelected = true ;
49- }
50-
51- controller . SelectedTag = controller . Tags . FirstOrDefault ( x => x . IsSelected ) ;
52- }
10+ var itemToMove = controller . SelectedAttribute ;
11+ if ( itemToMove == null || controller . ParsedFile == null )
12+ return ;
13+
14+ var currentIndex = controller . ParsedFile . Attributes . IndexOf ( itemToMove ) ;
15+ if ( currentIndex == 0 )
16+ return ;
17+
18+ controller . ParsedFile . Attributes . Remove ( itemToMove ) ;
19+ controller . ParsedFile . Attributes . Insert ( currentIndex - 1 , itemToMove ) ;
20+ controller . UpdateView ( ) ;
21+ controller . SelectedTag = controller . Tags
22+ . Where ( x => x . _input == itemToMove )
23+ . FirstOrDefault ( ) ;
5324 }
5425
5526 public void ExecuteDown ( MetaDataEditorViewModel controller )
5627 {
57- if ( controller . ParsedFile == null ) return ;
58-
59- var itemsToMove = controller . Tags
60- . Where ( x => x . IsSelected )
61- . Select ( x => x . _input )
62- . ToList ( ) ;
63-
64- if ( ! itemsToMove . Any ( ) ) return ;
65-
66- var attributes = controller . ParsedFile . Attributes ;
67-
68- // Sort descending to move bottom items first
69- var sortedItems = itemsToMove . OrderByDescending ( x => attributes . IndexOf ( x ) ) . ToList ( ) ;
70- bool moved = false ;
71-
72- foreach ( var item in sortedItems )
73- {
74- var currentIndex = attributes . IndexOf ( item ) ;
75- if ( currentIndex < attributes . Count - 1 )
76- {
77- // If the item below is also in the selection, keep them as a block
78- var itemBelow = attributes [ currentIndex + 1 ] ;
79- if ( ! itemsToMove . Contains ( itemBelow ) )
80- {
81- attributes . RemoveAt ( currentIndex ) ;
82- attributes . Insert ( currentIndex + 1 , item ) ;
83- moved = true ;
84- }
85- }
86- }
28+ var itemToMove = controller . SelectedAttribute ;
29+ if ( itemToMove == null || controller . ParsedFile == null )
30+ return ;
8731
88- if ( moved )
89- {
90- controller . UpdateView ( ) ;
32+ var currentIndex = controller . ParsedFile . Attributes . IndexOf ( itemToMove ) ;
33+ if ( currentIndex == controller . ParsedFile . Attributes . Count - 1 )
34+ return ;
9135
92- // Restore selection state for the moved items
93- foreach ( var tag in controller . Tags . Where ( t => itemsToMove . Contains ( t . _input ) ) )
94- {
95- tag . IsSelected = true ;
96- }
36+ controller . ParsedFile . Attributes . Remove ( itemToMove ) ;
37+ controller . ParsedFile . Attributes . Insert ( currentIndex + 1 , itemToMove ) ;
38+ controller . UpdateView ( ) ;
39+ controller . SelectedTag = controller . Tags
40+ . Where ( x => x . _input == itemToMove )
41+ . FirstOrDefault ( ) ;
9742
98- controller . SelectedTag = controller . Tags . FirstOrDefault ( x => x . IsSelected ) ;
99- }
10043 }
10144 }
10245}
0 commit comments