feat(api): nvim_open_win() relative to tabline and laststatus #32006

Problem:  Anchoring a floating window to the tabline and laststatus is
          cumbersome; requiring autocommands and looping over all
          windows/tabpages.
Solution: Add new "tabline" and "laststatus" options to the `relative`
          field of nvim_open_win() to place a window relative to.
This commit is contained in:
luukvbaal
2025-01-14 14:02:46 +01:00
committed by GitHub
parent e8ddb7a469
commit 25d8c3a5ad
8 changed files with 133 additions and 12 deletions

View File

@@ -101,10 +101,12 @@
/// @param config Map defining the window configuration. Keys:
/// - relative: Sets the window layout to "floating", placed at (row,col)
/// coordinates relative to:
/// - "editor" The global editor grid
/// - "win" Window given by the `win` field, or current window.
/// - "cursor" Cursor position in current window.
/// - "mouse" Mouse position
/// - "cursor" Cursor position in current window.
/// - "editor" The global editor grid.
/// - "laststatus" 'laststatus' if present, or last row.
/// - "mouse" Mouse position.
/// - "tabline" Tabline if present, or first row.
/// - "win" Window given by the `win` field, or current window.
/// - win: |window-ID| window to split, or relative window when creating a
/// float (relative="win").
/// - anchor: Decides which corner of the float to place at (row,col):
@@ -699,7 +701,9 @@ Dict(win_config) nvim_win_get_config(Window window, Arena *arena, Error *err)
FUNC_API_SINCE(6)
{
/// Keep in sync with FloatRelative in buffer_defs.h
static const char *const float_relative_str[] = { "editor", "win", "cursor", "mouse" };
static const char *const float_relative_str[] = {
"editor", "win", "cursor", "mouse", "tabline", "laststatus"
};
/// Keep in sync with WinSplit in buffer_defs.h
static const char *const win_split_str[] = { "left", "right", "above", "below" };
@@ -805,6 +809,10 @@ static bool parse_float_relative(String relative, FloatRelative *out)
*out = kFloatRelativeCursor;
} else if (striequal(str, "mouse")) {
*out = kFloatRelativeMouse;
} else if (striequal(str, "tabline")) {
*out = kFloatRelativeTabline;
} else if (striequal(str, "laststatus")) {
*out = kFloatRelativeLaststatus;
} else {
return false;
}