Skip to content

Commit

Permalink
Ladybird: Add "Copy" and "Select All" actions to the Edit menu
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Jan 12, 2023
1 parent b79bc25 commit 9c7e26b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
31 changes: 30 additions & 1 deletion Ladybird/BrowserWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Andreas Kling <[email protected]>
* Copyright (c) 2022-2023, Andreas Kling <[email protected]>
* Copyright (c) 2022, Matthew Costa <[email protected]>
* Copyright (c) 2022, Filiph Sandström <[email protected]>
* Copyright (c) 2023, Linus Groh <[email protected]>
Expand All @@ -18,6 +18,8 @@
#include <LibWeb/Loader/ResourceLoader.h>
#include <QAction>
#include <QActionGroup>
#include <QClipboard>
#include <QGuiApplication>
#include <QInputDialog>
#include <QPlainTextEdit>

Expand Down Expand Up @@ -53,6 +55,18 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive
quit_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
menu->addAction(quit_action);

auto* edit_menu = menuBar()->addMenu("&Edit");

auto* copy_action = new QAction("&Copy", this);
copy_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Copy));
edit_menu->addAction(copy_action);
QObject::connect(copy_action, &QAction::triggered, this, &BrowserWindow::copy_selected_text);

auto* select_all_action = new QAction("Select &All", this);
select_all_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::SelectAll));
edit_menu->addAction(select_all_action);
QObject::connect(select_all_action, &QAction::triggered, this, &BrowserWindow::select_all);

auto* view_menu = menuBar()->addMenu("&View");

auto* open_next_tab_action = new QAction("Open &Next Tab", this);
Expand Down Expand Up @@ -455,3 +469,18 @@ void BrowserWindow::reset_zoom()
if (m_current_tab)
m_current_tab->view().reset_zoom();
}

void BrowserWindow::select_all()
{
if (auto* tab = m_current_tab)
tab->view().select_all();
}

void BrowserWindow::copy_selected_text()
{
if (auto* tab = m_current_tab) {
auto text = tab->view().selected_text();
auto* clipboard = QGuiApplication::clipboard();
clipboard->setText(qstring_from_ak_deprecated_string(text));
}
}
2 changes: 2 additions & 0 deletions Ladybird/BrowserWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public slots:
void zoom_in();
void zoom_out();
void reset_zoom();
void select_all();
void copy_selected_text();

private:
void debug_request(DeprecatedString const& request, DeprecatedString const& argument = "");
Expand Down
10 changes: 10 additions & 0 deletions Ladybird/WebContentView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,3 +1120,13 @@ void WebContentView::notify_server_did_get_accessibility_tree(DeprecatedString c
{
dbgln("TODO: support accessibility tree in Ladybird");
}

DeprecatedString WebContentView::selected_text()
{
return client().get_selected_text();
}

void WebContentView::select_all()
{
client().async_select_all();
}
3 changes: 3 additions & 0 deletions Ladybird/WebContentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class WebContentView final
void zoom_out();
void reset_zoom();

DeprecatedString selected_text();
void select_all();

virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) override;
virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id) override;
virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) override;
Expand Down

0 comments on commit 9c7e26b

Please sign in to comment.