mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-15 23:37:32 +03:00
Browser: Implement pasting content from the clipboard
This commit is contained in:
parent
7e38653492
commit
0069390e1c
Notes:
sideshowbarker
2024-07-16 21:51:02 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/0069390e1c Pull-request: https://github.com/SerenityOS/serenity/pull/23707
@ -227,6 +227,16 @@ void BrowserWindow::build_menus(StringView const man_file)
|
||||
GUI::Clipboard::the().set_plain_text(selected_text);
|
||||
});
|
||||
|
||||
m_paste_action = GUI::CommonActions::make_paste_action([this](auto&) {
|
||||
auto& tab = active_tab();
|
||||
|
||||
auto [data, mime_type, metadata] = GUI::Clipboard::the().fetch_data_and_type();
|
||||
if (data.is_empty() || !mime_type.starts_with("text/"sv))
|
||||
return;
|
||||
|
||||
tab.view().paste(MUST(String::from_utf8(StringView { data })));
|
||||
});
|
||||
|
||||
m_select_all_action = GUI::CommonActions::make_select_all_action([this](auto&) {
|
||||
active_tab().view().select_all();
|
||||
});
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
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& paste_action() { return *m_paste_action; }
|
||||
GUI::Action& select_all_action() { return *m_select_all_action; }
|
||||
GUI::Action& view_source_action() { return *m_view_source_action; }
|
||||
GUI::Action& inspect_dom_tree_action() { return *m_inspect_dom_tree_action; }
|
||||
@ -69,6 +70,7 @@ private:
|
||||
RefPtr<GUI::Action> m_go_home_action;
|
||||
RefPtr<GUI::Action> m_reload_action;
|
||||
RefPtr<GUI::Action> m_copy_selection_action;
|
||||
RefPtr<GUI::Action> m_paste_action;
|
||||
RefPtr<GUI::Action> m_select_all_action;
|
||||
RefPtr<GUI::Action> m_view_source_action;
|
||||
RefPtr<GUI::Action> m_inspect_dom_tree_action;
|
||||
|
@ -728,6 +728,7 @@ Tab::Tab(BrowserWindow& window)
|
||||
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_action(window.paste_action());
|
||||
m_page_context_menu->add_action(window.select_all_action());
|
||||
// FIXME: It would be nice to have a separator here, but the below action is sometimes hidden, and WindowServer
|
||||
// does not hide successive separators like other toolkits.
|
||||
|
Loading…
Reference in New Issue
Block a user