windows: float config changes

- Allow floating windows of width 1. #9846
- For a new floating window the size must be specified. Later on we
  might try to calculate a reasonable size by buffer contents
- Remember the configured size of a window, just like its position.
- Make get_config and set_config more consistent. Handle relative='' properly in set_config.
  get_config doesn't return keys that don't make sense for a non-floating window.
- Don't use width=0 for non-changed width, just omit the key.
This commit is contained in:
Björn Linse
2019-04-13 14:25:15 +02:00
parent d08692a824
commit c8acbe3b62
5 changed files with 198 additions and 61 deletions

View File

@@ -173,6 +173,13 @@ describe('floating windows', function()
local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=3, col=5})
local expected = {anchor='NW', col=5, external=false, focusable=true, height=2, relative='editor', row=3, width=20}
eq(expected, meths.win_get_config(win))
eq({relative='', external=false, focusable=true}, meths.win_get_config(0))
if multigrid then
meths.win_set_config(win, {external=true, width=10, height=1})
eq({external=true,focusable=true,width=10,height=1,relative=''}, meths.win_get_config(win))
end
end)
it('defaults to nonumber and NormalFloat highlight', function()
@@ -253,6 +260,112 @@ describe('floating windows', function()
end
end)
it('can have minimum size', function()
insert("the background text")
local buf = meths.create_buf(false, true)
meths.buf_set_lines(buf, 0, -1, true, {'x'})
local win = meths.open_win(buf, false, {relative='win', width=1, height=1, row=0, col=4, focusable=false})
if multigrid then
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
|
## grid 2
the background tex^t |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
## grid 4
{1:x}|
]], float_pos={
[4] = {{id = 1002}, "NW", 2, 0, 4, false}
}}
else
screen:expect([[
the {1:x}ackground tex^t |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
|
]])
end
meths.win_set_config(win, {relative='win', row=0, col=15})
if multigrid then
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
|
## grid 2
the background tex^t |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
## grid 4
{1:x}|
]], float_pos={
[4] = {{id = 1002}, "NW", 2, 0, 15, false}
}}
else
screen:expect([[
the background {1:x}ex^t |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
|
]])
end
meths.win_close(win,false)
if multigrid then
screen:expect([[
## grid 1
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
|
## grid 2
the background tex^t |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
]])
else
screen:expect([[
the background tex^t |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
|
]])
end
end)
it('API has proper error messages', function()
local buf = meths.create_buf(false,false)
eq({false, "Invalid key 'bork'"},
@@ -271,6 +384,10 @@ describe('floating windows', function()
meth_pcall(meths.open_win,buf, false, {width=-1,height=2,relative='editor'}))
eq({false, "'height' key must be a positive Integer"},
meth_pcall(meths.open_win,buf, false, {width=20,height=-1,relative='editor'}))
eq({false, "'height' key must be a positive Integer"},
meth_pcall(meths.open_win,buf, false, {width=20,height=0,relative='editor'}))
eq({false, "Must specify 'width' and 'height'"},
meth_pcall(meths.open_win,buf, false, {relative='editor'}))
end)
it('can be placed relative window or cursor', function()
@@ -836,15 +953,15 @@ describe('floating windows', function()
screen:expect([[
|
{0:~ }|
{0:~ }{1:such }{0: }|
{0:~ }{1:very }{0: }|
{0:~ }{1:^float }{0: }|
{0:~ }|
{0:~ }|
{0:~ }{2:~ }{0: }|
|
]])
end
meths.win_set_config(win, {width=0, height=3})
meths.win_set_config(win, {height=3})
feed('gg')
if multigrid then
screen:expect{grid=[[
@@ -1173,9 +1290,9 @@ describe('floating windows', function()
screen:expect([[
|
{0:~ }|
{0:~ }{1:^such }{0: }|
{0:~ }|
{0:~ }|
{0:~ }{1:^such }{0: }|
{0:~ }{1:very }{0: }|
{0:~ }{1:float }{0: }|
{0:~ }|
|
]])
@@ -3256,7 +3373,7 @@ describe('floating windows', function()
end
if multigrid then
meths.win_set_config(0, {external=true})
meths.win_set_config(0, {external=true, width=30, height=2})
expected_pos = {[3]={external=true}}
screen:expect{grid=[[
## grid 1
@@ -3274,12 +3391,12 @@ describe('floating windows', function()
{0:~ }|
{0:~ }|
## grid 3
^y |
{0:~ }|
^y |
{0:~ }|
]], float_pos=expected_pos}
else
eq({false, "UI doesn't support external windows"},
meth_pcall(meths.win_set_config, 0, {external=true}))
meth_pcall(meths.win_set_config, 0, {external=true, width=30, height=2}))
return
end
@@ -3547,7 +3664,8 @@ describe('floating windows', function()
it(":tabnew and :tabnext (external)", function()
if multigrid then
meths.win_set_config(win, {external=true})
-- also test external window wider than main screen
meths.win_set_config(win, {external=true, width=65, height=4})
expected_pos = {[3]={external=true}}
feed(":tabnew<cr>")
screen:expect{grid=[[
@@ -3567,8 +3685,10 @@ describe('floating windows', function()
{0:~ }|
{0:~ }|
## grid 3
y |
{0:~ }|
y |
{0:~ }|
{0:~ }|
{0:~ }|
## grid 4
^ |
{0:~ }|
@@ -3578,7 +3698,7 @@ describe('floating windows', function()
]], float_pos=expected_pos}
else
eq({false, "UI doesn't support external windows"},
meth_pcall(meths.win_set_config, 0, {external=true}))
meth_pcall(meths.win_set_config, 0, {external=true, width=65, height=4}))
end
feed(":tabnext<cr>")
@@ -3599,8 +3719,10 @@ describe('floating windows', function()
{0:~ }|
{0:~ }|
## grid 3
y |
{0:~ }|
y |
{0:~ }|
{0:~ }|
{0:~ }|
## grid 4
|
{0:~ }|
@@ -3628,8 +3750,10 @@ describe('floating windows', function()
{0:~ }|
{0:~ }|
## grid 3
y |
{0:~ }|
y |
{0:~ }|
{0:~ }|
{0:~ }|
## grid 4
^ |
{0:~ }|