From 9b4bd611ef6990b2b4a83c6b593b7791b2bd4e1a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 30 Mar 2016 19:46:43 +0100 Subject: [PATCH] Replace menu and info when they actually moved Previous logic worked only when the buffer moved in the window, but not if some highlighter (like line numbering or flag lines) moved the text around. --- src/client.cc | 27 ++++++++++++--------------- src/client.hh | 2 ++ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/client.cc b/src/client.cc index cf8b3e71..06ee4260 100644 --- a/src/client.cc +++ b/src/client.cc @@ -190,24 +190,21 @@ void Client::redraw_ifn() if (m_ui_pending & Draw) { - auto window_pos = window.position(); m_ui->draw(window.update_display_buffer(context()), get_face("Default")); - // window moved, reanchor eventual menu and info - if (window_pos != window.position()) - { - if (not m_menu.items.empty() and m_menu.style == MenuStyle::Inline) - m_ui_pending |= (MenuShow | MenuSelect); - if (not m_info.content.empty() and is_inline(m_info.style)) - m_ui_pending |= InfoShow; - } + if (not m_menu.items.empty() and m_menu.style == MenuStyle::Inline and + m_menu.ui_anchor != window.display_position(m_menu.anchor)) + m_ui_pending |= (MenuShow | MenuSelect); + if (not m_info.content.empty() and is_inline(m_info.style) and + m_info.ui_anchor != window.display_position(m_info.anchor)) + m_ui_pending |= InfoShow; } if (m_ui_pending & MenuShow) { - const CharCoord ui_anchor = m_menu.style == MenuStyle::Inline ? + m_menu.ui_anchor = m_menu.style == MenuStyle::Inline ? window.display_position(m_menu.anchor) : CharCoord{}; - m_ui->menu_show(m_menu.items, ui_anchor, + m_ui->menu_show(m_menu.items, m_menu.ui_anchor, get_face("MenuForeground"), get_face("MenuBackground"), m_menu.style); } @@ -218,9 +215,9 @@ void Client::redraw_ifn() if (m_ui_pending & InfoShow) { - const CharCoord ui_anchor = is_inline(m_info.style) ? + m_info.ui_anchor = is_inline(m_info.style) ? window.display_position(m_info.anchor) : CharCoord{}; - m_ui->info_show(m_info.title, m_info.content, ui_anchor, + m_ui->info_show(m_info.title, m_info.content, m_info.ui_anchor, get_face("Information"), m_info.style); } if (m_ui_pending & InfoHide) @@ -333,7 +330,7 @@ void Client::on_option_changed(const Option& option) void Client::menu_show(Vector choices, ByteCoord anchor, MenuStyle style) { - m_menu = Menu{ std::move(choices), anchor, style, -1 }; + m_menu = Menu{ std::move(choices), anchor, {}, style, -1 }; m_ui_pending |= MenuShow; m_ui_pending &= ~MenuHide; } @@ -354,7 +351,7 @@ void Client::menu_hide() void Client::info_show(String title, String content, ByteCoord anchor, InfoStyle style) { - m_info = Info{ std::move(title), std::move(content), anchor, style }; + m_info = Info{ std::move(title), std::move(content), anchor, {}, style }; m_ui_pending |= InfoShow; m_ui_pending &= ~InfoHide; } diff --git a/src/client.hh b/src/client.hh index 3fa36907..fcedd7bb 100644 --- a/src/client.hh +++ b/src/client.hh @@ -101,6 +101,7 @@ private: { Vector items; ByteCoord anchor; + CharCoord ui_anchor; MenuStyle style; int selected; } m_menu; @@ -110,6 +111,7 @@ private: String title; String content; ByteCoord anchor; + CharCoord ui_anchor; InfoStyle style; } m_info;