Sfoglia il codice sorgente

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 anni fa
parent
commit
358ec1f1eb
1 ha cambiato i file con 7 aggiunte e 0 eliminazioni
  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&) {
         m_context_menu_for_hyperlink->add_action(GUI::Action::create("Copy URL", [this](auto&) {
             GUI::Clipboard::the().set_plain_text(m_context_menu_href);
             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_separator();
         m_context_menu_for_hyperlink->add_action(copy_action());
         m_context_menu_for_hyperlink->add_action(copy_action());
         m_context_menu_for_hyperlink->add_action(paste_action());
         m_context_menu_for_hyperlink->add_action(paste_action());