From 358ec1f1ebbe31e49e86d9743620c78d7d1c85a4 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 6 Dec 2020 21:17:57 +0000 Subject: [PATCH] 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. --- Libraries/LibVT/TerminalWidget.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Libraries/LibVT/TerminalWidget.cpp b/Libraries/LibVT/TerminalWidget.cpp index 0fb223e97d..46ce22bc5d 100644 --- a/Libraries/LibVT/TerminalWidget.cpp +++ b/Libraries/LibVT/TerminalWidget.cpp @@ -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());