mirror of
https://github.com/neovim/neovim.git
synced 2026-01-07 03:48:02 +10:00
fix(api): fix inconsistent behavior of topline touched in recent refactor
The change in #24824 0081549 was not a regression, however it was an
incomplete change. Unfortunately some common plugins come to depend on
this exising self-inconsistent behavior. These plugins are going to need
to update for 0.10
nvim_buf_set_lines used to NOT adjust the topline correctly if a buffer
was displayed in just one window. However, if displayed in multiple
windows, it was correctly adjusted for any window not deemed the
current window for the buffer (which could be an arbitrary choice if the
buffer was not already current, as noted in the last rafactor)
This fixes so that all windows have their topline adjusted. The added
tests show this behavior, which should be the reasonable one.
This commit is contained in:
@@ -137,6 +137,139 @@ describe('api/buf', function()
|
||||
-- it's impossible to get out-of-bounds errors for an unloaded buffer
|
||||
eq({}, buffer('get_lines', bufnr, 8888, 9999, 1))
|
||||
end)
|
||||
|
||||
describe('handles topline', function()
|
||||
local screen
|
||||
before_each(function()
|
||||
screen = Screen.new(20, 12)
|
||||
screen:set_default_attr_ids {
|
||||
[1] = {bold = true, foreground = Screen.colors.Blue1};
|
||||
[2] = {reverse = true, bold = true};
|
||||
[3] = {reverse = true};
|
||||
}
|
||||
screen:attach()
|
||||
meths.buf_set_lines(0, 0, -1, 1, {"aaa", "bbb", "ccc", "ddd", "www", "xxx", "yyy", "zzz"})
|
||||
meths.set_option_value('modified', false, {})
|
||||
end)
|
||||
|
||||
it('of current window', function()
|
||||
local win = meths.get_current_win()
|
||||
local buf = meths.get_current_buf()
|
||||
|
||||
command('new | wincmd w')
|
||||
meths.win_set_cursor(win, {8,0})
|
||||
|
||||
screen:expect{grid=[[
|
||||
|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{3:[No Name] }|
|
||||
www |
|
||||
xxx |
|
||||
yyy |
|
||||
^zzz |
|
||||
{2:[No Name] }|
|
||||
|
|
||||
]]}
|
||||
meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"})
|
||||
|
||||
screen:expect{grid=[[
|
||||
|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{3:[No Name] }|
|
||||
www |
|
||||
xxx |
|
||||
yyy |
|
||||
^zzz |
|
||||
{2:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('of non-current window', function()
|
||||
local win = meths.get_current_win()
|
||||
local buf = meths.get_current_buf()
|
||||
|
||||
command('new')
|
||||
meths.win_set_cursor(win, {8,0})
|
||||
|
||||
screen:expect{grid=[[
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:[No Name] }|
|
||||
www |
|
||||
xxx |
|
||||
yyy |
|
||||
zzz |
|
||||
{3:[No Name] }|
|
||||
|
|
||||
]]}
|
||||
|
||||
meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"})
|
||||
screen:expect{grid=[[
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:[No Name] }|
|
||||
www |
|
||||
xxx |
|
||||
yyy |
|
||||
zzz |
|
||||
{3:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('of split windows with same buffer', function()
|
||||
local win = meths.get_current_win()
|
||||
local buf = meths.get_current_buf()
|
||||
|
||||
command('split')
|
||||
meths.win_set_cursor(win, {8,0})
|
||||
meths.win_set_cursor(0, {1,0})
|
||||
|
||||
screen:expect{grid=[[
|
||||
^aaa |
|
||||
bbb |
|
||||
ccc |
|
||||
ddd |
|
||||
www |
|
||||
{2:[No Name] }|
|
||||
www |
|
||||
xxx |
|
||||
yyy |
|
||||
zzz |
|
||||
{3:[No Name] }|
|
||||
|
|
||||
]]}
|
||||
meths.buf_set_lines(buf, 0, 2, true, {"aaabbb"})
|
||||
|
||||
screen:expect{grid=[[
|
||||
^aaabbb |
|
||||
ccc |
|
||||
ddd |
|
||||
www |
|
||||
xxx |
|
||||
{2:[No Name] [+] }|
|
||||
www |
|
||||
xxx |
|
||||
yyy |
|
||||
zzz |
|
||||
{3:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('deprecated: {get,set,del}_line', function()
|
||||
@@ -659,6 +792,139 @@ describe('api/buf', function()
|
||||
]])
|
||||
eq({'one', 'two'}, get_lines(0, 2, true))
|
||||
end)
|
||||
|
||||
describe('handles topline', function()
|
||||
local screen
|
||||
before_each(function()
|
||||
screen = Screen.new(20, 12)
|
||||
screen:set_default_attr_ids {
|
||||
[1] = {bold = true, foreground = Screen.colors.Blue1};
|
||||
[2] = {reverse = true, bold = true};
|
||||
[3] = {reverse = true};
|
||||
}
|
||||
screen:attach()
|
||||
meths.buf_set_lines(0, 0, -1, 1, {"aaa", "bbb", "ccc", "ddd", "www", "xxx", "yyy", "zzz"})
|
||||
meths.set_option_value('modified', false, {})
|
||||
end)
|
||||
|
||||
it('of current window', function()
|
||||
local win = meths.get_current_win()
|
||||
local buf = meths.get_current_buf()
|
||||
|
||||
command('new | wincmd w')
|
||||
meths.win_set_cursor(win, {8,0})
|
||||
|
||||
screen:expect{grid=[[
|
||||
|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{3:[No Name] }|
|
||||
www |
|
||||
xxx |
|
||||
yyy |
|
||||
^zzz |
|
||||
{2:[No Name] }|
|
||||
|
|
||||
]]}
|
||||
meths.buf_set_text(buf, 0,3, 1,0, {"X"})
|
||||
|
||||
screen:expect{grid=[[
|
||||
|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{3:[No Name] }|
|
||||
www |
|
||||
xxx |
|
||||
yyy |
|
||||
^zzz |
|
||||
{2:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('of non-current window', function()
|
||||
local win = meths.get_current_win()
|
||||
local buf = meths.get_current_buf()
|
||||
|
||||
command('new')
|
||||
meths.win_set_cursor(win, {8,0})
|
||||
|
||||
screen:expect{grid=[[
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:[No Name] }|
|
||||
www |
|
||||
xxx |
|
||||
yyy |
|
||||
zzz |
|
||||
{3:[No Name] }|
|
||||
|
|
||||
]]}
|
||||
|
||||
meths.buf_set_text(buf, 0,3, 1,0, {"X"})
|
||||
screen:expect{grid=[[
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:[No Name] }|
|
||||
www |
|
||||
xxx |
|
||||
yyy |
|
||||
zzz |
|
||||
{3:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('of split windows with same buffer', function()
|
||||
local win = meths.get_current_win()
|
||||
local buf = meths.get_current_buf()
|
||||
|
||||
command('split')
|
||||
meths.win_set_cursor(win, {8,0})
|
||||
meths.win_set_cursor(0, {1,1})
|
||||
|
||||
screen:expect{grid=[[
|
||||
a^aa |
|
||||
bbb |
|
||||
ccc |
|
||||
ddd |
|
||||
www |
|
||||
{2:[No Name] }|
|
||||
www |
|
||||
xxx |
|
||||
yyy |
|
||||
zzz |
|
||||
{3:[No Name] }|
|
||||
|
|
||||
]]}
|
||||
meths.buf_set_text(buf, 0,3, 1,0, {"X"})
|
||||
|
||||
screen:expect{grid=[[
|
||||
a^aaXbbb |
|
||||
ccc |
|
||||
ddd |
|
||||
www |
|
||||
xxx |
|
||||
{2:[No Name] [+] }|
|
||||
www |
|
||||
xxx |
|
||||
yyy |
|
||||
zzz |
|
||||
{3:[No Name] [+] }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe_lua_and_rpc('nvim_buf_get_text', function(api)
|
||||
|
||||
Reference in New Issue
Block a user