From b7c0f682e4cf4020face128cf5694df65fac9652 Mon Sep 17 00:00:00 2001 From: X512 Date: Thu, 5 Mar 2020 23:01:19 +0900 Subject: [PATCH] BListView: fix ScrollToSelection When selection moves down, BListView was sometimes scroll to upper item, not lower. Change-Id: I8f3cf87d43e93c3d2cabfd7ca76f44f1575525e0 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2311 Reviewed-by: waddlesplash Reviewed-by: John Scipione Reviewed-by: Adrien Destugues --- src/kits/interface/ListView.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/kits/interface/ListView.cpp b/src/kits/interface/ListView.cpp index fce55539b9..bd65e7e120 100644 --- a/src/kits/interface/ListView.cpp +++ b/src/kits/interface/ListView.cpp @@ -1113,16 +1113,11 @@ BListView::ScrollToSelection() { BRect itemFrame = ItemFrame(CurrentSelection(0)); - if (Bounds().Contains(itemFrame)) - return; - - float scrollPos = itemFrame.top < Bounds().top ? - itemFrame.top : itemFrame.bottom - Bounds().Height(); - - if (itemFrame.top - scrollPos < Bounds().top) - scrollPos = itemFrame.top; - - ScrollTo(itemFrame.left, scrollPos); + if (itemFrame.top < Bounds().top + || itemFrame.Height() > Bounds().Height()) + ScrollBy(0, itemFrame.top - Bounds().top); + else if (itemFrame.bottom > Bounds().bottom) + ScrollBy(0, itemFrame.bottom - Bounds().bottom); }