mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:14:58 +00:00
Browser: Reset the DOM Inspector's state when re-opening it
This resets the DOM Inspector to a default state when re-opening it, instead of it displaying the previous selection and properties, which may be outdated. This is closer to how Chrome and Firefox behave. Eventually, it probably makes sense to copy their behavior of selecting the `<body>` element by default.
This commit is contained in:
parent
97379ace25
commit
73c95bcd5f
3 changed files with 28 additions and 4 deletions
|
@ -52,10 +52,7 @@ void InspectorWidget::set_inspected_node(GUI::ModelIndex const index)
|
|||
auto inspected_node_properties = maybe_inspected_node_properties.value();
|
||||
load_style_json(inspected_node_properties.specified_values_json, inspected_node_properties.computed_values_json);
|
||||
} else {
|
||||
m_inspected_node_specified_values_json.clear();
|
||||
m_inspected_node_computed_values_json.clear();
|
||||
m_style_table_view->set_model(nullptr);
|
||||
m_computed_style_table_view->set_model(nullptr);
|
||||
clear_style_json();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,6 +85,18 @@ InspectorWidget::~InspectorWidget()
|
|||
{
|
||||
}
|
||||
|
||||
void InspectorWidget::select_default_node()
|
||||
{
|
||||
clear_style_json();
|
||||
|
||||
// FIXME: Select the <body> element, or else the root node.
|
||||
m_dom_tree_view->collapse_tree();
|
||||
m_dom_tree_view->set_cursor({}, GUI::AbstractView::SelectionUpdate::ClearIfNotSelected);
|
||||
|
||||
m_layout_tree_view->collapse_tree();
|
||||
m_layout_tree_view->set_cursor({}, GUI::AbstractView::SelectionUpdate::ClearIfNotSelected);
|
||||
}
|
||||
|
||||
void InspectorWidget::set_dom_json(String json)
|
||||
{
|
||||
if (m_dom_json.has_value() && m_dom_json.value() == json)
|
||||
|
@ -103,6 +112,8 @@ void InspectorWidget::set_dom_json(String json)
|
|||
i32 node_id = m_pending_inspect_node_id.value();
|
||||
m_pending_inspect_node_id.clear();
|
||||
set_inspected_node(node_id);
|
||||
} else {
|
||||
select_default_node();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,4 +135,12 @@ void InspectorWidget::load_style_json(String specified_values_json, String compu
|
|||
m_computed_style_table_view->set_model(Web::StylePropertiesModel::create(m_inspected_node_computed_values_json.value().view()));
|
||||
}
|
||||
|
||||
void InspectorWidget::clear_style_json()
|
||||
{
|
||||
m_inspected_node_specified_values_json.clear();
|
||||
m_inspected_node_computed_values_json.clear();
|
||||
m_style_table_view->set_model(nullptr);
|
||||
m_computed_style_table_view->set_model(nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue