Ladybird/AppKit: Implement pasting content from the clipboard

This commit is contained in:
Timothy Flynn 2024-03-24 16:02:42 -04:00 committed by Andreas Kling
parent 0069390e1c
commit ed24d8f2b5
Notes: sideshowbarker 2024-07-17 07:20:57 +09:00

View File

@ -873,6 +873,15 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
copy_data_to_clipboard(m_web_view_bridge->selected_text(), NSPasteboardTypeString);
}
- (void)paste:(id)sender
{
auto* paste_board = [NSPasteboard generalPasteboard];
if (auto* contents = [paste_board stringForType:NSPasteboardTypeString]) {
m_web_view_bridge->paste(Ladybird::ns_string_to_string(contents));
}
}
- (void)selectAll:(id)sender
{
m_web_view_bridge->select_all();
@ -1003,6 +1012,9 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
[_page_context_menu addItem:[[NSMenuItem alloc] initWithTitle:@"Copy"
action:@selector(copy:)
keyEquivalent:@""]];
[_page_context_menu addItem:[[NSMenuItem alloc] initWithTitle:@"Paste"
action:@selector(paste:)
keyEquivalent:@""]];
[_page_context_menu addItem:[[NSMenuItem alloc] initWithTitle:@"Select All"
action:@selector(selectAll:)
keyEquivalent:@""]];