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:
Jelle Raaijmakers
2024-08-26 14:08:40 +02:00
committed by Tim Flynn
parent badcdcacf5
commit 732e3fa82f
6 changed files with 42 additions and 7 deletions

View File

@@ -22,6 +22,7 @@
#include <LibWeb/HTML/Numbers.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/Namespace.h>
#include <LibWeb/Selection/Selection.h>
namespace Web::HTML {
@@ -452,4 +453,13 @@ void HTMLTextAreaElement::queue_firing_input_event()
});
}
void HTMLTextAreaElement::selection_was_changed()
{
auto selection = document().get_selection();
if (!selection || selection->range_count() == 0)
return;
MUST(selection->set_base_and_extent(*m_text_node, selection_start().value(), *m_text_node, selection_end().value()));
}
}