LibWebView: Do not embed text as data in the Inspector HTML
We were previously embedding the original text to handle the special case where the text is empty. We generate an extra span to hold the string "#text" as a placeholder, so that we don't generate a 0px-wide, unclickable (and therefore uneditable) node. Instead, we can just detect when this is the case in the Inspector JS. This further reduces the generated HTML for the Inspector on https://github.com/SerenityOS/serenity from 1.9MB to 1.8MB (about 94KB, or 4.7%).
This commit is contained in:
parent
f07f5a2622
commit
fd558a012b
Notes:
sideshowbarker
2024-07-17 17:38:29 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/fd558a012b Pull-request: https://github.com/SerenityOS/serenity/pull/23251 Issue: https://github.com/SerenityOS/serenity/issues/23241
2 changed files with 6 additions and 2 deletions
|
@ -302,7 +302,11 @@ const editDOMNode = domNode => {
|
|||
let editor = createDOMEditor(handleChange, cancelChange);
|
||||
|
||||
if (type === "text") {
|
||||
editor.value = domNode.dataset.text;
|
||||
let emptyTextSpan = domNode.querySelector(".internal");
|
||||
|
||||
if (emptyTextSpan === null) {
|
||||
editor.value = domNode.innerText;
|
||||
}
|
||||
} else {
|
||||
editor.value = domNode.innerText;
|
||||
}
|
||||
|
|
|
@ -485,7 +485,7 @@ String InspectorClient::generate_dom_tree(JsonObject const& dom_tree)
|
|||
deprecated_text = escape_html_entities(deprecated_text);
|
||||
|
||||
auto text = MUST(Web::Infra::strip_and_collapse_whitespace(deprecated_text));
|
||||
builder.appendff("<span data-node-type=\"text\" data-text=\"{}\" class=\"hoverable editable\" {}>", text, data_attributes.string_view());
|
||||
builder.appendff("<span data-node-type=\"text\" class=\"hoverable editable\" {}>", data_attributes.string_view());
|
||||
|
||||
if (text.is_empty())
|
||||
builder.appendff("<span class=\"internal\">{}</span>", name);
|
||||
|
|
Loading…
Add table
Reference in a new issue