From d974142c7e79ef713a7e67999371516749f9c275 Mon Sep 17 00:00:00 2001 From: Sebastian Zaha Date: Wed, 19 Jul 2023 15:26:29 +0200 Subject: [PATCH] Ladybird: Allow copying text in the js console --- Ladybird/Tab.cpp | 12 +++++++++++- Ladybird/Tab.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Ladybird/Tab.cpp b/Ladybird/Tab.cpp index aa33c7bb072..e5ced63acdf 100644 --- a/Ladybird/Tab.cpp +++ b/Ladybird/Tab.cpp @@ -5,7 +5,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "Tab.h" #include "BrowserWindow.h" #include "ConsoleWidget.h" #include "InspectorWidget.h" @@ -667,6 +666,17 @@ void Tab::show_console_window() m_console_widget = new Ladybird::ConsoleWidget; m_console_widget->setWindowTitle("JS Console"); m_console_widget->resize(640, 480); + + // Make the copy action available in the window via the bound copy key shortcut. + // Simply adding it to the context menu is not enough. + m_console_widget->addAction(&m_window->copy_selection_action()); + + m_console_context_menu = make("Context menu", m_console_widget); + m_console_context_menu->addAction(&m_window->copy_selection_action()); + m_console_widget->view().on_context_menu_request = [this](Gfx::IntPoint) { + auto screen_position = QCursor::pos(); + m_console_context_menu->exec(screen_position); + }; m_console_widget->on_js_input = [this](auto js_source) { view().js_console_input(js_source); }; diff --git a/Ladybird/Tab.h b/Ladybird/Tab.h index 49b2572ac5c..874e25ad5b4 100644 --- a/Ladybird/Tab.h +++ b/Ladybird/Tab.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -113,5 +114,6 @@ private: bool m_is_history_navigation { false }; Ladybird::ConsoleWidget* m_console_widget { nullptr }; + OwnPtr m_console_context_menu; Ladybird::InspectorWidget* m_inspector_widget { nullptr }; };