diff --git a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index bb5393173b3e..0a0ce424b11b 100644 --- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -634,9 +634,20 @@ nsTreeBodyFrame::ReflowFinished(nsIPresShell* aPresShell, PRBool* aFlushFlag) PRInt32 rowCount; mView->GetRowCount(&rowCount); PRInt32 lastPageTopRow = PR_MAX(0, rowCount - mPageCount); - if (mTopRowIndex >= lastPageTopRow) + if (mTopRowIndex > lastPageTopRow) ScrollToRow(lastPageTopRow); + // make sure that the current selected item is still + // visible after the tree changes size. + nsCOMPtr sel; + mView->GetSelection(getter_AddRefs(sel)); + if (sel) { + PRInt32 currentIndex; + sel->GetCurrentIndex(¤tIndex); + if (currentIndex != -1) + EnsureRowIsVisible(currentIndex); + } + InvalidateScrollbar(); CheckVerticalOverflow(); }