LibWeb: Update Selection.collapse
algorithm
This commit is contained in:
parent
8a6c8a1c27
commit
94230acf28
Notes:
github-actions[bot]
2024-09-03 15:43:17 +00:00
Author: https://github.com/HolonProduction 🔰 Commit: https://github.com/LadybirdBrowser/ladybird/commit/94230acf287 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1252
3 changed files with 43 additions and 2 deletions
|
@ -0,0 +1,6 @@
|
|||
null
|
||||
null
|
||||
button1
|
||||
button1
|
||||
button2
|
||||
button2
|
|
@ -0,0 +1,35 @@
|
|||
<script src="include.js"></script>
|
||||
<button id="button1"></button>
|
||||
<div id="root"></div>
|
||||
<script>
|
||||
function printSelectionNodes(selection) {
|
||||
if (selection.anchorNode) {
|
||||
println(`${selection.anchorNode.id}`);
|
||||
} else {
|
||||
println(`${selection.anchorNode}`);
|
||||
}
|
||||
if (selection.focusNode) {
|
||||
println(`${selection.focusNode.id}`);
|
||||
} else {
|
||||
println(`${selection.focusNode}`);
|
||||
}
|
||||
}
|
||||
|
||||
test(() => {
|
||||
printSelectionNodes(document.getSelection());
|
||||
|
||||
const button1 = document.querySelector("#button1");
|
||||
document.getSelection().collapse(button1);
|
||||
|
||||
printSelectionNodes(document.getSelection());
|
||||
|
||||
const rootElement = document.getElementById("root");
|
||||
const shadowRoot = rootElement.attachShadow({ mode: "open" });
|
||||
const button2 = document.createElement("button");
|
||||
button2.id = "button2";
|
||||
shadowRoot.appendChild(button2);
|
||||
document.getSelection().collapse(button2);
|
||||
|
||||
printSelectionNodes(document.getSelection());
|
||||
});
|
||||
</script>
|
|
@ -183,8 +183,8 @@ WebIDL::ExceptionOr<void> Selection::collapse(JS::GCPtr<DOM::Node> node, unsigne
|
|||
return WebIDL::IndexSizeError::create(realm(), "Selection.collapse() with offset longer than node's length"_fly_string);
|
||||
}
|
||||
|
||||
// 3. If node's root is not the document associated with this, abort these steps.
|
||||
if (&node->root() != m_document.ptr())
|
||||
// 3. If document associated with this is not a shadow-including inclusive ancestor of node, abort these steps.
|
||||
if (!m_document->is_shadow_including_inclusive_ancestor_of(*node))
|
||||
return {};
|
||||
|
||||
// 4. Otherwise, let newRange be a new range.
|
||||
|
|
Loading…
Add table
Reference in a new issue