mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 09:12:07 +00:00
fix(api): better topline adjustments in nvim_buf_set_lines
Some more reasonable defaults for topline: - if topline was replaced with another line, that now becomes topline - if line was inserted just before topline, display it. This is more similar to the previous API behavior.
This commit is contained in:
@@ -182,8 +182,8 @@ describe('api/buf', function()
|
||||
{2:[No Name] }|
|
||||
|
|
||||
]]}
|
||||
meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"})
|
||||
|
||||
meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"})
|
||||
screen:expect{grid=[[
|
||||
|
|
||||
{1:~ }|
|
||||
@@ -198,6 +198,72 @@ describe('api/buf', function()
|
||||
{2:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
|
||||
-- replacing topline keeps it the topline
|
||||
meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"})
|
||||
screen:expect{grid=[[
|
||||
|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{3:[No Name] }|
|
||||
wwweeee |
|
||||
xxx |
|
||||
yyy |
|
||||
^zzz |
|
||||
{2:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
|
||||
-- inserting just before topline does not scroll up if cursor would be moved
|
||||
meths.buf_set_lines(buf, 3, 3, true, {"mmm"})
|
||||
screen:expect{grid=[[
|
||||
|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{3:[No Name] }|
|
||||
wwweeee |
|
||||
xxx |
|
||||
yyy |
|
||||
^zzz |
|
||||
{2:[No Name] [+] }|
|
||||
|
|
||||
]], unchanged=true}
|
||||
|
||||
meths.win_set_cursor(0, {7, 0})
|
||||
screen:expect{grid=[[
|
||||
|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{3:[No Name] }|
|
||||
wwweeee |
|
||||
xxx |
|
||||
^yyy |
|
||||
zzz |
|
||||
{2:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
|
||||
meths.buf_set_lines(buf, 4, 4, true, {"mmmeeeee"})
|
||||
screen:expect{grid=[[
|
||||
|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{3:[No Name] }|
|
||||
mmmeeeee |
|
||||
wwweeee |
|
||||
xxx |
|
||||
^yyy |
|
||||
{2:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('of non-current window', function()
|
||||
@@ -237,6 +303,40 @@ describe('api/buf', function()
|
||||
{3:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
|
||||
-- replacing topline keeps it the topline
|
||||
meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"})
|
||||
screen:expect{grid=[[
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:[No Name] }|
|
||||
wwweeee |
|
||||
xxx |
|
||||
yyy |
|
||||
zzz |
|
||||
{3:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
|
||||
-- inserting just before topline scrolls up
|
||||
meths.buf_set_lines(buf, 3, 3, true, {"mmm"})
|
||||
screen:expect{grid=[[
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:[No Name] }|
|
||||
mmm |
|
||||
wwweeee |
|
||||
xxx |
|
||||
yyy |
|
||||
{3:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('of split windows with same buffer', function()
|
||||
@@ -277,6 +377,40 @@ describe('api/buf', function()
|
||||
{3:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
|
||||
-- replacing topline keeps it the topline
|
||||
meths.buf_set_lines(buf, 3, 4, true, {"wwweeee"})
|
||||
screen:expect{grid=[[
|
||||
^aaabbb |
|
||||
ccc |
|
||||
ddd |
|
||||
wwweeee |
|
||||
xxx |
|
||||
{2:[No Name] [+] }|
|
||||
wwweeee |
|
||||
xxx |
|
||||
yyy |
|
||||
zzz |
|
||||
{3:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
|
||||
-- inserting just before topline scrolls up
|
||||
meths.buf_set_lines(buf, 3, 3, true, {"mmm"})
|
||||
screen:expect{grid=[[
|
||||
^aaabbb |
|
||||
ccc |
|
||||
ddd |
|
||||
mmm |
|
||||
wwweeee |
|
||||
{2:[No Name] [+] }|
|
||||
mmm |
|
||||
wwweeee |
|
||||
xxx |
|
||||
yyy |
|
||||
{3:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
end)
|
||||
|
||||
|
Reference in New Issue
Block a user