From d5143db081f24b497c43bc4fc6c7db4e1f5812ce Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Wed, 4 Dec 2024 10:33:23 +0100 Subject: [PATCH] LibWeb: Skip node trees outside of range in insertParagraph Instead of recursively iterating all descendants of the common ancestor of the new line range that are not contained by that range, skip the entire node tree as soon as we determine they're not. --- Libraries/LibWeb/Editing/Commands.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Libraries/LibWeb/Editing/Commands.cpp b/Libraries/LibWeb/Editing/Commands.cpp index 64f62a5640b..8b370c382be 100644 --- a/Libraries/LibWeb/Editing/Commands.cpp +++ b/Libraries/LibWeb/Editing/Commands.cpp @@ -639,8 +639,9 @@ bool command_insert_paragraph_action(DOM::Document& document, String const&) Vector> contained_nodes; auto common_ancestor = new_line_range->common_ancestor_container(); common_ancestor->for_each_in_subtree([&](GC::Ref child_node) { - if (new_line_range->contains_node(child_node)) - contained_nodes.append(child_node); + if (!new_line_range->contains_node(child_node)) + return TraversalDecision::SkipChildrenAndContinue; + contained_nodes.append(child_node); return TraversalDecision::Continue; });