mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-01 16:02:53 +00:00
LibWeb: Propagate input/textarea selection update to document selection
Calling `.setSelectionRange()` or `.select()` now updates the document selection as well, visualizing the text selection.
This commit is contained in:
parent
badcdcacf5
commit
732e3fa82f
Notes:
github-actions[bot]
2024-08-27 11:12:49 +00:00
Author: https://github.com/gmta
Commit: 732e3fa82f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1193
Reviewed-by: https://github.com/trflynn89 ✅
6 changed files with 42 additions and 7 deletions
|
@ -411,14 +411,21 @@ void FormAssociatedElement::set_the_selection_range(Optional<WebIDL::UnsignedLon
|
|||
// extent or direction), then queue an element task on the user interaction task source
|
||||
// given the element to fire an event named select at the element, with the bubbles attribute
|
||||
// initialized to true.
|
||||
// AD-HOC: If there is no selection, we do not fire the event. This seems to correspond to how
|
||||
// other browsers behave.
|
||||
if (was_modified && m_selection_start != m_selection_end) {
|
||||
if (was_modified) {
|
||||
auto& html_element = form_associated_element_to_html_element();
|
||||
html_element.queue_an_element_task(Task::Source::UserInteraction, [&html_element] {
|
||||
auto select_event = DOM::Event::create(html_element.realm(), EventNames::select, { .bubbles = true });
|
||||
static_cast<DOM::EventTarget*>(&html_element)->dispatch_event(select_event);
|
||||
});
|
||||
|
||||
// AD-HOC: If there is no selection, we do not fire the event. This seems to correspond to how
|
||||
// other browsers behave.
|
||||
if (m_selection_start != m_selection_end) {
|
||||
html_element.queue_an_element_task(Task::Source::UserInteraction, [&html_element] {
|
||||
auto select_event = DOM::Event::create(html_element.realm(), EventNames::select, { .bubbles = true });
|
||||
static_cast<DOM::EventTarget*>(&html_element)->dispatch_event(select_event);
|
||||
});
|
||||
}
|
||||
|
||||
// AD-HOC: Notify the element that the selection was changed, so it can perform
|
||||
// element-specific updates.
|
||||
selection_was_changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue