@@ -165,40 +165,36 @@ public static void UpdateUnityProjectViews()
165165 _updatingUnityProjectList = false ;
166166 }
167167
168- public static void MoveSelectedProjectUp ( )
168+ public static void MoveSelectedProjectDown ( )
169169 {
170170 if ( ! TryGetSelectedProject ( out var unityProject ) || unityProject is null )
171171 return ;
172172 var ind = UnityHubUtils . UnityProjects . IndexOf ( unityProject ) ;
173173 if ( ind == - 1 )
174174 return ;
175- if ( ind == UnityHubUtils . UnityProjects . Count - 1 )
176- return ;
177- UnityHubUtils . UnityProjects . RemoveAt ( ind ) ;
178- UnityHubUtils . UnityProjects . Insert ( ind + 1 , unityProject ) ;
175+ var replacedIndex = ( ind + 1 ) % UnityHubUtils . UnityProjects . Count ;
176+ ( UnityHubUtils . UnityProjects [ ind ] , UnityHubUtils . UnityProjects [ replacedIndex ] ) = ( UnityHubUtils . UnityProjects [ replacedIndex ] , UnityHubUtils . UnityProjects [ ind ] ) ;
179177 UnityHubUtils . SaveUnityProjects ( ) ;
180- ( s_unityProjectsParent . Items [ ind ] , s_unityProjectsParent . Items [ ind + 1 ] ) = ( s_unityProjectsParent . Items [ ind + 1 ] , s_unityProjectsParent . Items [ ind ] ) ;
181- s_unityProjectsParent . SelectedIndex = ind + 1 ;
178+ ( s_unityProjectsParent . Items [ ind ] , s_unityProjectsParent . Items [ replacedIndex ] ) = ( s_unityProjectsParent . Items [ replacedIndex ] , s_unityProjectsParent . Items [ ind ] ) ;
179+ s_unityProjectsParent . SelectedIndex = replacedIndex ;
182180 ( ( UnityProjectView ) s_unityProjectsParent . Items [ ind ] ) . Update ( UnityHubUtils . UnityProjects [ ind ] ) ;
183- ( ( UnityProjectView ) s_unityProjectsParent . Items [ ind + 1 ] ) . Update ( UnityHubUtils . UnityProjects [ ind + 1 ] ) ;
181+ ( ( UnityProjectView ) s_unityProjectsParent . Items [ replacedIndex ] ) . Update ( UnityHubUtils . UnityProjects [ replacedIndex ] ) ;
184182 }
185183
186- public static void MoveSelectedProjectDown ( )
184+ public static void MoveSelectedProjectUp ( )
187185 {
188186 if ( ! TryGetSelectedProject ( out var unityProject ) || unityProject is null )
189187 return ;
190188 var ind = UnityHubUtils . UnityProjects . IndexOf ( unityProject ) ;
191189 if ( ind == - 1 )
192190 return ;
193- if ( ind == 0 )
194- return ;
195- UnityHubUtils . UnityProjects . RemoveAt ( ind ) ;
196- UnityHubUtils . UnityProjects . Insert ( ind - 1 , unityProject ) ;
191+ var replacedIndex = ind == 0 ? UnityHubUtils . UnityProjects . Count - 1 : ind - 1 ;
192+ ( UnityHubUtils . UnityProjects [ ind ] , UnityHubUtils . UnityProjects [ replacedIndex ] ) = ( UnityHubUtils . UnityProjects [ replacedIndex ] , UnityHubUtils . UnityProjects [ ind ] ) ;
197193 UnityHubUtils . SaveUnityProjects ( ) ;
198- ( s_unityProjectsParent . Items [ ind ] , s_unityProjectsParent . Items [ ind - 1 ] ) = ( s_unityProjectsParent . Items [ ind - 1 ] , s_unityProjectsParent . Items [ ind ] ) ;
199- s_unityProjectsParent . SelectedIndex = ind - 1 ;
194+ ( s_unityProjectsParent . Items [ ind ] , s_unityProjectsParent . Items [ replacedIndex ] ) = ( s_unityProjectsParent . Items [ replacedIndex ] , s_unityProjectsParent . Items [ ind ] ) ;
195+ s_unityProjectsParent . SelectedIndex = replacedIndex ;
200196 ( ( UnityProjectView ) s_unityProjectsParent . Items [ ind ] ) . Update ( UnityHubUtils . UnityProjects [ ind ] ) ;
201- ( ( UnityProjectView ) s_unityProjectsParent . Items [ ind - 1 ] ) . Update ( UnityHubUtils . UnityProjects [ ind - 1 ] ) ;
197+ ( ( UnityProjectView ) s_unityProjectsParent . Items [ replacedIndex ] ) . Update ( UnityHubUtils . UnityProjects [ replacedIndex ] ) ;
202198 }
203199
204200 static Control CreateContent ( ) => new DockPanel
0 commit comments