mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
Merge pull request #29136 from zeertzjq/vim-8.2.0083
vim-patch:8.2.{0083,0109}
This commit is contained in:
@@ -4421,18 +4421,30 @@ static bool ins_tab(void)
|
||||
// Delete following spaces.
|
||||
int i = cursor->col - fpos.col;
|
||||
if (i > 0) {
|
||||
STRMOVE(ptr, ptr + i);
|
||||
if (!(State & VREPLACE_FLAG)) {
|
||||
char *newp = xmalloc((size_t)(curbuf->b_ml.ml_line_len - i));
|
||||
ptrdiff_t col = ptr - curbuf->b_ml.ml_line_ptr;
|
||||
if (col > 0) {
|
||||
memmove(newp, ptr - col, (size_t)col);
|
||||
}
|
||||
memmove(newp + col, ptr + i, (size_t)(curbuf->b_ml.ml_line_len - col - i));
|
||||
if (curbuf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) {
|
||||
xfree(curbuf->b_ml.ml_line_ptr);
|
||||
}
|
||||
curbuf->b_ml.ml_line_ptr = newp;
|
||||
curbuf->b_ml.ml_line_len -= i;
|
||||
curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY;
|
||||
inserted_bytes(fpos.lnum, change_col,
|
||||
cursor->col - change_col, fpos.col - change_col);
|
||||
} else {
|
||||
STRMOVE(ptr, ptr + i);
|
||||
}
|
||||
// correct replace stack.
|
||||
if ((State & REPLACE_FLAG) && !(State & VREPLACE_FLAG)) {
|
||||
for (temp = i; --temp >= 0;) {
|
||||
replace_join(repl_off);
|
||||
}
|
||||
}
|
||||
if (!(State & VREPLACE_FLAG)) {
|
||||
curbuf->b_ml.ml_line_len -= i;
|
||||
inserted_bytes(fpos.lnum, change_col,
|
||||
cursor->col - change_col, fpos.col - change_col);
|
||||
}
|
||||
}
|
||||
cursor->col -= i;
|
||||
|
||||
|
||||
@@ -379,6 +379,25 @@ describe('lua buffer event callbacks: on_lines', function()
|
||||
]],
|
||||
})
|
||||
end)
|
||||
|
||||
it('line lengths are correct when pressing TAB with folding #29119', function()
|
||||
api.nvim_buf_set_lines(0, 0, -1, true, { 'a', 'b' })
|
||||
|
||||
exec_lua([[
|
||||
_G.res = {}
|
||||
vim.o.foldmethod = 'indent'
|
||||
vim.o.softtabstop = -1
|
||||
vim.api.nvim_buf_attach(0, false, {
|
||||
on_lines = function(_, bufnr, _, row, _, end_row)
|
||||
local lines = vim.api.nvim_buf_get_lines(bufnr, row, end_row, true)
|
||||
table.insert(_G.res, lines)
|
||||
end
|
||||
})
|
||||
]])
|
||||
|
||||
feed('i<Tab>')
|
||||
eq({ '\ta' }, exec_lua('return _G.res[#_G.res]'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('lua: nvim_buf_attach on_bytes', function()
|
||||
|
||||
Reference in New Issue
Block a user