mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-18 08:51:46 +03:00
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.
This commit is contained in:
parent
075e4985d7
commit
7d4c9c2ccf
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -1224,6 +1224,7 @@ const CommandDesc info_cmd = {
|
||||
"info <switches> <params>...: display an info box with the params as content",
|
||||
ParameterDesc{
|
||||
SwitchMap{ { "anchor", { true, "set info anchoring <line>.<column>" } },
|
||||
{ "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);
|
||||
|
@ -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);
|
||||
|
@ -24,6 +24,8 @@ enum class InfoStyle
|
||||
{
|
||||
Prompt,
|
||||
Inline,
|
||||
InlineAbove,
|
||||
InlineBelow,
|
||||
MenuDoc
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user