mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 06:24:58 +00:00
LibWebView: Add some helpers for "Copy email/telephone" functionality
Other browsers have a nice little feature where right-clicking on a `mailto` or `tel` link will let you copy the email address or telephone number, instead of the full URL. So let's do that!
This commit is contained in:
parent
db9a507f7f
commit
c8247e5737
2 changed files with 31 additions and 0 deletions
|
@ -160,4 +160,26 @@ Optional<URLParts> break_url_into_parts(StringView url_string)
|
|||
return {};
|
||||
}
|
||||
|
||||
URLType url_type(URL const& url)
|
||||
{
|
||||
if (url.scheme() == "mailto"sv)
|
||||
return URLType::Email;
|
||||
if (url.scheme() == "tel"sv)
|
||||
return URLType::Telephone;
|
||||
return URLType::Other;
|
||||
}
|
||||
|
||||
String url_text_to_copy(URL const& url)
|
||||
{
|
||||
auto url_text = MUST(url.to_string());
|
||||
|
||||
if (url.scheme() == "mailto"sv)
|
||||
return MUST(url_text.substring_from_byte_offset("mailto:"sv.length()));
|
||||
|
||||
if (url.scheme() == "tel"sv)
|
||||
return MUST(url_text.substring_from_byte_offset("tel:"sv.length()));
|
||||
|
||||
return url_text;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,4 +28,13 @@ struct URLParts {
|
|||
};
|
||||
Optional<URLParts> break_url_into_parts(StringView url);
|
||||
|
||||
// These are both used for the "right-click -> copy FOO" interaction for links.
|
||||
enum class URLType {
|
||||
Email,
|
||||
Telephone,
|
||||
Other,
|
||||
};
|
||||
URLType url_type(URL const&);
|
||||
String url_text_to_copy(URL const&);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue