From f186224dfcf86678b6e5ee126d6b9a393f02f634 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 2 May 2023 23:55:14 +0800 Subject: [PATCH] fix(pum): fix missing rightmost column with 'rightleft' (#23445) --- src/nvim/popupmenu.c | 17 +- test/functional/ui/popupmenu_spec.lua | 225 ++++++++++++++++++++++++-- 2 files changed, 219 insertions(+), 23 deletions(-) diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 3246ef2c71..e3166b0c02 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -435,15 +435,20 @@ void pum_redraw(void) int col_off = 0; bool extra_space = false; if (pum_rl) { - col_off = pum_width; - if (pum_col < curwin->w_wincol + curwin->w_width - 1) { + col_off = pum_width - 1; + assert(!(State & MODE_CMDLINE)); + int win_end_col = ui_has(kUIMultigrid) ? curwin->w_grid.cols : W_ENDCOL(curwin); + if (pum_col < win_end_col - 1) { grid_width += 1; extra_space = true; } - } else if (pum_col > 0) { - grid_width += 1; - col_off = 1; - extra_space = true; + } else { + int min_col = (!(State & MODE_CMDLINE) && ui_has(kUIMultigrid)) ? -curwin->w_wincol : 0; + if (pum_col > min_col) { + grid_width += 1; + col_off = 1; + extra_space = true; + } } if (pum_scrollbar > 0) { grid_width++; diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index 6c26c8ea39..4c0ecd9c4e 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -5,6 +5,7 @@ local clear, feed = helpers.clear, helpers.feed local source = helpers.source local insert = helpers.insert local meths = helpers.meths +local async_meths = helpers.async_meths local command = helpers.command local funcs = helpers.funcs local eq = helpers.eq @@ -1978,6 +1979,54 @@ describe('builtin popupmenu', function() {2:-- }{5:match 1 of 4} | ]]) end + + feed('\n') + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [4:-----------]│[2:--------------------]| + [4:-----------]│[2:--------------------]| + [4:-----------]│[2:--------------------]| + [4:-----------]│[2:--------------------]| + [4:-----------]│[2:--------------------]| + [4:-----------]│[2:--------------------]| + {3:') screen:expect([[ ^ drow tfelthgir emos| - {1: }{s: drow}{1: ~}| - {1: }{n: eciohc}{1: ~}| - {1: }{n: txet}{1: ~}| - {1: }{n: gniht}{1: ~}| + {1: }{s: drow }{1: ~}| + {1: }{n: eciohc }{1: ~}| + {1: }{n: txet }{1: ~}| + {1: }{n: gniht }{1: ~}| {1: ~}| {1: ~}| {1: ~}| @@ -2643,25 +2692,167 @@ describe('builtin popupmenu', function() {1: ~}| {1: ~}| ## grid 5 - {n: drow}| - {n: eciohc}| - {n: txet}| - {n: gniht}| + {n: drow }| + {n: eciohc }| + {n: txet }| + {n: gniht }| ]], float_pos={ - [5] = {{id = -1}, "NW", 4, 1, -11, false, 100}; + [5] = {{id = -1}, "NW", 4, 1, -10, false, 100}; }} else screen:expect([[ tfelthgir emos│ ^ tfelthgir emos| - {1: }{n: drow}{1: ~}| - {1: }{n: eciohc}{1: ~}| - {1: }{n: txet}{1: ~}| - {1: }{n: gniht}{1: ~}| + {1: }{n: drow }{1: ~}| + {1: }{n: eciohc }{1: ~}| + {1: }{n: txet }{1: ~}| + {1: }{n: gniht }{1: ~}| {1: ~}│{1: ~}| {3:[No Name] [+] }{4:[No Name] [+] }| {2:-- INSERT --} | ]]) end + feed('') + funcs.complete(1, {'word', 'choice', 'text', 'thing'}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + {3:[No Name] [+] }{4:[No Name] [+] }| + [3:----------------------------------------]| + ## grid 2 + tfelthgir emos| + | + {1: ~}| + {1: ~}| + {1: ~}| + {1: ~}| + ## grid 3 + {2:-- INSERT --} | + ## grid 4 + tfelthgir emos| + ^ | + {1: ~}| + {1: ~}| + {1: ~}| + {1: ~}| + ## grid 5 + {n: drow}| + {n: eciohc}| + {n: txet}| + {n: gniht}| + ]], float_pos={ + [5] = {{id = -1}, "NW", 4, 2, 5, false, 100}; + }} + else + screen:expect([[ + tfelthgir emos│ tfelthgir emos| + │ ^ | + {1: ~}│{1: }{n: drow}| + {1: ~}│{1: }{n: eciohc}| + {1: ~}│{1: }{n: txet}| + {1: ~}│{1: }{n: gniht}| + {3:[No Name] [+] }{4:[No Name] [+] }| + {2:-- INSERT --} | + ]]) + end + feed('') + async_meths.call_function('input', {'', '', 'sign'}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + {3:[No Name] [+] }{4:[No Name] [+] }| + [3:----------------------------------------]| + ## grid 2 + tfelthgir emos| + | + {1: ~}| + {1: ~}| + {1: ~}| + {1: ~}| + ## grid 3 + ^ | + ## grid 4 + tfelthgir emos| + | + {1: ~}| + {1: ~}| + {1: ~}| + {1: ~}| + ]]} + else + screen:expect([[ + tfelthgir emos│ tfelthgir emos| + │ | + {1: ~}│{1: ~}| + {1: ~}│{1: ~}| + {1: ~}│{1: ~}| + {1: ~}│{1: ~}| + {3:[No Name] [+] }{4:[No Name] [+] }| + ^ | + ]]) + end + command('set wildoptions+=pum') + feed('') + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + [2:-------------------]│[4:--------------------]| + {3:[No Name] [+] }{4:[No Name] [+] }| + [3:----------------------------------------]| + ## grid 2 + tfelthgir emos| + | + {1: ~}| + {1: ~}| + {1: ~}| + {1: ~}| + ## grid 3 + define^ | + ## grid 4 + tfelthgir emos| + | + {1: ~}| + {1: ~}| + {1: ~}| + {1: ~}| + ## grid 5 + {s:define }| + {n:jump }| + {n:list }| + {n:place }| + {n:undefine }| + {n:unplace }| + ]], float_pos={ + [5] = {{id = -1}, "SW", 1, 7, 0, false, 250}; + }} + else + screen:expect([[ + tfelthgir emos│ tfelthgir emos| + {s:define } │ | + {n:jump }{1: ~}│{1: ~}| + {n:list }{1: ~}│{1: ~}| + {n:place }{1: ~}│{1: ~}| + {n:undefine }{1: ~}│{1: ~}| + {n:unplace }{3: }{4:[No Name] [+] }| + define^ | + ]]) + end end) if not multigrid then