mirror of
https://github.com/fadden/6502bench.git
synced 2025-01-04 16:33:52 +00:00
Fix crashing bug in selection management
The fix for Shift+F3 required briefly switching the code list view to single-select mode. Unfortunately, while in that mode the control throws an exception if you touch SelectedItems (plural) rather than SelectedItem (singular), and in an unusual case the selection-changed event handler was doing just that.
This commit is contained in:
parent
e79064709c
commit
7000a5094e
@ -715,6 +715,16 @@ namespace SourceGen.WpfGui {
|
||||
// We work around this by temporarily switching to single-select mode.
|
||||
//
|
||||
// This could cause problems if we wanted to select multiple single lines.
|
||||
//
|
||||
// NOTE: this causes a selection-changed event, which can cause problems
|
||||
// if something tries to fiddle with SelectedItems (you can only do that
|
||||
// when in multi-select mode) instead of SelectedItem. I tried to mitigate this
|
||||
// by setting the selection twice, once in multi-select mode, so that the
|
||||
// selection is unlikely to change, but that restored the Shift+F3 problem.
|
||||
//
|
||||
// (To repro problem: double-clicking a line in the message log about
|
||||
// a reference to a non-existent symbol associated with a self-referential line
|
||||
// blows things up... see test 2010.)
|
||||
codeListView.SelectionMode = SelectionMode.Single;
|
||||
codeListView.SelectedItem = CodeDisplayList[start];
|
||||
codeListView.SelectionMode = SelectionMode.Extended;
|
||||
@ -908,12 +918,21 @@ namespace SourceGen.WpfGui {
|
||||
/// <param name="newParts">Replacement parts.</param>
|
||||
private void CodeListView_ReplaceEntry(int index, DisplayList.FormattedParts newParts) {
|
||||
bool isSelected = CodeDisplayList.SelectedIndices[index];
|
||||
if (isSelected) {
|
||||
codeListView.SelectedItems.Remove(CodeDisplayList[index]);
|
||||
if (isSelected && codeListView.SelectionMode != SelectionMode.Single) {
|
||||
if (codeListView.SelectionMode != SelectionMode.Single) {
|
||||
Debug.WriteLine("HEY: hit unhappy single-select case");
|
||||
codeListView.SelectedIndex = -1;
|
||||
} else {
|
||||
codeListView.SelectedItems.Remove(CodeDisplayList[index]);
|
||||
}
|
||||
}
|
||||
CodeDisplayList[index] = newParts;
|
||||
if (isSelected) {
|
||||
codeListView.SelectedItems.Add(newParts);
|
||||
if (codeListView.SelectionMode == SelectionMode.Single) {
|
||||
codeListView.SelectedIndex = index;
|
||||
} else {
|
||||
codeListView.SelectedItems.Add(newParts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user