Author: anevilyak Date: 2010-02-22 02:40:24 +0100 (Mon, 22 Feb 2010) New Revision: 35571 Changeset: http://dev.haiku-os.org/changeset/35571/haiku Ticket: http://dev.haiku-os.org/ticket/4253 Modified: haiku/trunk/src/kits/interface/ListView.cpp Log: Fix several problems in BListView: - SwapItems() did not correctly swap the item tops of the two items being swapped. This would result in quite broken/confusing behavior due to the view having the wrong idea of their current position. - SwapItems() also did not pass the correct range to _RescanSelection(). This could result in the selection range getting quite confused when swapping items. - _RescanSelection() did not always correctly reset fLastSelection, though this mostly only would've resulted in unnecessary but harmless work. Fixes ticket #4253 and possibly some others. Modified: haiku/trunk/src/kits/interface/ListView.cpp =================================================================== --- haiku/trunk/src/kits/interface/ListView.cpp 2010-02-21 21:59:27 UTC (rev 35570) +++ haiku/trunk/src/kits/interface/ListView.cpp 2010-02-22 01:40:24 UTC (rev 35571) @@ -1685,14 +1685,14 @@ int32 last = max_c(a, b); if (ItemAt(a)->IsSelected() != ItemAt(b)->IsSelected()) { if (first < fFirstSelected || last > fLastSelected) - _RescanSelection(min_c(first, fFirstSelected), min_c(last, fLastSelected)); + _RescanSelection(min_c(first, fFirstSelected), max_c(last, fLastSelected)); // though the actually selected items stayed the // same, the selection has still changed SelectionChanged(); } - ItemAt(a)->SetTop(bFrame.top); - ItemAt(b)->SetTop(aFrame.top); + ItemAt(a)->SetTop(aFrame.top); + ItemAt(b)->SetTop(bFrame.top); // take care of invalidation if (Window()) { @@ -1801,7 +1801,7 @@ from = max_c(0, from); to = min_c(to, CountItems() - 1); - + if (fAnchorIndex != -1) { if (fAnchorIndex == from) fAnchorIndex = to; @@ -1818,6 +1818,8 @@ if (fFirstSelected > from) from = fFirstSelected; + + fLastSelected = fFirstSelected; for (int32 i = from; i <= to; i++) { if (ItemAt(i)->IsSelected()) fLastSelected = i;