fix(api/buffer): fix handling of viewport of non-current buffer

A lot of functions in move.c only worked for curwin, alternatively
took a `wp` arg but still only work if that happens to be curwin.

Refactor those that are needed for update_topline(wp) to work
for any window.

fixes #27723
fixes #27720
This commit is contained in:
bfredl
2024-03-11 13:19:49 +01:00
parent d5488633f6
commit 08fc1ebbaa
50 changed files with 844 additions and 814 deletions

View File

@@ -136,7 +136,7 @@ function ChildProcessStream.spawn(argv, env, io_extra)
end
--- @diagnostic disable-next-line:missing-fields
self._proc, self._pid = uv.spawn(prog, {
stdio = { self._child_stdin, self._child_stdout, 2, io_extra },
stdio = { self._child_stdin, self._child_stdout, 1, io_extra },
args = args,
--- @diagnostic disable-next-line:assign-type-mismatch
env = env,

View File

@@ -121,6 +121,66 @@ describe('api/buf', function()
eq({ 5, 2 }, api.nvim_win_get_cursor(win2))
end)
it('cursor position is maintained consistently with viewport', function()
local 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()
local lines = { 'line1', 'line2', 'line3', 'line4', 'line5', 'line6' }
local buf = api.nvim_get_current_buf()
api.nvim_buf_set_lines(buf, 0, -1, true, lines)
command('6')
command('new')
screen:expect {
grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
line5 |
line6 |
{1:~ }|*2
{3:[No Name] [+] }|
|
]],
}
api.nvim_buf_set_lines(buf, 0, -1, true, lines)
screen:expect {
grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
line3 |
line4 |
line5 |
line6 |
{3:[No Name] [+] }|
|
]],
}
command('wincmd w')
screen:expect {
grid = [[
|
{1:~ }|*4
{3:[No Name] }|
line3 |
line4 |
line5 |
^line6 |
{2:[No Name] [+] }|
|
]],
}
end)
it('line_count has defined behaviour for unloaded buffers', function()
-- we'll need to know our bufnr for when it gets unloaded
local bufnr = api.nvim_buf_get_number(0)
@@ -323,20 +383,20 @@ describe('api/buf', function()
]],
}
-- inserting just before topline scrolls up
api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect {
grid = [[
^ |
{1:~ }|*4
{2:[No Name] }|
mmm |
wwweeee |
xxx |
yyy |
zzz |
{3:[No Name] [+] }|
|
]],
unchanged = true,
}
end)
@@ -402,7 +462,6 @@ describe('api/buf', function()
]],
}
-- inserting just before topline scrolls up
api.nvim_buf_set_lines(buf, 3, 3, true, { 'mmm' })
screen:expect {
grid = [[
@@ -412,10 +471,10 @@ describe('api/buf', function()
mmm |
wwweeee |
{2:[No Name] [+] }|
mmm |
wwweeee |
xxx |
yyy |
zzz |
{3:[No Name] [+] }|
|
]],

View File

@@ -13,15 +13,19 @@ describe('ffi.cdef', function()
eq(
12,
exec_lua [[
exec_lua [=[
local ffi = require('ffi')
ffi.cdef('int curwin_col_off(void);')
ffi.cdef [[
typedef struct window_S win_T;
int win_col_off(win_T *wp);
extern win_T *curwin;
]]
vim.cmd('set number numberwidth=4 signcolumn=yes:4')
return ffi.C.curwin_col_off()
]]
return ffi.C.win_col_off(ffi.C.curwin)
]=]
)
eq(
@@ -30,7 +34,6 @@ describe('ffi.cdef', function()
local ffi = require('ffi')
ffi.cdef[[
typedef struct window_S win_T;
typedef struct {} stl_hlrec_t;
typedef struct {} StlClickRecord;
typedef struct {} statuscol_T;