From c3aa249a36803be3b3159ba63b9ddc13ca06ac84 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 9 May 2020 18:45:45 +0200 Subject: [PATCH] LibVT: Snapshot the URL we're opening a context menu for Otherwise it may get lost due to a leave event firing in the widget. --- Libraries/LibVT/TerminalWidget.cpp | 10 ++++++---- Libraries/LibVT/TerminalWidget.h | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Libraries/LibVT/TerminalWidget.cpp b/Libraries/LibVT/TerminalWidget.cpp index 3cd0957b4a..74d891eeae 100644 --- a/Libraries/LibVT/TerminalWidget.cpp +++ b/Libraries/LibVT/TerminalWidget.cpp @@ -132,10 +132,10 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtradd_action(GUI::Action::create("Open URL", [this](auto&) { - Desktop::Launcher::open(m_hovered_href); + Desktop::Launcher::open(m_context_menu_href); })); m_context_menu_for_hyperlink->add_action(GUI::Action::create("Copy URL", [this](auto&) { - GUI::Clipboard::the().set_data(m_hovered_href); + GUI::Clipboard::the().set_data(m_context_menu_href); })); m_context_menu_for_hyperlink->add_separator(); m_context_menu_for_hyperlink->add_action(copy_action()); @@ -772,10 +772,12 @@ void TerminalWidget::emit(const u8* data, size_t size) void TerminalWidget::context_menu_event(GUI::ContextMenuEvent& event) { - if (m_hovered_href_id.is_null()) + if (m_hovered_href_id.is_null()) { m_context_menu->popup(event.screen_position()); - else + } else { + m_context_menu_href = m_hovered_href; m_context_menu_for_hyperlink->popup(event.screen_position()); + } } void TerminalWidget::drop_event(GUI::DropEvent& event) diff --git a/Libraries/LibVT/TerminalWidget.h b/Libraries/LibVT/TerminalWidget.h index 4d5085f6da..d13fdb2d30 100644 --- a/Libraries/LibVT/TerminalWidget.h +++ b/Libraries/LibVT/TerminalWidget.h @@ -133,6 +133,9 @@ private: String m_hovered_href; String m_hovered_href_id; + // Snapshot of m_hovered_href when opening a context menu for a hyperlink. + String m_context_menu_href; + bool m_should_beep { false }; bool m_belling { false }; bool m_alt_key_held { false };