LibWebView: Add a helper to get selected text with collapsed whitespace

This commit is contained in:
Timothy Flynn 2023-10-23 16:52:57 -04:00 committed by Andreas Kling
parent e221b3afeb
commit 6af279a22d
Notes: sideshowbarker 2024-07-17 07:20:49 +09:00
2 changed files with 10 additions and 0 deletions

View file

@ -10,6 +10,7 @@
#include <LibCore/DateTime.h>
#include <LibCore/StandardPaths.h>
#include <LibGfx/ImageFormats/PNGWriter.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWebView/ViewImplementation.h>
namespace WebView {
@ -128,6 +129,14 @@ DeprecatedString ViewImplementation::selected_text()
return client().get_selected_text();
}
Optional<String> ViewImplementation::selected_text_with_whitespace_collapsed()
{
auto selected_text = MUST(Web::Infra::strip_and_collapse_whitespace(this->selected_text()));
if (selected_text.is_empty())
return OptionalNone {};
return selected_text;
}
void ViewImplementation::select_all()
{
client().async_select_all();

View file

@ -63,6 +63,7 @@ public:
void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
DeprecatedString selected_text();
Optional<String> selected_text_with_whitespace_collapsed();
void select_all();
void get_source();