From b29fbe96ddbedb23756341b326074c9377f5cbc2 Mon Sep 17 00:00:00 2001 From: networkException Date: Sun, 4 Sep 2022 22:20:16 +0200 Subject: [PATCH] LibVT: Handle non file urls in on hover tooltips Previously we would simply compute the basename of the hovered url's path and display it as the resource that will be opened. This patch adds a fallback for non file urls to simply show the full url, making http urls show up properly. --- Userland/Libraries/LibVT/TerminalWidget.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index bc544d6336..0e0b44c3b6 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -831,13 +831,22 @@ void TerminalWidget::mousemove_event(GUI::MouseEvent& event) auto handlers = Desktop::Launcher::get_handlers_for_url(attribute.href); if (!handlers.is_empty()) { - auto path = URL(attribute.href).path(); - auto name = LexicalPath::basename(path); - if (path == handlers[0]) { - set_tooltip(String::formatted("Execute {}", name)); + auto url = URL(attribute.href); + auto path = url.path(); + + auto app_file = Desktop::AppFile::get_for_app(LexicalPath::basename(handlers[0])); + auto app_name = app_file->is_valid() ? app_file->name() : LexicalPath::basename(handlers[0]); + + if (url.scheme() == "file") { + auto file_name = LexicalPath::basename(path); + + if (path == handlers[0]) { + set_tooltip(String::formatted("Execute {}", app_name)); + } else { + set_tooltip(String::formatted("Open {} with {}", file_name, app_name)); + } } else { - auto af = Desktop::AppFile::get_for_app(LexicalPath::basename(handlers[0])); - set_tooltip(String::formatted("Open {} with {}", name, af->is_valid() ? af->name() : LexicalPath::basename(handlers[0]))); + set_tooltip(String::formatted("Open {} with {}", attribute.href, app_name)); } } } else {