mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +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 ✅
@@ -29,6 +29,7 @@
|
||||
#include <LibWeb/HTML/BrowsingContextGroup.h>
|
||||
#include <LibWeb/HTML/DocumentState.h>
|
||||
#include <LibWeb/HTML/HTMLIFrameElement.h>
|
||||
#include <LibWeb/HTML/HTMLInputElement.h>
|
||||
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
|
||||
#include <LibWeb/HTML/Navigable.h>
|
||||
#include <LibWeb/HTML/Navigation.h>
|
||||
@@ -2630,7 +2631,16 @@ String Navigable::selected_text() const
|
||||
auto document = active_document();
|
||||
if (!document)
|
||||
return String {};
|
||||
|
||||
auto const* input_element = as_if<HTML::HTMLInputElement>(document->active_element());
|
||||
if (input_element && input_element->type_state() == HTML::HTMLInputElement::TypeAttributeState::Password) {
|
||||
// Apparently nobody wants bullet characters. We leave the clipboard alone here like other browsers.
|
||||
return String {};
|
||||
}
|
||||
auto selection = document->get_selection();
|
||||
if (auto form_text = selection->try_form_control_selected_text_for_stringifier(); form_text.has_value())
|
||||
return form_text->to_utf8();
|
||||
|
||||
auto range = selection->range();
|
||||
if (!range)
|
||||
return String {};
|
||||
|
||||
Reference in New Issue
Block a user