|
48 | 48 | % Get original items and highlight |
49 | 49 | oldValue = obj.Value; %#ok<MCSUP> |
50 | 50 | oldHighlight = obj.HighlightedValue; %#ok<MCSUP> |
51 | | - |
52 | | - % What's currently selected? |
53 | | - oldLBHighlight = obj.getListBoxSelectedIndex(); |
54 | 51 |
|
55 | 52 | % Retain the matching original value selection |
56 | 53 | isPresent = ismember(oldValue, newItems); |
57 | 54 | newValue = oldValue(isPresent); |
58 | 55 |
|
59 | | - % Retain the matching original highlight indices |
60 | | - isPresentIdx = find(isPresent); |
61 | | - newHighlightIdx = intersect(oldLBHighlight, isPresentIdx, 'stable'); |
62 | | - |
63 | | - % In case items were removed, we can back up to the highlight |
64 | | - % values |
| 56 | + % Attempt to retain the highlight values |
65 | 57 | isPresent = ismember(oldHighlight, newItems); |
66 | 58 | newHighlight = oldHighlight(isPresent); |
67 | 59 |
|
68 | 60 | % Set new items |
69 | 61 | obj.Items = newItems; |
70 | | - % newValue = intersect(oldValue, value, 'stable') |
71 | 62 |
|
72 | | - % Set selection and highlight for consistency |
73 | | - % newHighlight = intersect(oldHighlightValue, value, 'stable') |
| 63 | + % Set selection for consistency |
74 | 64 | obj.Value = newValue; %#ok<MCSUP> |
75 | | - % obj.HighlightedValue = newHighlight; %#ok<MCSUP> |
76 | 65 |
|
77 | 66 | % Set highlight for consistency |
78 | 67 | if obj.AllowDuplicates %#ok<MCSUP> |
|
84 | 73 | obj.HighlightedValue = newHighlight; %#ok<MCSUP> |
85 | 74 | end |
86 | 75 |
|
87 | | - % elseif isempty(newHighlightIdx) |
88 | | - % |
89 | | - % % Set empty selection |
90 | | - % obj.ListBox.ValueIndex = []; %#ok<MCSUP> |
91 | | - % |
92 | | - % else |
93 | | - % |
94 | | - % % Keep the same indices selected |
95 | | - % obj.ListBox.ValueIndex = newHighlightIdx; %#ok<MCSUP> |
96 | | - % |
97 | | - % end |
98 | | - |
99 | 76 | end |
100 | 77 |
|
101 | 78 |
|
|
0 commit comments