mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibWebView: Allow editing empty DOM text nodes in the Inspector
When a DOM text node is empty, we currently render the node name (which is "#text") in the Inspector. This is just to prevent displaying nothing at all, which looks a bit off. However, the patch to allow editing text fields neglected to allow editing these empty fields. This patch attaches the original text data as a data attribute, much like we do for DOM attributes. That is used as the editable text in the inspector, and the empty text fields are now wrapped in an editable span.
This commit is contained in:
parent
6595e76fef
commit
55ec1cbfb5
Notes:
sideshowbarker
2024-07-17 11:33:34 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/55ec1cbfb5 Pull-request: https://github.com/SerenityOS/serenity/pull/22229
2 changed files with 15 additions and 12 deletions
|
@ -262,10 +262,9 @@ const editDOMNode = domNode => {
|
|||
}
|
||||
|
||||
const domNodeID = selectedDOMNode.dataset.id;
|
||||
const type = domNode.dataset.nodeType;
|
||||
|
||||
const handleChange = value => {
|
||||
const type = domNode.dataset.nodeType;
|
||||
|
||||
if (type === "text" || type === "comment") {
|
||||
inspector.setDOMNodeText(domNodeID, value);
|
||||
} else if (type === "tag") {
|
||||
|
@ -282,7 +281,12 @@ const editDOMNode = domNode => {
|
|||
};
|
||||
|
||||
let editor = createDOMEditor(handleChange, cancelChange);
|
||||
editor.value = domNode.innerText;
|
||||
|
||||
if (type === "text") {
|
||||
editor.value = domNode.dataset.text;
|
||||
} else {
|
||||
editor.value = domNode.innerText;
|
||||
}
|
||||
|
||||
domNode.parentNode.replaceChild(editor, domNode);
|
||||
};
|
||||
|
|
|
@ -484,16 +484,15 @@ String InspectorClient::generate_dom_tree(JsonObject const& dom_tree)
|
|||
auto deprecated_text = node.get_deprecated_string("text"sv).release_value();
|
||||
deprecated_text = escape_html_entities(deprecated_text);
|
||||
|
||||
if (auto text = MUST(Web::Infra::strip_and_collapse_whitespace(deprecated_text)); text.is_empty()) {
|
||||
builder.appendff("<span class=\"hoverable internal\" {}>", data_attributes.string_view());
|
||||
builder.append(name);
|
||||
builder.append("</span>"sv);
|
||||
} else {
|
||||
builder.appendff("<span data-node-type=\"text\" class=\"hoverable editable\" {}>", data_attributes.string_view());
|
||||
builder.append(text);
|
||||
builder.append("</span>"sv);
|
||||
}
|
||||
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());
|
||||
|
||||
if (text.is_empty())
|
||||
builder.appendff("<span class=\"internal\">{}</span>", name);
|
||||
else
|
||||
builder.append(text);
|
||||
|
||||
builder.append("</span>"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue