LibWeb: Selection toString focused text control delegation

Allows selected text in form controls to be copied to clipboard.
This commit is contained in:
Jonathan Gamble
2025-12-31 14:34:58 -06:00
committed by Shannon Booth
parent 451177f1f4
commit 7385569a02
Notes: github-actions[bot] 2026-01-02 17:41:12 +00:00
12 changed files with 140 additions and 4 deletions

View File

@@ -890,6 +890,18 @@ void FormAssociatedTextControlElement::handle_delete(DeleteDirection direction)
did_edit_text_node();
}
Optional<Utf16String> FormAssociatedTextControlElement::selected_text_for_stringifier() const
{
// https://w3c.github.io/selection-api/#dom-selection-stringifier
// Used for clipboard copy and window.getSelection().toString() when this element is active.
size_t start = this->selection_start();
size_t end = this->selection_end();
if (start >= end)
return {};
return Utf16String::from_utf16(relevant_value().substring_view(start, end - start));
}
void FormAssociatedTextControlElement::collapse_selection_to_offset(size_t position)
{
m_selection_start = position;