Browser: Implement pasting content from the clipboard

This commit is contained in:
Timothy Flynn 2024-03-24 18:23:37 -04:00 committed by Andreas Kling
parent 7e38653492
commit 0069390e1c
Notes: sideshowbarker 2024-07-16 21:51:02 +09:00
3 changed files with 13 additions and 0 deletions

View File

@ -227,6 +227,16 @@ void BrowserWindow::build_menus(StringView const man_file)
GUI::Clipboard::the().set_plain_text(selected_text);
});
m_paste_action = GUI::CommonActions::make_paste_action([this](auto&) {
auto& tab = active_tab();
auto [data, mime_type, metadata] = GUI::Clipboard::the().fetch_data_and_type();
if (data.is_empty() || !mime_type.starts_with("text/"sv))
return;
tab.view().paste(MUST(String::from_utf8(StringView { data })));
});
m_select_all_action = GUI::CommonActions::make_select_all_action([this](auto&) {
active_tab().view().select_all();
});

View File

@ -37,6 +37,7 @@ public:
GUI::Action& go_home_action() { return *m_go_home_action; }
GUI::Action& reload_action() { return *m_reload_action; }
GUI::Action& copy_selection_action() { return *m_copy_selection_action; }
GUI::Action& paste_action() { return *m_paste_action; }
GUI::Action& select_all_action() { return *m_select_all_action; }
GUI::Action& view_source_action() { return *m_view_source_action; }
GUI::Action& inspect_dom_tree_action() { return *m_inspect_dom_tree_action; }
@ -69,6 +70,7 @@ private:
RefPtr<GUI::Action> m_go_home_action;
RefPtr<GUI::Action> m_reload_action;
RefPtr<GUI::Action> m_copy_selection_action;
RefPtr<GUI::Action> m_paste_action;
RefPtr<GUI::Action> m_select_all_action;
RefPtr<GUI::Action> m_view_source_action;
RefPtr<GUI::Action> m_inspect_dom_tree_action;

View File

@ -728,6 +728,7 @@ Tab::Tab(BrowserWindow& window)
m_page_context_menu->add_action(window.reload_action());
m_page_context_menu->add_separator();
m_page_context_menu->add_action(window.copy_selection_action());
m_page_context_menu->add_action(window.paste_action());
m_page_context_menu->add_action(window.select_all_action());
// FIXME: It would be nice to have a separator here, but the below action is sometimes hidden, and WindowServer
// does not hide successive separators like other toolkits.