Changeset - a321f999a1ea
[Not reviewed]
default
0 1 0
Jason Maltzen - 3 years ago 2021-07-23 07:56:44
jason@hiddenachievement.com
Fix a crash when trying to reorder the reaction list after recording the first reaction in the list.
1 file changed with 4 insertions and 1 deletions:
0 comments (0 inline, 0 general)
ViewModels/ExperimentLogViewModel.cs
Show inline comments
...
 
@@ -122,33 +122,36 @@ namespace DesertPaintCodex.ViewModels
 

	
 
        private void OnReactionResults()
 
        {
 
            int newPos = ResortTestInList(TestView.ReactionTest, RemainingTests);
 
            if (newPos != SelectedRemainingTest)
 
            {
 
                SelectedRemainingTest = newPos;
 
            }
 
        }
 
        
 
        #endregion
 

	
 
        private static int ResortTestInList(ReactionTest test, IList<ReactionTest> list)
 
        {
 
            int oldPos = list.IndexOf(test);
 

	
 
            if (((oldPos > 0) || (test.CompareTo(list[oldPos - 1]) > 0))
 
            // If the item is first in the list or the previous item is valued < the test
 
            // And either the item is last in the list or the next item in the list is valued > than the item
 
            // Don't move it
 
            if (((oldPos == 0) || (test.CompareTo(list[oldPos - 1]) > 0))
 
                && ((oldPos == list.Count - 1) || (test.CompareTo(list[oldPos + 1]) < 0))) return oldPos; // No need to move.
 

	
 
            list.RemoveAt(oldPos);
 
            return InsertTestIntoList(test, list);
 
        }
 
        
 
        private static int InsertTestIntoList(ReactionTest test, IList<ReactionTest> list)
 
        {
 
            int i;
 
            for (i = 0; i < list.Count; i++)
 
            {
 
                if (test.CompareTo(list[i]) < 0) break;
 
            }
 
            list.Insert(i, test);
 
            return i;
 
        }
0 comments (0 inline, 0 general)