diff options
author | luukvbaal <luukvbaal@gmail.com> | 2025-01-14 14:02:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-14 05:02:46 -0800 |
commit | 25d8c3a5ad7e9c5668841e66540ebe34ceda73a7 (patch) | |
tree | 139f1495e3b947676e9f011c50dd6ad525347a01 /src | |
parent | e8ddb7a46938f8843abc1c321cfd83cee2ba0020 (diff) | |
download | rneovim-25d8c3a5ad7e9c5668841e66540ebe34ceda73a7.tar.gz rneovim-25d8c3a5ad7e9c5668841e66540ebe34ceda73a7.tar.bz2 rneovim-25d8c3a5ad7e9c5668841e66540ebe34ceda73a7.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/win_config.c | 18 | ||||
-rw-r--r-- | src/nvim/buffer_defs.h | 2 | ||||
-rw-r--r-- | src/nvim/window.c | 6 | ||||
-rw-r--r-- | src/nvim/winfloat.c | 9 |
4 files changed, 30 insertions, 5 deletions
diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index 45c9e3f56c..225189a3f9 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -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; } diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 3fe44beab9..bffb29578f 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -900,6 +900,8 @@ typedef enum { kFloatRelativeWindow = 1, kFloatRelativeCursor = 2, kFloatRelativeMouse = 3, + kFloatRelativeTabline = 4, + kFloatRelativeLaststatus = 5, } FloatRelative; /// Keep in sync with win_split_str[] in nvim_win_get_config() (api/win_config.c) diff --git a/src/nvim/window.c b/src/nvim/window.c index 68f45ec5ba..1c0d8c1027 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -835,6 +835,10 @@ void ui_ext_win_position(win_T *wp, bool validate) col += tcol - 1; } } + } else if (c.relative == kFloatRelativeLaststatus) { + row += Rows - (int)p_ch - last_stl_height(false); + } else if (c.relative == kFloatRelativeTabline) { + row += tabline_height(); } bool resort = wp->w_grid_alloc.comp_index != 0 @@ -1066,6 +1070,7 @@ win_T *win_split_ins(int size, int flags, win_T *new_wp, int dir, frame_T *to_fl return NULL; } need_status = STATUS_HEIGHT; + win_float_anchor_laststatus(); } bool do_equal = false; @@ -6803,6 +6808,7 @@ void last_status(bool morewin) { // Don't make a difference between horizontal or vertical split. last_status_rec(topframe, last_stl_height(morewin) > 0, global_stl_height() > 0); + win_float_anchor_laststatus(); } // Remove status line from window, replacing it with a horizontal separator if needed. diff --git a/src/nvim/winfloat.c b/src/nvim/winfloat.c index 3e791e2beb..d11b965dfc 100644 --- a/src/nvim/winfloat.c +++ b/src/nvim/winfloat.c @@ -307,6 +307,15 @@ void win_check_anchored_floats(win_T *win) } } +void win_float_anchor_laststatus(void) +{ + FOR_ALL_WINDOWS_IN_TAB(win, curtab) { + if (win->w_config.relative == kFloatRelativeLaststatus) { + win->w_pos_changed = true; + } + } +} + void win_reconfig_floats(void) { for (win_T *wp = lastwin; wp && wp->w_floating; wp = wp->w_prev) { |