mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 12:07:14 +02:00
LibWeb: Selection toString focused text control delegation
Allows selected text in form controls to be copied to clipboard.
This commit is contained in:
committed by
Shannon Booth
parent
451177f1f4
commit
7385569a02
Notes:
github-actions[bot]
2026-01-02 17:41:12 +00:00
Author: https://github.com/jonbgamble Commit: https://github.com/LadybirdBrowser/ladybird/commit/7385569a024 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7292 Reviewed-by: https://github.com/shannonbooth ✅
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user