Ladybird: Allow copying text in the js console

This commit is contained in:
Sebastian Zaha 2023-07-19 15:26:29 +02:00 committed by Linus Groh
parent 8e8f124ca9
commit d974142c7e
Notes: sideshowbarker 2024-07-18 03:35:30 +09:00
2 changed files with 13 additions and 1 deletions

View file

@ -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<QMenu>("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);
};

View file

@ -13,6 +13,7 @@
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QMenu>
#include <QToolBar>
#include <QToolButton>
#include <QWidget>
@ -113,5 +114,6 @@ private:
bool m_is_history_navigation { false };
Ladybird::ConsoleWidget* m_console_widget { nullptr };
OwnPtr<QMenu> m_console_context_menu;
Ladybird::InspectorWidget* m_inspector_widget { nullptr };
};