1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:07:35 +00:00

Browser: Add context menu item for copying selected text

This commit is contained in:
Timothy Flynn 2021-07-14 08:33:35 -04:00 committed by Andreas Kling
parent 2fda6ce159
commit 58cb37f986
3 changed files with 18 additions and 0 deletions

View file

@ -17,6 +17,7 @@
#include <LibCore/StandardPaths.h>
#include <LibGUI/AboutDialog.h>
#include <LibGUI/Application.h>
#include <LibGUI/Clipboard.h>
#include <LibGUI/Icon.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/Menu.h>
@ -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();