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:
zeertzjq
2021-10-03 08:36:24 +08:00
committed by GitHub
parent c5e8c39102
commit b3e815094b
5 changed files with 295 additions and 83 deletions

View File

@@ -1866,6 +1866,293 @@ describe('float window', function()
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()
screen:try_resize(30,5)
local firstwin = meths.get_current_win().id