1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00:00

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.
This commit is contained in:
Timothy Flynn 2023-12-05 16:54:53 -05:00 committed by Andreas Kling
parent 777b4f7921
commit 9a5fe740c6

View file

@ -33,6 +33,7 @@
#include <LibWeb/HTML/Storage.h> #include <LibWeb/HTML/Storage.h>
#include <LibWeb/HTML/TraversableNavigable.h> #include <LibWeb/HTML/TraversableNavigable.h>
#include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/Window.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/Layout/Viewport.h> #include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Loader/ContentFilter.h> #include <LibWeb/Loader/ContentFilter.h>
#include <LibWeb/Loader/ProxyMappings.h> #include <LibWeb/Loader/ProxyMappings.h>
@ -705,10 +706,17 @@ void ConnectionFromClient::replace_dom_node_attribute(i32 node_id, String const&
return; return;
auto& element = static_cast<Web::DOM::Element&>(*dom_node); auto& element = static_cast<Web::DOM::Element&>(*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(); 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) void ConnectionFromClient::remove_dom_node(i32 node_id)