mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 05:09:12 +00:00
LibWeb+WebContent+Ladybird: Add ability to paste text from clipboard
Text can be pasted by pressing Ctrl/Cmd+V or by using button in the context menu. For now only the Qt client is supported.
This commit is contained in:
parent
d5c6e45dca
commit
561e011e07
Notes:
sideshowbarker
2024-07-16 23:13:25 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: 561e011e07
Pull-request: https://github.com/SerenityOS/serenity/pull/23675
Reviewed-by: https://github.com/trflynn89
15 changed files with 82 additions and 4 deletions
|
@ -93,13 +93,20 @@ void EditEventHandler::handle_delete(DOM::Range& range)
|
|||
}
|
||||
|
||||
void EditEventHandler::handle_insert(JS::NonnullGCPtr<DOM::Position> position, u32 code_point)
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append_code_point(code_point);
|
||||
handle_insert(position, MUST(builder.to_string()));
|
||||
}
|
||||
|
||||
void EditEventHandler::handle_insert(JS::NonnullGCPtr<DOM::Position> position, String data)
|
||||
{
|
||||
if (is<DOM::Text>(*position->node())) {
|
||||
auto& node = verify_cast<DOM::Text>(*position->node());
|
||||
|
||||
StringBuilder builder;
|
||||
builder.append(node.data().bytes_as_string_view().substring_view(0, position->offset()));
|
||||
builder.append_code_point(code_point);
|
||||
builder.append(data);
|
||||
builder.append(node.data().bytes_as_string_view().substring_view(position->offset()));
|
||||
|
||||
// Cut string by max length
|
||||
|
@ -113,9 +120,7 @@ void EditEventHandler::handle_insert(JS::NonnullGCPtr<DOM::Position> position, u
|
|||
} else {
|
||||
auto& node = *position->node();
|
||||
auto& realm = node.realm();
|
||||
StringBuilder builder;
|
||||
builder.append_code_point(code_point);
|
||||
auto text = realm.heap().allocate<DOM::Text>(realm, node.document(), MUST(builder.to_string()));
|
||||
auto text = realm.heap().allocate<DOM::Text>(realm, node.document(), data);
|
||||
MUST(node.append_child(*text));
|
||||
position->set_node(text);
|
||||
position->set_offset(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue