aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglepnir <glephunter@gmail.com>2023-09-27 17:23:42 +0800
committerglepnir <glephunter@gmail.com>2023-09-30 18:30:23 +0800
commit4200a0f1678c06c6da4e4cfb0184c29c1174ed21 (patch)
tree0a76101997ab9b1a13b699abdc65e3f39c8df43c
parentdfa8b582a64aa22d3c57261bfcdc970b26cb58f3 (diff)
downloadrneovim-4200a0f1678c06c6da4e4cfb0184c29c1174ed21.tar.gz
rneovim-4200a0f1678c06c6da4e4cfb0184c29c1174ed21.tar.bz2
rneovim-4200a0f1678c06c6da4e4cfb0184c29c1174ed21.zip
feat(float): support toggle show float window
-rw-r--r--runtime/doc/api.txt1
-rw-r--r--runtime/doc/news.txt3
-rw-r--r--runtime/lua/vim/_meta/api.lua1
-rw-r--r--runtime/lua/vim/_meta/api_keysets.lua1
-rw-r--r--src/nvim/api/keysets.h1
-rw-r--r--src/nvim/api/win_config.c6
-rw-r--r--src/nvim/buffer_defs.h2
-rw-r--r--src/nvim/window.c29
-rw-r--r--test/functional/ui/float_spec.lua126
9 files changed, 156 insertions, 14 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt
index 1eebd0bb18..ec979e2ab1 100644
--- a/runtime/doc/api.txt
+++ b/runtime/doc/api.txt
@@ -3181,6 +3181,7 @@ nvim_open_win({buffer}, {enter}, {*config}) *nvim_open_win()*
fire from calling this function.
• fixed: If true when anchor is NW or SW, the float window
would be kept fixed even if the window would be truncated.
+ • hide: If true the floating window will be hidden.
Return: ~
Window handle, or 0 on error
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 05a2d35f9a..23a7e1d503 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -65,6 +65,9 @@ The following changes may require adaptations in user config or plugins.
now requires an explicit range argument to be passed. If injections are
required, provide an explicit range via `parser:parse({ start_row, end_row })`.
+• Float window support hide and show by setting `hide` on `nvim_open_win` and
+ `nvim_win_set_config`.
+
==============================================================================
NEW FEATURES *news-features*
diff --git a/runtime/lua/vim/_meta/api.lua b/runtime/lua/vim/_meta/api.lua
index 68ef54eb2f..0575c13443 100644
--- a/runtime/lua/vim/_meta/api.lua
+++ b/runtime/lua/vim/_meta/api.lua
@@ -1617,6 +1617,7 @@ function vim.api.nvim_open_term(buffer, opts) end
--- fire from calling this function.
--- • fixed: If true when anchor is NW or SW, the float window
--- would be kept fixed even if the window would be truncated.
+--- • hide: If true the floating window will be hidden.
--- @return integer
function vim.api.nvim_open_win(buffer, enter, config) end
diff --git a/runtime/lua/vim/_meta/api_keysets.lua b/runtime/lua/vim/_meta/api_keysets.lua
index eaaa32d7b3..698e706171 100644
--- a/runtime/lua/vim/_meta/api_keysets.lua
+++ b/runtime/lua/vim/_meta/api_keysets.lua
@@ -113,6 +113,7 @@ error('Cannot require a meta file')
--- @field style? string
--- @field noautocmd? boolean
--- @field fixed? boolean
+--- @field hide? boolean
--- @class vim.api.keyset.get_autocmds
--- @field event? any
diff --git a/src/nvim/api/keysets.h b/src/nvim/api/keysets.h
index 236e75983e..429826f231 100644
--- a/src/nvim/api/keysets.h
+++ b/src/nvim/api/keysets.h
@@ -113,6 +113,7 @@ typedef struct {
String style;
Boolean noautocmd;
Boolean fixed;
+ Boolean hide;
} Dict(float_config);
typedef struct {
diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c
index ea0b7ce512..60d32eb30d 100644
--- a/src/nvim/api/win_config.c
+++ b/src/nvim/api/win_config.c
@@ -165,6 +165,7 @@
/// calling this function.
/// - fixed: If true when anchor is NW or SW, the float window
/// would be kept fixed even if the window would be truncated.
+/// - hide: If true the floating window will be hidden.
///
/// @param[out] err Error details, if any
///
@@ -323,6 +324,7 @@ Dictionary nvim_win_get_config(Window window, Error *err)
PUT(rv, "focusable", BOOLEAN_OBJ(config->focusable));
PUT(rv, "external", BOOLEAN_OBJ(config->external));
+ PUT(rv, "hide", BOOLEAN_OBJ(config->hide));
if (wp->w_floating) {
PUT(rv, "width", INTEGER_OBJ(config->width));
@@ -848,6 +850,10 @@ static bool parse_float_config(Dict(float_config) *config, FloatConfig *fconfig,
fconfig->fixed = config->fixed;
}
+ if (HAS_KEY_X(config, hide)) {
+ fconfig->hide = config->hide;
+ }
+
return true;
#undef HAS_KEY_X
}
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index ff0fca1a56..562e0ba089 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -967,6 +967,7 @@ typedef struct {
int footer_width;
bool noautocmd;
bool fixed;
+ bool hide;
} FloatConfig;
#define FLOAT_CONFIG_INIT ((FloatConfig){ .height = 0, .width = 0, \
@@ -977,6 +978,7 @@ typedef struct {
.zindex = kZIndexFloatDefault, \
.style = kWinStyleUnused, \
.noautocmd = false, \
+ .hide = false, \
.fixed = false })
// Structure to store last cursor position and topline. Used by check_lnums()
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 1208494eaf..98fe96af87 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -990,9 +990,13 @@ void ui_ext_win_position(win_T *wp, bool validate)
wp->w_grid_alloc.zindex = wp->w_float_config.zindex;
if (ui_has(kUIMultigrid)) {
String anchor = cstr_as_string((char *)float_anchor_str[c.anchor]);
- ui_call_win_float_pos(wp->w_grid_alloc.handle, wp->handle, anchor,
- grid->handle, row, col, c.focusable,
- wp->w_grid_alloc.zindex);
+ if (!c.hide) {
+ ui_call_win_float_pos(wp->w_grid_alloc.handle, wp->handle, anchor,
+ grid->handle, row, col, c.focusable,
+ wp->w_grid_alloc.zindex);
+ } else {
+ ui_call_win_hide(wp->w_grid_alloc.handle);
+ }
} else {
bool valid = (wp->w_redr_type == 0);
if (!valid && !validate) {
@@ -1014,13 +1018,18 @@ void ui_ext_win_position(win_T *wp, bool validate)
}
wp->w_winrow = comp_row;
wp->w_wincol = comp_col;
- ui_comp_put_grid(&wp->w_grid_alloc, comp_row, comp_col,
- wp->w_height_outer, wp->w_width_outer, valid, false);
- ui_check_cursor_grid(wp->w_grid_alloc.handle);
- wp->w_grid_alloc.focusable = wp->w_float_config.focusable;
- if (!valid) {
- wp->w_grid_alloc.valid = false;
- redraw_later(wp, UPD_NOT_VALID);
+
+ if (!c.hide) {
+ ui_comp_put_grid(&wp->w_grid_alloc, comp_row, comp_col,
+ wp->w_height_outer, wp->w_width_outer, valid, false);
+ ui_check_cursor_grid(wp->w_grid_alloc.handle);
+ wp->w_grid_alloc.focusable = wp->w_float_config.focusable;
+ if (!valid) {
+ wp->w_grid_alloc.valid = false;
+ redraw_later(wp, UPD_NOT_VALID);
+ }
+ } else {
+ ui_comp_remove_grid(&wp->w_grid_alloc);
}
}
} else {
diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua
index 6db9e7af3e..18c8a7370f 100644
--- a/test/functional/ui/float_spec.lua
+++ b/test/functional/ui/float_spec.lua
@@ -1172,14 +1172,14 @@ describe('float window', function()
it('return their configuration', function()
local buf = meths.create_buf(false, false)
local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=3, col=5, zindex=60})
- local expected = {anchor='NW', col=5, external=false, focusable=true, height=2, relative='editor', row=3, width=20, zindex=60}
+ local expected = {anchor='NW', col=5, external=false, focusable=true, height=2, relative='editor', row=3, width=20, zindex=60, hide=false}
eq(expected, meths.win_get_config(win))
- eq({relative='', external=false, focusable=true}, meths.win_get_config(0))
+ eq({relative='', external=false, focusable=true, hide=false}, meths.win_get_config(0))
if multigrid then
meths.win_set_config(win, {external=true, width=10, height=1})
- eq({external=true,focusable=true,width=10,height=1,relative=''}, meths.win_get_config(win))
+ eq({external=true,focusable=true,width=10,height=1,relative='',hide=false}, meths.win_get_config(win))
end
end)
@@ -4281,7 +4281,7 @@ describe('float window', function()
|
]]}
end
- eq({relative='win', width=12, height=1, bufpos={1,32}, anchor='NW',
+ eq({relative='win', width=12, height=1, bufpos={1,32}, anchor='NW', hide=false,
external=false, col=0, row=1, win=firstwin, focusable=true, zindex=50}, meths.win_get_config(win))
feed('<c-e>')
@@ -10809,6 +10809,124 @@ describe('float window', function()
]]}
end
end)
+
+ it('float window with hide option', function()
+ local buf = meths.create_buf(false,false)
+ local win = meths.open_win(buf, false, {relative='editor', width=10, height=2, row=2, col=5, hide = true})
+ local expected_pos = {
+ [4]={{id=1001}, 'NW', 1, 2, 5, true},
+ }
+
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+
+ ## grid 4 (hidden)
+ {1: }|
+ {2:~ }|
+ ]], float_pos = {}}
+ else
+ screen:expect([[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end
+
+ meths.win_set_config(win, {hide = false})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+
+ ## grid 4
+ {1: }|
+ {2:~ }|
+ ]], float_pos = expected_pos}
+ else
+ screen:expect([[
+ ^ |
+ {0:~ }|
+ {0:~ }{1: }{0: }|
+ {0:~ }{2:~ }{0: }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end
+
+ meths.win_set_config(win, {hide=true})
+ if multigrid then
+ screen:expect{grid=[[
+ ## grid 1
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [2:----------------------------------------]|
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ ## grid 3
+ |
+
+ ## grid 4 (hidden)
+ {1: }|
+ {2:~ }|
+ ]], float_pos = {}}
+ else
+ screen:expect([[
+ ^ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]])
+ end
+ end)
end
describe('with ext_multigrid', function()