1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 18:05:07 +00:00

LibGUI: Fix TreeView scrolling to top when clicking sub-items

This code was confusing two different versions of scroll_into_view that
were getting mixed up due to member function shadowing.

Adding an "override" to the subclass declaration exposed the problem.

With this fixed, we no longer lose our scroll position wildly when
using the mouse to select TreeView items.
This commit is contained in:
Andreas Kling 2020-09-16 15:28:16 +02:00
parent d1445cee6d
commit 95b6c98435
3 changed files with 9 additions and 9 deletions

View file

@ -360,7 +360,7 @@ void TreeView::paint_event(PaintEvent& event)
});
}
void TreeView::scroll_into_view(const ModelIndex& a_index, Orientation orientation)
void TreeView::scroll_into_view(const ModelIndex& a_index, bool scroll_horizontally, bool scroll_vertically)
{
if (!a_index.is_valid())
return;
@ -372,7 +372,7 @@ void TreeView::scroll_into_view(const ModelIndex& a_index, Orientation orientati
}
return IterationDecision::Continue;
});
ScrollableWidget::scroll_into_view(found_rect, orientation);
ScrollableWidget::scroll_into_view(found_rect, scroll_horizontally, scroll_vertically);
}
void TreeView::did_update_model(unsigned flags)
@ -442,7 +442,7 @@ void TreeView::keydown_event(KeyEvent& event)
}
if (cursor_index.is_valid() && cursor_index.parent().is_valid()) {
selection().set(cursor_index.parent());
scroll_into_view(selection().first(), Orientation::Vertical);
scroll_into_view(selection().first(), false, true);
return;
}
}
@ -461,7 +461,7 @@ void TreeView::keydown_event(KeyEvent& event)
}
selection().set(model()->index(0, model()->tree_column(), cursor_index));
scroll_into_view(selection().first(), Orientation::Vertical);
scroll_into_view(selection().first(), false, true);
return;
}
}
@ -494,7 +494,7 @@ void TreeView::move_cursor(CursorMovement movement, SelectionUpdate)
});
if (found_index.is_valid()) {
selection().set(found_index);
scroll_into_view(selection().first(), Orientation::Vertical);
scroll_into_view(selection().first(), false, true);
update();
}
break;
@ -512,7 +512,7 @@ void TreeView::move_cursor(CursorMovement movement, SelectionUpdate)
});
if (found_index.is_valid()) {
selection().set(found_index);
scroll_into_view(selection().first(), Orientation::Vertical);
scroll_into_view(selection().first(), false, true);
update();
}
return;