mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibWeb: Do not assume the shadow root has a host when updating selection
For example, if the shadow root was detached from the document in some manner, its host will be null.
This commit is contained in:
committed by
Andreas Kling
parent
59fe7ca830
commit
8fb2cc2be1
@@ -0,0 +1 @@
|
||||
12389 PASS (didn't crash)
|
||||
@@ -0,0 +1,17 @@
|
||||
<input type="text" id="input" value="12389" />
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
let input = document.getElementById("input");
|
||||
|
||||
input.focus();
|
||||
input.select();
|
||||
|
||||
input.type = "number";
|
||||
|
||||
const rect = input.getBoundingClientRect();
|
||||
internals.click(rect.x + rect.width / 2, rect.y + rect.height / 2);
|
||||
|
||||
println("PASS (didn't crash)");
|
||||
});
|
||||
</script>
|
||||
@@ -1138,7 +1138,9 @@ void EventHandler::update_selection_range_for_input_or_textarea()
|
||||
auto& root = node.root();
|
||||
if (!root.is_shadow_root())
|
||||
return;
|
||||
auto& shadow_host = *root.parent_or_shadow_host();
|
||||
auto* shadow_host = root.parent_or_shadow_host();
|
||||
if (!shadow_host)
|
||||
return;
|
||||
|
||||
// Invoke "set the selection range" on the form associated element
|
||||
auto selection_start = range->start_offset();
|
||||
@@ -1147,10 +1149,10 @@ void EventHandler::update_selection_range_for_input_or_textarea()
|
||||
auto direction = HTML::SelectionDirection::Forward;
|
||||
|
||||
Optional<HTML::FormAssociatedTextControlElement&> target {};
|
||||
if (is<HTML::HTMLInputElement>(shadow_host))
|
||||
target = static_cast<HTML::HTMLInputElement&>(shadow_host);
|
||||
else if (is<HTML::HTMLTextAreaElement>(shadow_host))
|
||||
target = static_cast<HTML::HTMLTextAreaElement&>(shadow_host);
|
||||
if (is<HTML::HTMLInputElement>(*shadow_host))
|
||||
target = static_cast<HTML::HTMLInputElement&>(*shadow_host);
|
||||
else if (is<HTML::HTMLTextAreaElement>(*shadow_host))
|
||||
target = static_cast<HTML::HTMLTextAreaElement&>(*shadow_host);
|
||||
|
||||
if (target.has_value())
|
||||
target.value().set_the_selection_range(selection_start, selection_end, direction);
|
||||
|
||||
Reference in New Issue
Block a user