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.
This commit is contained in:
Andreas Kling 2020-05-09 18:45:45 +02:00
parent 31ec4de0ee
commit c3aa249a36
Notes: sideshowbarker 2024-07-19 06:48:21 +09:00
2 changed files with 9 additions and 4 deletions

View file

@ -132,10 +132,10 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co
m_context_menu_for_hyperlink = GUI::Menu::construct();
m_context_menu_for_hyperlink->add_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)

View file

@ -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 };