Explorar el Código

Browser: Allow jumping to stylenames by typing in the inspector

This adds the default behavior of search and highlighting of
abstractView to the inspectorWidget. Search results are based on
the titles in the first columns.
Vrins hace 3 años
padre
commit
044be82567

+ 3 - 0
Userland/Applications/Browser/InspectorWidget.cpp

@@ -162,12 +162,15 @@ void InspectorWidget::load_style_json(String specified_values_json, String compu
 {
     m_selection_specified_values_json = specified_values_json;
     m_style_table_view->set_model(Web::StylePropertiesModel::create(m_selection_specified_values_json.value().view()));
+    m_style_table_view->set_searchable(true);
 
     m_selection_computed_values_json = computed_values_json;
     m_computed_style_table_view->set_model(Web::StylePropertiesModel::create(m_selection_computed_values_json.value().view()));
+    m_computed_style_table_view->set_searchable(true);
 
     m_selection_custom_properties_json = custom_properties_json;
     m_custom_properties_table_view->set_model(Web::StylePropertiesModel::create(m_selection_custom_properties_json.value().view()));
+    m_custom_properties_table_view->set_searchable(true);
 }
 
 void InspectorWidget::update_node_box_model(Optional<String> node_box_sizing_json)

+ 17 - 0
Userland/Libraries/LibWeb/StylePropertiesModel.cpp

@@ -56,4 +56,21 @@ GUI::Variant StylePropertiesModel::data(GUI::ModelIndex const& index, GUI::Model
     return {};
 }
 
+Vector<GUI::ModelIndex> StylePropertiesModel::matches(StringView searching, unsigned flags, GUI::ModelIndex const& parent)
+{
+    if (m_values.is_empty())
+        return {};
+    Vector<GUI::ModelIndex> found_indices;
+    for (auto it = m_values.begin(); !it.is_end(); ++it) {
+        GUI::ModelIndex index = this->index(it.index(), Column::PropertyName, parent);
+        if (!string_matches(data(index, GUI::ModelRole::Display).as_string(), searching, flags))
+            continue;
+
+        found_indices.append(index);
+        if (flags & FirstMatchOnly)
+            break;
+    }
+    return found_indices;
+}
+
 }

+ 2 - 0
Userland/Libraries/LibWeb/StylePropertiesModel.h

@@ -33,6 +33,8 @@ public:
     virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return Column::__Count; }
     virtual String column_name(int) const override;
     virtual GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole) const override;
+    virtual bool is_searchable() const override { return true; }
+    virtual Vector<GUI::ModelIndex> matches(StringView, unsigned flags, GUI::ModelIndex const&) override;
 
 private:
     explicit StylePropertiesModel(JsonObject);