This commit is contained in:
glepnir 2024-09-18 01:24:55 +03:00 committed by GitHub
commit b7f992e216
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 113 additions and 49 deletions

View File

@ -905,16 +905,18 @@ static bool pum_set_selected(int n, int repeat)
int context = pum_height / 2;
int prev_selected = pum_selected;
// Close the floating preview window when 'selected' is -1, meaning we are back to the original.
// Or no info item in this selected.
if (n < 0 || (n >= 0 && pum_array[n].pum_info == NULL)) {
win_T *wp = win_float_find_preview();
if (wp) {
win_close(wp, true, true);
}
}
pum_selected = n;
unsigned cur_cot_flags = get_cot_flags();
bool use_float = (cur_cot_flags & COT_POPUP) != 0;
// when new leader add and info window is shown and no selected we still
// need use the first index item to update the info float window position.
bool force_select = use_float && pum_selected < 0 && win_float_find_preview();
if (force_select) {
pum_selected = 0;
}
if ((pum_selected >= 0) && (pum_selected < pum_size)) {
if (pum_first > pum_selected - 4) {
// scroll down; when we did a jump it's probably a PageUp then
@ -1131,11 +1133,6 @@ static bool pum_set_selected(int n, int repeat)
}
}
// restore before selected value
if (force_select) {
pum_selected = n;
}
return resized;
}

View File

@ -1698,25 +1698,26 @@ describe('builtin popupmenu', function()
}
end
-- info window position should be adjusted when new leader add
feed('<C-P>o')
-- delete one character make the pum width smaller than before
-- info window position should be adjusted when popupmenu width changed
feed('<BS>')
if multigrid then
screen:expect {
screen:expect({
grid = [[
## grid 1
[2:----------------------------------------]|*10
[3:----------------------------------------]|
## grid 2
o^ |
{1:~ }|*9
## grid 3
{2:-- }{8:Back at original} |
## grid 4
{n:1info}|
{n: }|
## grid 5
{n:one }|
]],
## grid 1
[2:----------------------------------------]|*10
[3:----------------------------------------]|
## grid 2
on^ |
{1:~ }|*9
## grid 3
{2:-- }{5:match 1 of 3} |
## grid 4
{n:1info}|
{n: }|
## grid 5
{s:one }|
]],
float_pos = {
[5] = { -1, 'NW', 2, 1, 0, false, 100 },
[4] = { 1001, 'NW', 1, 1, 15, false, 50 },
@ -1727,7 +1728,7 @@ describe('builtin popupmenu', function()
topline = 0,
botline = 2,
curline = 0,
curcol = 1,
curcol = 2,
linecount = 1,
sum_scroll_delta = 0,
},
@ -1741,22 +1742,88 @@ describe('builtin popupmenu', function()
sum_scroll_delta = 0,
},
},
}
win_viewport_margins = {
[2] = {
bottom = 0,
left = 0,
right = 0,
top = 0,
win = 1000,
},
[4] = {
bottom = 0,
left = 0,
right = 0,
top = 0,
win = 1001,
},
},
})
else
screen:expect {
screen:expect({
grid = [[
o^ |
{n:one 1info}{1: }|
{1:~ }{n: }{1: }|
{1:~ }|*7
{2:-- }{8:Back at original} |
]],
}
on^ |
{s:one }{n:1info}{1: }|
{1:~ }{n: }{1: }|
{1:~ }|*7
{2:-- }{5:match 1 of 3} |
]],
})
end
-- when back to original the preview float should be closed.
feed('<C-P>')
if multigrid then
screen:expect({
grid = [[
## grid 1
[2:----------------------------------------]|*10
[3:----------------------------------------]|
## grid 2
on^ |
{1:~ }|*9
## grid 3
{2:-- }{8:Back at original} |
## grid 5
{n:one }|
]],
float_pos = {
[5] = { -1, 'NW', 2, 1, 0, false, 100 },
},
win_viewport = {
[2] = {
win = 1000,
topline = 0,
botline = 2,
curline = 0,
curcol = 2,
linecount = 1,
sum_scroll_delta = 0,
},
},
win_viewport_margins = {
[2] = {
bottom = 0,
left = 0,
right = 0,
top = 0,
win = 1000,
},
},
})
else
screen:expect({
grid = [[
on^ |
{n:one }{1: }|
{1:~ }|*8
{2:-- }{8:Back at original} |
]],
})
end
-- test nvim__complete_set_info
feed('<ESC>cc<C-X><C-O><C-N><C-N>')
vim.uv.sleep(10)
feed('<ESC>S<C-X><C-O><C-N><C-N>')
if multigrid then
screen:expect {
grid = [[
@ -1772,13 +1839,13 @@ describe('builtin popupmenu', function()
{n:one }|
{n:two }|
{s:looooooooooooooong }|
## grid 6
## grid 7
{n:3info}|
{n: }|
]],
float_pos = {
[5] = { -1, 'NW', 2, 1, 0, false, 100 },
[6] = { 1002, 'NW', 1, 1, 19, false, 50 },
[7] = { 1003, 'NW', 1, 1, 19, false, 50 },
},
win_viewport = {
[2] = {
@ -1790,8 +1857,8 @@ describe('builtin popupmenu', function()
linecount = 1,
sum_scroll_delta = 0,
},
[6] = {
win = 1002,
[7] = {
win = 1003,
topline = 0,
botline = 2,
curline = 0,
@ -1833,12 +1900,12 @@ describe('builtin popupmenu', function()
{s: one }|
{n: two }|
{n: looooooooooooooong }|
## grid 7
## grid 8
{n:1info}|
{n: }|
]],
float_pos = {
[7] = { 1003, 'NW', 1, 1, 14, false, 50 },
[8] = { 1004, 'NW', 1, 1, 14, false, 50 },
[5] = { -1, 'NW', 2, 1, 19, false, 100 },
},
win_viewport = {
@ -1851,8 +1918,8 @@ describe('builtin popupmenu', function()
linecount = 1,
sum_scroll_delta = 0,
},
[7] = {
win = 1003,
[8] = {
win = 1004,
topline = 0,
botline = 2,
curline = 0,