@@ -840,21 +840,18 @@ private void HandleDragged(MsuProjectWindowViewModelTreeData from, MsuProjectWin
840840
841841 if ( currentParent == destinationParent )
842842 {
843- var currentSongIndex = destinationParent . ChildTreeData . IndexOf ( from ) ;
844- var destinationTreeIndex = _viewModel . TreeItems . IndexOf ( to ) + 1 ;
845- if ( currentSongIndex < destinationIndex )
846- {
847- destinationTreeIndex -- ;
848- destinationIndex -- ;
849- }
843+ var dictionary = destinationParent . ChildTreeData . ToDictionary ( x => x . SongInfo ! , x => x ) ;
844+ destinationParent . ChildTreeData . Clear ( ) ;
845+ var destinationParentIndex = _viewModel . TreeItems . IndexOf ( destinationParent ) ;
850846
851- destinationParent . ChildTreeData . Remove ( from ) ;
852- destinationParent . ChildTreeData . Insert ( destinationIndex , from ) ;
853- _viewModel . TreeItems . Remove ( from ) ;
854- _viewModel . TreeItems . Insert ( destinationTreeIndex , from ) ;
855- for ( var i = 0 ; i < destinationParent . ChildTreeData . Count ; i ++ )
847+ for ( var i = 0 ; i < destinationTrack . Songs . Count ; i ++ )
856848 {
857- destinationParent . ChildTreeData [ i ] . SortIndex = destinationParent . SortIndex + i + 1 ;
849+ var song = destinationTrack . Songs [ i ] ;
850+ var songTreeData = dictionary [ song ] ;
851+ destinationParent . ChildTreeData . Add ( songTreeData ) ;
852+ _viewModel . TreeItems . Remove ( songTreeData ) ;
853+ _viewModel . TreeItems . Insert ( destinationParentIndex + i + 1 , songTreeData ) ;
854+ songTreeData . SortIndex = destinationParent . SortIndex + i + 1 ;
858855 }
859856
860857 _viewModel . MsuSongViewModel . UpdateViewModel ( _project , destinationTrack , from . SongInfo , from ) ;
@@ -863,6 +860,7 @@ private void HandleDragged(MsuProjectWindowViewModelTreeData from, MsuProjectWin
863860 else
864861 {
865862 var newTreeData = from ;
863+ var fromSongInfo = from . SongInfo ;
866864
867865 foreach ( var previousTree in currentParent . ChildTreeData . Concat ( destinationParent . ChildTreeData ) )
868866 {
@@ -940,7 +938,7 @@ private void HandleDragged(MsuProjectWindowViewModelTreeData from, MsuProjectWin
940938 SongInfo = song ,
941939 } ;
942940
943- if ( song == from . SongInfo )
941+ if ( song == fromSongInfo )
944942 {
945943 newTreeData = songTreeData ;
946944 }
@@ -960,7 +958,7 @@ private void HandleDragged(MsuProjectWindowViewModelTreeData from, MsuProjectWin
960958 destinationParent . ToggleAsParent ( true , false ) ;
961959 }
962960
963- _viewModel . MsuSongViewModel . UpdateViewModel ( _project , destinationTrack , from . SongInfo , newTreeData ) ;
961+ _viewModel . MsuSongViewModel . UpdateViewModel ( _project , destinationTrack , fromSongInfo , newTreeData ) ;
964962 _viewModel . SelectedTreeItem = newTreeData ;
965963 }
966964
0 commit comments