From 380c56a4ef7512165ac2363c644cf353ca778f8e Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sun, 14 Jul 2019 14:41:46 -0700 Subject: [PATCH] Recalculate list indices after adding or removing lines Minor display list bug that presented itself when a 3-line note was deleted. --- SourceGenWPF/DisplayList.cs | 13 +++++++++++++ SourceGenWPF/MainController.cs | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/SourceGenWPF/DisplayList.cs b/SourceGenWPF/DisplayList.cs index d057ce3..f2ad910 100644 --- a/SourceGenWPF/DisplayList.cs +++ b/SourceGenWPF/DisplayList.cs @@ -315,6 +315,7 @@ namespace SourceGenWPF { if (oldCount != newCount) { SelectedIndices = new DisplayListSelection(mList.Count); + RecalculateListIndices(); } OnPropertyChanged(CountString); @@ -322,6 +323,18 @@ namespace SourceGenWPF { OnCollectionReset(); } + /// + /// Recalculates the list index fields after lines are added or removed. + /// + private void RecalculateListIndices() { + Debug.WriteLine("Recalculating list indices"); + for (int i = 0; i < mList.Count; i++) { + if (mList[i] != null) { + mList[i].ListIndex = i; + } + } + } + /// /// List elements. Instances are immutable. /// diff --git a/SourceGenWPF/MainController.cs b/SourceGenWPF/MainController.cs index 2f9cac4..0bf0dc3 100644 --- a/SourceGenWPF/MainController.cs +++ b/SourceGenWPF/MainController.cs @@ -2267,7 +2267,7 @@ namespace SourceGenWPF { /// is selected. public SelectionState UpdateSelectionState() { int selCount = mMainWin.CodeListView_GetSelectionCount(); - Debug.WriteLine("SelectionChanged, selCount=" + selCount); + Debug.WriteLine("SelectionChanged: selCount=" + selCount); SelectionState state = new SelectionState();