From e4a439b4a046df0706c383dd954a7a0d65734e87 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Mon, 22 Feb 2010 01:40:24 +0000 Subject: [PATCH] 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. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35571 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/ListView.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/kits/interface/ListView.cpp b/src/kits/interface/ListView.cpp index 9ac83a894d..14e6f5786f 100644 --- a/src/kits/interface/ListView.cpp +++ b/src/kits/interface/ListView.cpp @@ -1685,14 +1685,14 @@ BListView::_SwapItems(int32 a, int32 b) 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 @@ BListView::_RescanSelection(int32 from, int32 to) from = max_c(0, from); to = min_c(to, CountItems() - 1); - + if (fAnchorIndex != -1) { if (fAnchorIndex == from) fAnchorIndex = to; @@ -1818,6 +1818,8 @@ BListView::_RescanSelection(int32 from, int32 to) if (fFirstSelected > from) from = fFirstSelected; + + fLastSelected = fFirstSelected; for (int32 i = from; i <= to; i++) { if (ItemAt(i)->IsSelected()) fLastSelected = i;