refactor(change): do API changes to buffer without curbuf switch

Most of the messy things when changing a non-current buffer is
not about the buffer, it is about windows. In particular, it is about
`curwin`.

When editing a non-current buffer which is displayed in some other
window in the current tabpage, one such window will be "borrowed" as the
curwin. But this means if two or more non-current windows displayed the buffers,
one of them will be treated differenty. this is not desirable.

In particular, with nvim_buf_set_text, cursor _column_ position was only
corrected for one single window. Two new tests are added: the test
with just one non-current window passes, but the one with two didn't.

Two corresponding such tests were also added for nvim_buf_set_lines.
This already worked correctly on master, but make sure this is
well-tested for future refactors.

Also, nvim_create_buf no longer invokes autocmds just because you happened
to use `scratch=true`. No option value was changed, therefore OptionSet
must not be fired.
This commit is contained in:
bfredl
2023-08-21 14:52:17 +02:00
parent 1635c9e75e
commit 0081549547
33 changed files with 737 additions and 548 deletions

View File

@@ -1251,6 +1251,98 @@ AAAB]]
]]}
end)
end)
it('redraws with a change to non-current buffer', function()
write_file(fname, "aaa\nbbb\nccc\n\nxx", false)
write_file(fname_2, "aaa\nbbb\nccc\n\nyy", false)
reread()
local buf = meths.get_current_buf()
command('botright new')
screen:expect{grid=[[
{1: }aaa │{1: }aaa |
{1: }bbb │{1: }bbb |
{1: }ccc │{1: }ccc |
{1: } │{1: } |
{1: }{8:xx}{9: }│{1: }{8:yy}{9: }|
{6:~ }│{6:~ }|
{3:<onal-diff-screen-1 <l-diff-screen-1.2 }|
^ |
{6:~ }|
{6:~ }|
{6:~ }|
{6:~ }|
{6:~ }|
{6:~ }|
{7:[No Name] }|
:e |
]]}
meths.buf_set_lines(buf, 1, 2, true, {'BBB'})
screen:expect{grid=[[
{1: }aaa │{1: }aaa |
{1: }{8:BBB}{9: }│{1: }{8:bbb}{9: }|
{1: }ccc │{1: }ccc |
{1: } │{1: } |
{1: }{8:xx}{9: }│{1: }{8:yy}{9: }|
{6:~ }│{6:~ }|
{3:<-diff-screen-1 [+] <l-diff-screen-1.2 }|
^ |
{6:~ }|
{6:~ }|
{6:~ }|
{6:~ }|
{6:~ }|
{6:~ }|
{7:[No Name] }|
:e |
]]}
end)
it('redraws with a change current buffer in another window', function()
write_file(fname, "aaa\nbbb\nccc\n\nxx", false)
write_file(fname_2, "aaa\nbbb\nccc\n\nyy", false)
reread()
local buf = meths.get_current_buf()
command('botright split | diffoff')
screen:expect{grid=[[
{1: }aaa │{1: }aaa |
{1: }bbb │{1: }bbb |
{1: }ccc │{1: }ccc |
{1: } │{1: } |
{1: }{8:xx}{9: }│{1: }{8:yy}{9: }|
{6:~ }│{6:~ }|
{3:<onal-diff-screen-1 <l-diff-screen-1.2 }|
^aaa |
bbb |
ccc |
|
xx |
{6:~ }|
{6:~ }|
{7:Xtest-functional-diff-screen-1 }|
:e |
]]}
meths.buf_set_lines(buf, 1, 2, true, {'BBB'})
screen:expect{grid=[[
{1: }aaa │{1: }aaa |
{1: }{8:BBB}{9: }│{1: }{8:bbb}{9: }|
{1: }ccc │{1: }ccc |
{1: } │{1: } |
{1: }{8:xx}{9: }│{1: }{8:yy}{9: }|
{6:~ }│{6:~ }|
{3:<-diff-screen-1 [+] <l-diff-screen-1.2 }|
^aaa |
BBB |
ccc |
|
xx |
{6:~ }|
{6:~ }|
{7:Xtest-functional-diff-screen-1 [+] }|
:e |
]]}
end)
end)
it('win_update redraws lines properly', function()