diff options
author | Raphael <glephunter@gmail.com> | 2023-10-11 15:03:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-11 15:03:59 +0800 |
commit | f79052faef874b19ebbed007c30eb3f2c994a8b2 (patch) | |
tree | c2826b79876e7897f678dfc157530b21ffa67608 | |
parent | 4eea60939f9c079d4e1652e0ed1724c4f2ab6eda (diff) | |
download | rneovim-f79052faef874b19ebbed007c30eb3f2c994a8b2.tar.gz rneovim-f79052faef874b19ebbed007c30eb3f2c994a8b2.tar.bz2 rneovim-f79052faef874b19ebbed007c30eb3f2c994a8b2.zip |
refactor(float): rename ex_floatclose to ex_fclose (#25596)
-rw-r--r-- | runtime/doc/windows.txt | 4 | ||||
-rw-r--r-- | src/nvim/ex_cmds.lua | 2 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 2 | ||||
-rw-r--r-- | src/nvim/window.c | 4 | ||||
-rw-r--r-- | test/functional/ui/float_spec.lua | 152 |
5 files changed, 117 insertions, 47 deletions
diff --git a/runtime/doc/windows.txt b/runtime/doc/windows.txt index eb3c4df511..d6fce89f23 100644 --- a/runtime/doc/windows.txt +++ b/runtime/doc/windows.txt @@ -394,8 +394,8 @@ CTRL-W CTRL-O *CTRL-W_CTRL-O* *:on* *:only* *:fc* *:fclose* :[count]fc[lose][!] - Close [count]th floating window by zindex order. '!' to close - all floating windows. + Close [count] floating windows with the highest zindex values. + '!' to close all floating windows. ============================================================================== 4. Moving cursor to other windows *window-move-cursor* diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua index 27f8535a1c..4859a70553 100644 --- a/src/nvim/ex_cmds.lua +++ b/src/nvim/ex_cmds.lua @@ -1048,7 +1048,7 @@ module.cmds = { command='fclose', flags=bit.bor(BANG, RANGE), addr_type='ADDR_OTHER', - func='ex_floatclose', + func='ex_fclose', }, { command='global', diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 36355ce89b..279d14f001 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -7355,7 +7355,7 @@ static void ex_terminal(exarg_T *eap) } /// ":fclose" -static void ex_floatclose(exarg_T *eap) +static void ex_fclose(exarg_T *eap) { win_float_remove(eap->forceit, eap->line1); } diff --git a/src/nvim/window.c b/src/nvim/window.c index bb2e08158f..8e572b7986 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -7657,7 +7657,7 @@ win_T *lastwin_nofloating(void) return res; } -static int floating_zindex_compare(const void *a, const void *b) +static int float_zindex_cmp(const void *a, const void *b) { return (*(win_T **)b)->w_float_config.zindex - (*(win_T **)a)->w_float_config.zindex; } @@ -7668,7 +7668,7 @@ void win_float_remove(bool bang, int count) for (win_T *wp = lastwin; wp && wp->w_floating; wp = wp->w_prev) { kv_push(float_win_arr, wp); } - qsort(float_win_arr.items, float_win_arr.size, sizeof(win_T *), floating_zindex_compare); + qsort(float_win_arr.items, float_win_arr.size, sizeof(win_T *), float_zindex_cmp); for (size_t i = 0; i < float_win_arr.size; i++) { if (win_close(float_win_arr.items[i], false, false) == FAIL) { break; diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index ab02094beb..400b2bbae7 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -10928,25 +10928,24 @@ describe('float window', function() end end) - it('fclose command #9663', function() - local bufA = meths.create_buf(false,false) - local bufB = meths.create_buf(false,false) - local bufC = meths.create_buf(false,false) - local bufD = meths.create_buf(false,false) - local config_A = {relative='editor', width=11, height=11, row=5, col=5, border ='single', zindex=50} - local config_B = {relative='editor', width=8, height=8, row=7, col=7, border ='single', zindex=70} - local config_C = {relative='editor', width=4, height=4, row=9, col=9, border ='single',zindex=90} - local config_D = {relative='editor', width=2, height=2, row=10, col=10, border ='single',zindex=100} - meths.open_win(bufA, false, config_A) - meths.open_win(bufB, false, config_B) - meths.open_win(bufC, false, config_C) - meths.open_win(bufD, false, config_D) - --close window which have higher zindex value - command('fclose') + it(':fclose command #9663', function() + local buf_a = meths.create_buf(false,false) + local buf_b = meths.create_buf(false,false) + local buf_c = meths.create_buf(false,false) + local buf_d = meths.create_buf(false,false) + local config_a = {relative='editor', width=11, height=11, row=5, col=5, border ='single', zindex=50} + local config_b = {relative='editor', width=8, height=8, row=7, col=7, border ='single', zindex=70} + local config_c = {relative='editor', width=4, height=4, row=9, col=9, border ='single',zindex=90} + local config_d = {relative='editor', width=2, height=2, row=10, col=10, border ='single',zindex=100} + meths.open_win(buf_a, false, config_a) + meths.open_win(buf_b, false, config_b) + meths.open_win(buf_c, false, config_c) + meths.open_win(buf_d, false, config_d) local expected_pos = { [4]={{id=1001}, 'NW', 1, 5, 5, true, 50}, [5]={{id=1002}, 'NW', 1, 7, 7, true, 70}, [6]={{id=1003}, 'NW', 1, 9, 9, true, 90}, + [7]={{id=1004}, 'NW', 1, 10, 10, true, 100}, } if multigrid then screen:expect{grid=[[ @@ -10967,6 +10966,77 @@ describe('float window', function() {0:~ }| ## grid 3 | + ## grid 4 + {5:┌───────────┐}| + {5:│}{1: }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:└───────────┘}| + ## grid 5 + {5:┌────────┐}| + {5:│}{1: }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:└────────┘}| + ## grid 6 + {5:┌────┐}| + {5:│}{1: }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:│}{2:~ }{5:│}| + {5:└────┘}| + ## grid 7 + {5:┌──┐}| + {5:│}{1: }{5:│}| + {5:│}{2:~ }{5:│}| + {5:└──┘}| + ]], float_pos=expected_pos} + else + screen:expect([[ + ^ {5:┌─┌─┌────┐─┐┐} | + {0:~ }{5:│}{1: }{5:│}{1: }{5:│}{1: }{5:│}{1: }{5:││}{0: }| + {0:~ }{5:│}{2:~}{5:│}{2:~}{5:│┌──┐│}{2: }{5:││}{0: }| + {0:~ }{5:│}{2:~}{5:│}{2:~}{5:││}{1: }{5:││}{2: }{5:││}{0: }| + {0:~ }{5:│}{2:~}{5:│}{2:~}{5:││}{2:~ }{5:││}{2: }{5:││}{0: }| + {0:~ }{5:│}{2:~}{5:│}{2:~}{5:└└──┘┘}{2: }{5:││}{0: }| + | + ]]) + end + -- close the window with the highest zindex value + command('fclose') + expected_pos[7] = nil + 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 {5:┌───────────┐}| @@ -11000,21 +11070,21 @@ describe('float window', function() {5:│}{2:~ }{5:│}| {5:│}{2:~ }{5:│}| {5:└────┘}| - ]],float_pos= expected_pos} + ]], float_pos=expected_pos} else screen:expect([[ - ^ {5:┌─┌─┌────┐─┐┐} | - {0:~ }{5:│}{1: }{5:│}{1: }{5:│}{1: }{5:│}{1: }{5:││}{0: }| - {0:~ }{5:│}{2:~}{5:│}{2:~}{5:│}{2:~ }{5:│}{2: }{5:││}{0: }| - {0:~ }{5:│}{2:~}{5:│}{2:~}{5:│}{2:~ }{5:│}{2: }{5:││}{0: }| - {0:~ }{5:│}{2:~}{5:│}{2:~}{5:│}{2:~ }{5:│}{2: }{5:││}{0: }| - {0:~ }{5:│}{2:~}{5:│}{2:~}{5:└────┘}{2: }{5:││}{0: }| - | + ^ {5:┌─┌─┌────┐─┐┐} | + {0:~ }{5:│}{1: }{5:│}{1: }{5:│}{1: }{5:│}{1: }{5:││}{0: }| + {0:~ }{5:│}{2:~}{5:│}{2:~}{5:│}{2:~ }{5:│}{2: }{5:││}{0: }| + {0:~ }{5:│}{2:~}{5:│}{2:~}{5:│}{2:~ }{5:│}{2: }{5:││}{0: }| + {0:~ }{5:│}{2:~}{5:│}{2:~}{5:│}{2:~ }{5:│}{2: }{5:││}{0: }| + {0:~ }{5:│}{2:~}{5:│}{2:~}{5:└────┘}{2: }{5:││}{0: }| + | ]]) end -- with range command('1fclose') - expected_pos[6]=nil + expected_pos[6] = nil if multigrid then screen:expect{grid=[[ ## grid 1 @@ -11060,19 +11130,19 @@ describe('float window', function() {5:│}{2:~ }{5:│}| {5:│}{2:~ }{5:│}| {5:└────────┘}| - ]],float_pos= expected_pos} + ]], float_pos=expected_pos} else screen:expect([[ - ^ {5:┌─┌────────┐┐} | - {0:~ }{5:│}{1: }{5:│}{1: }{5:││}{0: }| - {0:~ }{5:│}{2:~}{5:│}{2:~ }{5:││}{0: }| - {0:~ }{5:│}{2:~}{5:│}{2:~ }{5:││}{0: }| - {0:~ }{5:│}{2:~}{5:│}{2:~ }{5:││}{0: }| - {0:~ }{5:│}{2:~}{5:│}{2:~ }{5:││}{0: }| - | + ^ {5:┌─┌────────┐┐} | + {0:~ }{5:│}{1: }{5:│}{1: }{5:││}{0: }| + {0:~ }{5:│}{2:~}{5:│}{2:~ }{5:││}{0: }| + {0:~ }{5:│}{2:~}{5:│}{2:~ }{5:││}{0: }| + {0:~ }{5:│}{2:~}{5:│}{2:~ }{5:││}{0: }| + {0:~ }{5:│}{2:~}{5:│}{2:~ }{5:││}{0: }| + | ]]) end - --with bang + -- with bang command('fclose!') if multigrid then screen:expect{grid=[[ @@ -11094,16 +11164,16 @@ describe('float window', function() ## grid 3 | - ]],float_pos= {}} + ]], float_pos={}} else screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| - | + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | ]]) end end) |