فهرست منبع

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%).
Timothy Flynn 1 سال پیش
والد
کامیت
fd558a012b
2فایلهای تغییر یافته به همراه6 افزوده شده و 2 حذف شده
  1. 5 1
      Base/res/ladybird/inspector.js
  2. 1 1
      Userland/Libraries/LibWebView/InspectorClient.cpp

+ 5 - 1
Base/res/ladybird/inspector.js

@@ -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;
     }

+ 1 - 1
Userland/Libraries/LibWebView/InspectorClient.cpp

@@ -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);