Hide info/menu when they are anchored to an invisible buffer coord
Fixes #1444
This commit is contained in:
parent
2992d5bb0b
commit
42f03fb71f
|
@ -209,38 +209,43 @@ void Client::redraw_ifn()
|
|||
return;
|
||||
|
||||
if (m_ui_pending & Draw)
|
||||
{
|
||||
m_ui->draw(window.update_display_buffer(context()),
|
||||
get_face("Default"), get_face("BufferPadding"));
|
||||
|
||||
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;
|
||||
const bool update_menu_anchor = (m_ui_pending & Draw) and not (m_ui_pending & MenuHide) and
|
||||
not m_menu.items.empty() and m_menu.style == MenuStyle::Inline;
|
||||
if ((m_ui_pending & MenuShow) or update_menu_anchor)
|
||||
{
|
||||
auto anchor = m_menu.style == MenuStyle::Inline ?
|
||||
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)
|
||||
{
|
||||
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,
|
||||
if (m_ui_pending & MenuShow and m_menu.ui_anchor)
|
||||
m_ui->menu_show(m_menu.items, *m_menu.ui_anchor,
|
||||
get_face("MenuForeground"), get_face("MenuBackground"),
|
||||
m_menu.style);
|
||||
}
|
||||
if (m_ui_pending & MenuSelect)
|
||||
if (m_ui_pending & MenuSelect and m_menu.ui_anchor)
|
||||
m_ui->menu_select(m_menu.selected);
|
||||
if (m_ui_pending & MenuHide)
|
||||
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) ?
|
||||
window.display_position(m_info.anchor) : DisplayCoord{};
|
||||
m_ui->info_show(m_info.title, m_info.content, m_info.ui_anchor,
|
||||
get_face("Information"), m_info.style);
|
||||
auto anchor = is_inline(m_info.style) ?
|
||||
window.display_position(m_info.anchor) : DisplayCoord{};
|
||||
if (not (m_ui_pending & MenuShow) and m_info.ui_anchor != anchor)
|
||||
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)
|
||||
m_ui->info_hide();
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ private:
|
|||
{
|
||||
Vector<DisplayLine> items;
|
||||
BufferCoord anchor;
|
||||
DisplayCoord ui_anchor;
|
||||
Optional<DisplayCoord> ui_anchor;
|
||||
MenuStyle style;
|
||||
int selected;
|
||||
} m_menu{};
|
||||
|
@ -113,7 +113,7 @@ private:
|
|||
String title;
|
||||
String content;
|
||||
BufferCoord anchor;
|
||||
DisplayCoord ui_anchor;
|
||||
Optional<DisplayCoord> ui_anchor;
|
||||
InfoStyle style;
|
||||
} m_info{};
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
|
||||
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};
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,8 @@ public:
|
|||
(not m_valid or m_value == other.m_value);
|
||||
}
|
||||
|
||||
bool operator!=(const Optional& other) const { return !(*this == other); }
|
||||
|
||||
template<typename... Args>
|
||||
void emplace(Args&&... args)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
for (auto& line : m_display_buffer.lines())
|
||||
{
|
||||
auto& range = line.range();
|
||||
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;
|
||||
}
|
||||
return { 0, 0 };
|
||||
return {};
|
||||
}
|
||||
|
||||
BufferCoord Window::buffer_coord(DisplayCoord coord) const
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "display_buffer.hh"
|
||||
#include "highlighter_group.hh"
|
||||
#include "option_manager.hh"
|
||||
#include "optional.hh"
|
||||
#include "safe_ptr.hh"
|
||||
#include "scope.hh"
|
||||
|
||||
|
@ -36,7 +37,7 @@ public:
|
|||
|
||||
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;
|
||||
|
||||
Highlighter& highlighters() { return m_highlighters; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user