mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(float)!: always anchor to corner of window including border #15832
N, W, S, E are all inclusive, i.e., always anchor to the exact corner of the window (including border). This line may also need change in this case (change 0 to -1): This is most consistent and easiest to reason about, especially with GUIs whose border do not need to have width/height of 1/1 in cell units. Fix #15789
This commit is contained in:
parent
c5e8c39102
commit
b3e815094b
@ -975,7 +975,7 @@ function M.make_floating_popup_options(width, height, opts)
|
|||||||
else
|
else
|
||||||
anchor = anchor..'S'
|
anchor = anchor..'S'
|
||||||
height = math.min(lines_above, height)
|
height = math.min(lines_above, height)
|
||||||
row = -get_border_size(opts).height
|
row = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.fn.wincol() + width + (opts.offset_x or 0) <= api.nvim_get_option('columns') then
|
if vim.fn.wincol() + width + (opts.offset_x or 0) <= api.nvim_get_option('columns') then
|
||||||
|
@ -1360,7 +1360,9 @@ void nvim_chan_send(Integer chan, String data, Error *err)
|
|||||||
/// - `bufpos`: Places float relative to buffer text (only when
|
/// - `bufpos`: Places float relative to buffer text (only when
|
||||||
/// relative="win"). Takes a tuple of zero-indexed [line, column].
|
/// relative="win"). Takes a tuple of zero-indexed [line, column].
|
||||||
/// `row` and `col` if given are applied relative to this
|
/// `row` and `col` if given are applied relative to this
|
||||||
/// position, else they default to `row=1` and `col=0`
|
/// position, else they default to:
|
||||||
|
/// - `row=1` and `col=0` if `anchor` is "NW" or "NE"
|
||||||
|
/// - `row=0` and `col=0` if `anchor` is "SW" or "SE"
|
||||||
/// (thus like a tooltip near the buffer text).
|
/// (thus like a tooltip near the buffer text).
|
||||||
/// - `row`: Row position in units of "screen cell height", may be fractional.
|
/// - `row`: Row position in units of "screen cell height", may be fractional.
|
||||||
/// - `col`: Column position in units of "screen cell width", may be
|
/// - `col`: Column position in units of "screen cell width", may be
|
||||||
|
@ -853,8 +853,8 @@ void ui_ext_win_position(win_T *wp)
|
|||||||
bool east = c.anchor & kFloatAnchorEast;
|
bool east = c.anchor & kFloatAnchorEast;
|
||||||
bool south = c.anchor & kFloatAnchorSouth;
|
bool south = c.anchor & kFloatAnchorSouth;
|
||||||
|
|
||||||
int comp_row = (int)row - (south ? wp->w_height : 0);
|
int comp_row = (int)row - (south ? wp->w_height_outer : 0);
|
||||||
int comp_col = (int)col - (east ? wp->w_width : 0);
|
int comp_col = (int)col - (east ? wp->w_width_outer : 0);
|
||||||
comp_row += grid->comp_row;
|
comp_row += grid->comp_row;
|
||||||
comp_col += grid->comp_col;
|
comp_col += grid->comp_col;
|
||||||
comp_row = MAX(MIN(comp_row, Rows - wp->w_height_outer - 1), 0);
|
comp_row = MAX(MIN(comp_row, Rows - wp->w_height_outer - 1), 0);
|
||||||
|
@ -2022,83 +2022,6 @@ describe('LSP', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('lsp.util.make_floating_popup_options', function()
|
|
||||||
before_each(function()
|
|
||||||
exec_lua [[
|
|
||||||
local bufnr = vim.uri_to_bufnr("file:///fake/uri")
|
|
||||||
local winheight = vim.fn.winheight(0)
|
|
||||||
for i = 1, winheight do
|
|
||||||
vim.api.nvim_buf_set_lines(bufnr, 0, 0, false, {''})
|
|
||||||
end
|
|
||||||
vim.api.nvim_win_set_buf(0, bufnr)
|
|
||||||
vim.api.nvim_win_set_cursor(0, {winheight, 0})
|
|
||||||
]]
|
|
||||||
end)
|
|
||||||
|
|
||||||
local function popup_row(opts)
|
|
||||||
return exec_lua([[
|
|
||||||
return vim.lsp.util.make_floating_popup_options(...).row
|
|
||||||
]], 2, 2, opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
local err_pattern = "^Error executing lua: %.%.%./util%.lua:0: invalid floating preview border: .*%. :help vim%.api%.nvim_open_win%(%)$"
|
|
||||||
|
|
||||||
it('calculates default border height correctly', function()
|
|
||||||
eq(0, popup_row())
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('calculates string border height correctly', function()
|
|
||||||
eq(0, popup_row({border = 'none'}))
|
|
||||||
eq(-2, popup_row({border = 'single'}))
|
|
||||||
eq(-2, popup_row({border = 'double'}))
|
|
||||||
eq(-2, popup_row({border = 'rounded'}))
|
|
||||||
eq(-2, popup_row({border = 'solid'}))
|
|
||||||
eq(-1, popup_row({border = 'shadow'}))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('error on invalid string border', function()
|
|
||||||
matches(err_pattern, pcall_err(popup_row, {border = ''}))
|
|
||||||
matches(err_pattern, pcall_err(popup_row, {border = 'invalid'}))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('error on invalid array border length', function()
|
|
||||||
matches(err_pattern, pcall_err(popup_row, {border = {}}))
|
|
||||||
matches(err_pattern, pcall_err(popup_row, {border = {'', '', ''}}))
|
|
||||||
matches(err_pattern, pcall_err(popup_row, {border = {'', '', '', '', ''}}))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('error on invalid array border member type', function()
|
|
||||||
matches(err_pattern, pcall_err(popup_row, {border = {0}}))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('calculates 8-array border height correctly', function()
|
|
||||||
eq(0, popup_row({border = {'', '', '', '', '', '', '', ''}}))
|
|
||||||
eq(-2, popup_row({border = {'', '~', '', '~', '', '~', '', '~'}}))
|
|
||||||
eq(-1, popup_row({border = {'', '', '', '~', '', '~', '', ''}}))
|
|
||||||
eq(0, popup_row({border = {'', '', '', {'~', 'NormalFloat'}, '', '', '', {'~', 'NormalFloat'}}}))
|
|
||||||
eq(-2, popup_row({border = {'', {'~', 'NormalFloat'}, '', '', '', {'~', 'NormalFloat'}, '', ''}}))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('calculates 4-array border height correctly', function()
|
|
||||||
eq(0, popup_row({border = {'', '', '', ''}}))
|
|
||||||
eq(-2, popup_row({border = {'', '~', '', '~'}}))
|
|
||||||
eq(0, popup_row({border = {'', '', '', {'~', 'NormalFloat'}}}))
|
|
||||||
eq(-2, popup_row({border = {'', {'~', 'NormalFloat'}, '', ''}}))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('calculates 2-array border height correctly', function()
|
|
||||||
eq(0, popup_row({border = {'', ''}}))
|
|
||||||
eq(-2, popup_row({border = {'', '~'}}))
|
|
||||||
eq(-2, popup_row({border = {'', {'~', 'NormalFloat'}}}))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('calculates 1-array border height correctly', function()
|
|
||||||
eq(0, popup_row({border = {''}}))
|
|
||||||
eq(-2, popup_row({border = {'~'}}))
|
|
||||||
eq(-2, popup_row({border = {{'~', 'NormalFloat'}}}))
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
describe('lsp.util._make_floating_popup_size', function()
|
describe('lsp.util._make_floating_popup_size', function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
exec_lua [[ contents =
|
exec_lua [[ contents =
|
||||||
|
@ -1866,6 +1866,293 @@ describe('float window', function()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('always anchor to corner including border', function()
|
||||||
|
screen:try_resize(40,13)
|
||||||
|
meths.buf_set_lines(0, 0, -1, true, {'just some example text', 'some more example text'})
|
||||||
|
feed('ggeee')
|
||||||
|
command('below split')
|
||||||
|
if multigrid then
|
||||||
|
screen:expect([[
|
||||||
|
## grid 1
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
{5:[No Name] [+] }|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
{4:[No Name] [+] }|
|
||||||
|
[3:----------------------------------------]|
|
||||||
|
## grid 2
|
||||||
|
just some example text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
## grid 3
|
||||||
|
|
|
||||||
|
## grid 4
|
||||||
|
just some exampl^e text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
]])
|
||||||
|
else
|
||||||
|
screen:expect([[
|
||||||
|
just some example text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{5:[No Name] [+] }|
|
||||||
|
just some exampl^e text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{4:[No Name] [+] }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end
|
||||||
|
|
||||||
|
local buf = meths.create_buf(false, false)
|
||||||
|
meths.buf_set_lines(buf, 0, -1, true, {' halloj! ',
|
||||||
|
' BORDAA '})
|
||||||
|
local win = meths.open_win(buf, false, {relative='cursor', width=9, height=2, row=1, col=-2, border="double"})
|
||||||
|
|
||||||
|
if multigrid then
|
||||||
|
screen:expect{grid=[[
|
||||||
|
## grid 1
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
{5:[No Name] [+] }|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
{4:[No Name] [+] }|
|
||||||
|
[3:----------------------------------------]|
|
||||||
|
## grid 2
|
||||||
|
just some example text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
## grid 3
|
||||||
|
|
|
||||||
|
## grid 4
|
||||||
|
just some exampl^e text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
## grid 6
|
||||||
|
{5:╔═════════╗}|
|
||||||
|
{5:║}{1: halloj! }{5:║}|
|
||||||
|
{5:║}{1: BORDAA }{5:║}|
|
||||||
|
{5:╚═════════╝}|
|
||||||
|
]], float_pos={
|
||||||
|
[6] = {{id = 1003}, "NW", 4, 1, 14, true}
|
||||||
|
}}
|
||||||
|
else
|
||||||
|
screen:expect([[
|
||||||
|
just some example text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{5:[No Name] [+] }|
|
||||||
|
just some exampl^e text |
|
||||||
|
some more exam{5:╔═════════╗} |
|
||||||
|
{0:~ }{5:║}{1: halloj! }{5:║}{0: }|
|
||||||
|
{0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
|
||||||
|
{0:~ }{5:╚═════════╝}{0: }|
|
||||||
|
{4:[No Name] [+] }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end
|
||||||
|
|
||||||
|
meths.win_set_config(win, {relative='cursor', row=0, col=-2, anchor='NE'})
|
||||||
|
if multigrid then
|
||||||
|
screen:expect{grid=[[
|
||||||
|
## grid 1
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
{5:[No Name] [+] }|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
{4:[No Name] [+] }|
|
||||||
|
[3:----------------------------------------]|
|
||||||
|
## grid 2
|
||||||
|
just some example text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
## grid 3
|
||||||
|
|
|
||||||
|
## grid 4
|
||||||
|
just some exampl^e text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
## grid 6
|
||||||
|
{5:╔═════════╗}|
|
||||||
|
{5:║}{1: halloj! }{5:║}|
|
||||||
|
{5:║}{1: BORDAA }{5:║}|
|
||||||
|
{5:╚═════════╝}|
|
||||||
|
]], float_pos={
|
||||||
|
[6] = {{id = 1003}, "NE", 4, 0, 14, true}
|
||||||
|
}}
|
||||||
|
else
|
||||||
|
screen:expect([[
|
||||||
|
just some example text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{5:[No Name] [+] }|
|
||||||
|
jus{5:╔═════════╗}pl^e text |
|
||||||
|
som{5:║}{1: halloj! }{5:║}ple text |
|
||||||
|
{0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
|
||||||
|
{0:~ }{5:╚═════════╝}{0: }|
|
||||||
|
{0:~ }|
|
||||||
|
{4:[No Name] [+] }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end
|
||||||
|
|
||||||
|
meths.win_set_config(win, {relative='cursor', row=1, col=-2, anchor='SE'})
|
||||||
|
if multigrid then
|
||||||
|
screen:expect{grid=[[
|
||||||
|
## grid 1
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
{5:[No Name] [+] }|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
{4:[No Name] [+] }|
|
||||||
|
[3:----------------------------------------]|
|
||||||
|
## grid 2
|
||||||
|
just some example text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
## grid 3
|
||||||
|
|
|
||||||
|
## grid 4
|
||||||
|
just some exampl^e text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
## grid 6
|
||||||
|
{5:╔═════════╗}|
|
||||||
|
{5:║}{1: halloj! }{5:║}|
|
||||||
|
{5:║}{1: BORDAA }{5:║}|
|
||||||
|
{5:╚═════════╝}|
|
||||||
|
]], float_pos={
|
||||||
|
[6] = {{id = 1003}, "SE", 4, 1, 14, true}
|
||||||
|
}}
|
||||||
|
else
|
||||||
|
screen:expect([[
|
||||||
|
just some example text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }{5:╔═════════╗}{0: }|
|
||||||
|
{0:~ }{5:║}{1: halloj! }{5:║}{0: }|
|
||||||
|
{5:[No║}{1: BORDAA }{5:║ }|
|
||||||
|
jus{5:╚═════════╝}pl^e text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{4:[No Name] [+] }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end
|
||||||
|
|
||||||
|
meths.win_set_config(win, {relative='cursor', row=0, col=-2, anchor='SW'})
|
||||||
|
if multigrid then
|
||||||
|
screen:expect{grid=[[
|
||||||
|
## grid 1
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
[2:----------------------------------------]|
|
||||||
|
{5:[No Name] [+] }|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
[4:----------------------------------------]|
|
||||||
|
{4:[No Name] [+] }|
|
||||||
|
[3:----------------------------------------]|
|
||||||
|
## grid 2
|
||||||
|
just some example text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
## grid 3
|
||||||
|
|
|
||||||
|
## grid 4
|
||||||
|
just some exampl^e text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
## grid 6
|
||||||
|
{5:╔═════════╗}|
|
||||||
|
{5:║}{1: halloj! }{5:║}|
|
||||||
|
{5:║}{1: BORDAA }{5:║}|
|
||||||
|
{5:╚═════════╝}|
|
||||||
|
]], float_pos={
|
||||||
|
[6] = {{id = 1003}, "SW", 4, 0, 14, true}
|
||||||
|
}}
|
||||||
|
else
|
||||||
|
screen:expect([[
|
||||||
|
just some example text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }{5:╔═════════╗}{0: }|
|
||||||
|
{0:~ }{5:║}{1: halloj! }{5:║}{0: }|
|
||||||
|
{0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
|
||||||
|
{5:[No Name] [+] ╚═════════╝ }|
|
||||||
|
just some exampl^e text |
|
||||||
|
some more example text |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{4:[No Name] [+] }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
it('can be placed relative text in a window', function()
|
it('can be placed relative text in a window', function()
|
||||||
screen:try_resize(30,5)
|
screen:try_resize(30,5)
|
||||||
local firstwin = meths.get_current_win().id
|
local firstwin = meths.get_current_win().id
|
||||||
|
Loading…
Reference in New Issue
Block a user