浏览代码

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.
Linus Groh 4 年之前
父节点
当前提交
358ec1f1eb
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      Libraries/LibVT/TerminalWidget.cpp

+ 7 - 0
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());