1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:17:45 +00:00

SpaceAnalyzer: Do not reset the path to '/' after a refresh

Clicking analyze or deleting a file would always cause the tree view in
the widget to reset back to viewing the root. This was changed to stay
in the directory currently being viewed
This commit is contained in:
Arda Cinar 2022-12-13 12:25:40 +03:00 committed by Sam Atkins
parent c045ae1a96
commit 33ea96912a
3 changed files with 26 additions and 6 deletions

View file

@ -357,11 +357,27 @@ void TreeMapWidget::context_menu_event(GUI::ContextMenuEvent& context_menu_event
on_context_menu_request(context_menu_event);
}
void TreeMapWidget::recalculate_path_for_new_tree()
{
TreeNode const* current = &m_tree->root();
size_t new_path_length = 0;
for (auto& segment : m_path) {
auto maybe_child = current->child_with_name(segment);
if (!maybe_child.has_value())
break;
new_path_length++;
current = &maybe_child.release_value();
}
m_path.shrink(new_path_length);
if (new_path_length < m_viewpoint)
m_viewpoint = new_path_length - 1;
}
void TreeMapWidget::set_tree(RefPtr<Tree> tree)
{
m_tree = tree;
m_path.clear();
m_viewpoint = 0;
recalculate_path_for_new_tree();
if (on_path_change) {
on_path_change();
}