diff --git a/Userland/Libraries/LibWeb/DOMTreeModel.cpp b/Userland/Libraries/LibWeb/DOMTreeModel.cpp index df2209687a..d3eaf157f6 100644 --- a/Userland/Libraries/LibWeb/DOMTreeModel.cpp +++ b/Userland/Libraries/LibWeb/DOMTreeModel.cpp @@ -131,4 +131,20 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol return {}; } +GUI::ModelIndex DOMTreeModel::index_for_node(DOM::Node* node) const +{ + if (!node) + return {}; + + DOM::Node* parent = node->parent(); + if (!parent) + return {}; + + auto maybe_row = parent->index_of_child(*node); + if (maybe_row.has_value()) + return create_index(maybe_row.value(), 0, node); + + return {}; +} + } diff --git a/Userland/Libraries/LibWeb/DOMTreeModel.h b/Userland/Libraries/LibWeb/DOMTreeModel.h index 574c2b316c..bfd5875ab4 100644 --- a/Userland/Libraries/LibWeb/DOMTreeModel.h +++ b/Userland/Libraries/LibWeb/DOMTreeModel.h @@ -26,6 +26,8 @@ public: virtual GUI::ModelIndex index(int row, int column, const GUI::ModelIndex& parent = GUI::ModelIndex()) const override; virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; + GUI::ModelIndex index_for_node(DOM::Node*) const; + private: explicit DOMTreeModel(DOM::Document&);