From 9a5fe740c6ed293f66421e93d163ba29b7339f81 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 5 Dec 2023 16:54:53 -0500 Subject: [PATCH] LibWebView: Make a best-effort attempt to not "shift" edited attributes Currently, when editing a DOM attribute, the replacement method first removes the attribute, then adds the replacement attributes. This results in the edited attribute jumping to the end of the attribute list in the Inspector. This patch will try to avoid removing the attribute if one of the replacements has the same name. This will keep the edited attribute in the same location. --- .../Services/WebContent/ConnectionFromClient.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 0e142e8bf1..f5f7bb5acd 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -705,10 +706,17 @@ void ConnectionFromClient::replace_dom_node_attribute(i32 node_id, String const& return; auto& element = static_cast(*dom_node); - element.remove_attribute(name); + bool should_remove_attribute = true; + + for (auto const& attribute : replacement_attributes) { + if (should_remove_attribute && Web::Infra::is_ascii_case_insensitive_match(name, attribute.name)) + should_remove_attribute = false; - for (auto const& attribute : replacement_attributes) element.set_attribute(attribute.name, attribute.value).release_value_but_fixme_should_propagate_errors(); + } + + if (should_remove_attribute) + element.remove_attribute(name); } void ConnectionFromClient::remove_dom_node(i32 node_id)