BOutlineListView: fixed compression causing inconsistent selection update

When compressing an item containing a selected  item, the selection is wrongly moved to the parent as the selection code is not
called. This is causing no visual change in the selected item. Morehover the next user click will always invoke the (wrongly) selected parent.

This can be easily reproduced in the FileTypes application:
 * expand the application item and select an application
 * compress the application item
 * expand the audio item and select and audio item
 * the invokation is performed on the application item and not on the selected audio item.

This fix takes into consideration both single and multiple selection mode.

Change-Id: Icf7c63e6d44f039a8bdf3bb7d343d7aed6b7ac7d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6402
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
Freaxed 2023-05-02 12:06:57 +02:00 committed by waddlesplash
parent 28cea299f7
commit dc3f8c631a

View File

@ -856,10 +856,9 @@ BOutlineListView::ExpandOrCollapse(BListItem* item, bool expand)
_RecalcItemTops(startIndex);
} else {
// collapse
uint32 level = item->fLevel;
int32 fullListIndex = FullListIndexOf(item);
int32 index = IndexOf(item);
int32 startIndex = index;
const uint32 level = item->fLevel;
const int32 fullListIndex = FullListIndexOf(item);
const int32 index = IndexOf(item);
int32 max = FullListCountItems() - fullListIndex - 1;
int32 count = 0;
bool selectionChanged = false;
@ -884,14 +883,19 @@ BOutlineListView::ExpandOrCollapse(BListItem* item, bool expand)
items++;
}
_RecalcItemTops(startIndex);
_RecalcItemTops(index);
// fix selection hints
// if the selected item was just removed by collapsing, select its
// parent
if (ListType() == B_SINGLE_SELECTION_LIST && selectionChanged)
fFirstSelected = fLastSelected = index;
if (index < fFirstSelected && index + count < fFirstSelected) {
if (selectionChanged) {
if (fFirstSelected > index && fFirstSelected <= index + count) {
fFirstSelected = index;
}
if (fLastSelected > index && fLastSelected <= index + count) {
fLastSelected = index;
}
}
if (index + count < fFirstSelected) {
// all items removed were higher than the selection range,
// adjust the indexes to correspond to their new visible positions
fFirstSelected -= count;
@ -906,7 +910,7 @@ BOutlineListView::ExpandOrCollapse(BListItem* item, bool expand)
fLastSelected = maxIndex;
if (selectionChanged)
SelectionChanged();
Select(fFirstSelected, fLastSelected);
}
_FixupScrollBar();