From 7d4c9c2ccf75f56e449dc28e91f960be144fdafd Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 10 Nov 2014 13:28:06 +0000 Subject: [PATCH] Support hinting if an inline info should be above or below the anchor Used by ctags function info, we always want it *above* the opening parenthesis so that it does not hide multi line parameter lists. --- rc/ctags.kak | 2 +- src/commands.cc | 11 +++++++++++ src/ncurses.cc | 21 ++++++++++++++++----- src/user_interface.hh | 2 ++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/rc/ctags.kak b/rc/ctags.kak index e521372d..7cd8b9c7 100644 --- a/rc/ctags.kak +++ b/rc/ctags.kak @@ -39,7 +39,7 @@ def funcinfo %{ %sh{ sigs=$(readtags -e ${kak_selection%(} | grep kind:f | sed -re 's/^(\S+).*((class|struct|namespace):(\S+))?.*signature:(.*)$/\5 [\4::\1]/') if [ -n "$sigs" ]; then - echo "eval -client ${kak_client} %{info -anchor $kak_cursor_line.$kak_cursor_column '$sigs'}" + echo "eval -client ${kak_client} %{info -anchor $kak_cursor_line.$kak_cursor_column -placement above '$sigs'}" fi } } diff --git a/src/commands.cc b/src/commands.cc index 7106df89..6e5a2836 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1224,6 +1224,7 @@ const CommandDesc info_cmd = { "info ...: display an info box with the params as content", ParameterDesc{ SwitchMap{ { "anchor", { true, "set info anchoring ." } }, + { "placement", { true, "set placement relative to anchor (above, below)" } }, { "title", { true, "set info title" } } }, ParameterDesc::Flags::None, 0, 1 }, @@ -1247,6 +1248,16 @@ const CommandDesc info_cmd = { str_to_int(anchor.substr(dotb+1))-1}; pos = context.window().display_position(coord); style = InfoStyle::Inline; + if (parser.has_option("placement")) + { + auto placement = parser.option_value("placement"); + if (placement == "above") + style = InfoStyle::InlineAbove; + else if (placement == "below") + style = InfoStyle::InlineBelow; + else + throw runtime_error("invalid placement " + placement); + } } const String& title = parser.has_option("title") ? parser.option_value("title") : ""; context.ui().info_show(title, parser[0], pos, get_face("Information"), style); diff --git a/src/ncurses.cc b/src/ncurses.cc index 88a4a93b..2931e340 100644 --- a/src/ncurses.cc +++ b/src/ncurses.cc @@ -642,12 +642,23 @@ static CharCoord compute_needed_size(StringView str) } static CharCoord compute_pos(CharCoord anchor, CharCoord size, - WINDOW* opt_window_to_avoid = nullptr) + WINDOW* opt_window_to_avoid = nullptr, + bool prefer_above = false) { CharCoord scrsize = window_size(stdscr); - CharCoord pos = { anchor.line+1, anchor.column }; - if (pos.line + size.line >= scrsize.line) - pos.line = max(0_line, anchor.line - size.line); + CharCoord pos; + if (prefer_above) + { + pos = anchor - CharCoord{size.line}; + if (pos.line < 0) + prefer_above = false; + } + if (not prefer_above) + { + pos = anchor + CharCoord{1_line}; + if (pos.line + size.line >= scrsize.line) + pos.line = max(0_line, anchor.line - size.line); + } if (pos.column + size.column >= scrsize.column) pos.column = max(0_char, anchor.column - size.column+1); @@ -790,7 +801,7 @@ void NCursesUI::info_show(StringView title, StringView content, pos = window_pos(m_menu_win) + CharCoord{0_line, window_size(m_menu_win).column}; else - pos = compute_pos(anchor, size, m_menu_win); + pos = compute_pos(anchor, size, m_menu_win, style == InfoStyle::InlineAbove); m_info_win = (NCursesWin*)newwin((int)size.line, (int)size.column, (int)pos.line, (int)pos.column); diff --git a/src/user_interface.hh b/src/user_interface.hh index 07f6eaa8..4f959544 100644 --- a/src/user_interface.hh +++ b/src/user_interface.hh @@ -24,6 +24,8 @@ enum class InfoStyle { Prompt, Inline, + InlineAbove, + InlineBelow, MenuDoc };