Hide info/menu when they are anchored to an invisible buffer coord

Fixes #1444
This commit is contained in:
Maxime Coste 2017-06-16 10:19:08 +01:00
parent 2992d5bb0b
commit 42f03fb71f
6 changed files with 34 additions and 26 deletions

View File

@ -209,38 +209,43 @@ void Client::redraw_ifn()
return; return;
if (m_ui_pending & Draw) if (m_ui_pending & Draw)
{
m_ui->draw(window.update_display_buffer(context()), m_ui->draw(window.update_display_buffer(context()),
get_face("Default"), get_face("BufferPadding")); get_face("Default"), get_face("BufferPadding"));
if (not m_menu.items.empty() and m_menu.style == MenuStyle::Inline and const bool update_menu_anchor = (m_ui_pending & Draw) and not (m_ui_pending & MenuHide) and
m_menu.ui_anchor != window.display_position(m_menu.anchor)) not m_menu.items.empty() and m_menu.style == MenuStyle::Inline;
m_ui_pending |= (MenuShow | MenuSelect); if ((m_ui_pending & MenuShow) or update_menu_anchor)
if (not m_info.content.empty() and is_inline(m_info.style) and {
m_info.ui_anchor != window.display_position(m_info.anchor)) auto anchor = m_menu.style == MenuStyle::Inline ?
m_ui_pending |= InfoShow; window.display_position(m_menu.anchor) : DisplayCoord{};
if (not (m_ui_pending & MenuShow) and m_menu.ui_anchor != anchor)
m_ui_pending |= anchor ? (MenuShow | MenuSelect) : MenuHide;
m_menu.ui_anchor = anchor;
} }
if (m_ui_pending & MenuShow) if (m_ui_pending & MenuShow and m_menu.ui_anchor)
{ m_ui->menu_show(m_menu.items, *m_menu.ui_anchor,
m_menu.ui_anchor = m_menu.style == MenuStyle::Inline ?
window.display_position(m_menu.anchor) : DisplayCoord{};
m_ui->menu_show(m_menu.items, m_menu.ui_anchor,
get_face("MenuForeground"), get_face("MenuBackground"), get_face("MenuForeground"), get_face("MenuBackground"),
m_menu.style); m_menu.style);
} if (m_ui_pending & MenuSelect and m_menu.ui_anchor)
if (m_ui_pending & MenuSelect)
m_ui->menu_select(m_menu.selected); m_ui->menu_select(m_menu.selected);
if (m_ui_pending & MenuHide) if (m_ui_pending & MenuHide)
m_ui->menu_hide(); m_ui->menu_hide();
if (m_ui_pending & InfoShow) const bool update_info_anchor = (m_ui_pending & Draw) and not (m_ui_pending & InfoHide) and
not m_info.content.empty() and is_inline(m_info.style);
if ((m_ui_pending & InfoShow) or update_info_anchor)
{ {
m_info.ui_anchor = is_inline(m_info.style) ? auto anchor = is_inline(m_info.style) ?
window.display_position(m_info.anchor) : DisplayCoord{}; window.display_position(m_info.anchor) : DisplayCoord{};
m_ui->info_show(m_info.title, m_info.content, m_info.ui_anchor, if (not (m_ui_pending & MenuShow) and m_info.ui_anchor != anchor)
get_face("Information"), m_info.style); m_ui_pending |= anchor ? InfoShow : InfoHide;
m_info.ui_anchor = anchor;
} }
if (m_ui_pending & InfoShow and m_info.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) if (m_ui_pending & InfoHide)
m_ui->info_hide(); m_ui->info_hide();

View File

@ -103,7 +103,7 @@ private:
{ {
Vector<DisplayLine> items; Vector<DisplayLine> items;
BufferCoord anchor; BufferCoord anchor;
DisplayCoord ui_anchor; Optional<DisplayCoord> ui_anchor;
MenuStyle style; MenuStyle style;
int selected; int selected;
} m_menu{}; } m_menu{};
@ -113,7 +113,7 @@ private:
String title; String title;
String content; String content;
BufferCoord anchor; BufferCoord anchor;
DisplayCoord ui_anchor; Optional<DisplayCoord> ui_anchor;
InfoStyle style; InfoStyle style;
} m_info{}; } m_info{};

View File

@ -41,7 +41,7 @@ public:
virtual std::pair<CursorMode, DisplayCoord> get_cursor_info() const virtual std::pair<CursorMode, DisplayCoord> get_cursor_info() const
{ {
DisplayCoord coord = context().window().display_position(context().selections().main().cursor()); DisplayCoord coord = *context().window().display_position(context().selections().main().cursor());
return {CursorMode::Buffer, coord}; return {CursorMode::Buffer, coord};
} }

View File

@ -57,6 +57,8 @@ public:
(not m_valid or m_value == other.m_value); (not m_valid or m_value == other.m_value);
} }
bool operator!=(const Optional& other) const { return !(*this == other); }
template<typename... Args> template<typename... Args>
void emplace(Args&&... args) void emplace(Args&&... args)
{ {

View File

@ -267,17 +267,17 @@ BufferCoord find_buffer_coord(const DisplayLine& line, const Buffer& buffer,
} }
} }
DisplayCoord Window::display_position(BufferCoord coord) const Optional<DisplayCoord> Window::display_position(BufferCoord coord) const
{ {
LineCount l = 0; LineCount l = 0;
for (auto& line : m_display_buffer.lines()) for (auto& line : m_display_buffer.lines())
{ {
auto& range = line.range(); auto& range = line.range();
if (range.begin <= coord and coord < range.end) if (range.begin <= coord and coord < range.end)
return {l, find_display_column(line, buffer(), coord)}; return DisplayCoord{l, find_display_column(line, buffer(), coord)};
++l; ++l;
} }
return { 0, 0 }; return {};
} }
BufferCoord Window::buffer_coord(DisplayCoord coord) const BufferCoord Window::buffer_coord(DisplayCoord coord) const

View File

@ -5,6 +5,7 @@
#include "display_buffer.hh" #include "display_buffer.hh"
#include "highlighter_group.hh" #include "highlighter_group.hh"
#include "option_manager.hh" #include "option_manager.hh"
#include "optional.hh"
#include "safe_ptr.hh" #include "safe_ptr.hh"
#include "scope.hh" #include "scope.hh"
@ -36,7 +37,7 @@ public:
const DisplayBuffer& update_display_buffer(const Context& context); const DisplayBuffer& update_display_buffer(const Context& context);
DisplayCoord display_position(BufferCoord coord) const; Optional<DisplayCoord> display_position(BufferCoord coord) const;
BufferCoord buffer_coord(DisplayCoord coord) const; BufferCoord buffer_coord(DisplayCoord coord) const;
Highlighter& highlighters() { return m_highlighters; } Highlighter& highlighters() { return m_highlighters; }