1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

LibVT: Add "Copy name" action to terminal link context menu

Similar to "Copy URL" there is now a "Copy name" action in the context
menu specialized for terminal links. I chose to not alter the behaviour
of the existing copy action to prevent surprises when text is selected
and the user happens to place the cursor over a link.

Closes #4187.
This commit is contained in:
Linus Groh 2020-12-06 21:17:57 +00:00 committed by Andreas Kling
parent 6b7061d00b
commit 358ec1f1eb

View file

@ -871,6 +871,13 @@ void TerminalWidget::context_menu_event(GUI::ContextMenuEvent& event)
m_context_menu_for_hyperlink->add_action(GUI::Action::create("Copy URL", [this](auto&) {
GUI::Clipboard::the().set_plain_text(m_context_menu_href);
}));
m_context_menu_for_hyperlink->add_action(GUI::Action::create("Copy name", [&](auto&) {
// file://courage/home/anon/something -> /home/anon/something
auto path = URL(m_context_menu_href).path();
// /home/anon/something -> something
auto name = LexicalPath(path).basename();
GUI::Clipboard::the().set_plain_text(name);
}));
m_context_menu_for_hyperlink->add_separator();
m_context_menu_for_hyperlink->add_action(copy_action());
m_context_menu_for_hyperlink->add_action(paste_action());