diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index eb02fb5955..b45fc44a0b 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -175,6 +176,19 @@ void BrowserWindow::build_menus() go_menu.add_separator(); go_menu.add_action(*m_reload_action); + m_copy_selection_action = GUI::CommonActions::make_copy_action([this](auto&) { + auto& tab = active_tab(); + String selected_text; + + if (tab.m_type == Tab::Type::InProcessWebView) + selected_text = tab.m_page_view->selected_text(); + else + selected_text = tab.m_web_content_view->selected_text(); + + if (!selected_text.is_empty()) + GUI::Clipboard::the().set_plain_text(selected_text); + }); + m_view_source_action = GUI::Action::create( "View &Source", { Mod_Ctrl, Key_U }, [this](auto&) { auto& tab = active_tab(); diff --git a/Userland/Applications/Browser/BrowserWindow.h b/Userland/Applications/Browser/BrowserWindow.h index ec149ca7e3..45bd69c5d1 100644 --- a/Userland/Applications/Browser/BrowserWindow.h +++ b/Userland/Applications/Browser/BrowserWindow.h @@ -30,6 +30,7 @@ public: GUI::Action& go_forward_action() { return *m_go_forward_action; } 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& view_source_action() { return *m_view_source_action; } GUI::Action& inspect_dom_tree_action() { return *m_inspect_dom_tree_action; } @@ -43,6 +44,7 @@ private: RefPtr m_go_forward_action; RefPtr m_go_home_action; RefPtr m_reload_action; + RefPtr m_copy_selection_action; RefPtr m_view_source_action; RefPtr m_inspect_dom_tree_action; diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 49fc92c881..9cc555dad1 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -332,6 +332,8 @@ Tab::Tab(BrowserWindow& window, Type type) m_page_context_menu->add_action(window.go_forward_action()); 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_separator(); m_page_context_menu->add_action(window.view_source_action()); m_page_context_menu->add_action(window.inspect_dom_tree_action()); hooks().on_context_menu_request = [&](auto& screen_position) {