fix(multicursor): prevent clipboard crash after cursor jump #41698

Problem:
Changing from an empty-line cursor after a multicursor jump can crash
while flushing a deferred clipboard update. Exact context restore can
leave an omitted register with a null array and stale non-zero size.

Solution:
Make free_register() fully reset the register after freeing its contents,
so it always leaves a valid empty register. Add a regression test.

Signed-off-by: sami <samiulsami7786@gmail.com>
This commit is contained in:
Samiul Islam
2026-09-04 23:06:50 +06:00
committed by GitHub
parent 630e0592b7
commit b7a0c71a54
2 changed files with 32 additions and 7 deletions

View File

@@ -2628,6 +2628,32 @@ describe('multicursor', function()
end)
describe('clipboard', function()
it("does not crash after jumping to an empty line with 'clipboard'", function()
n.exec_lua([[
_G.content = {}
vim.g.clipboard = {
name = 'test',
copy = {
['+'] = function(lines)
_G.content = lines
end,
},
paste = {
['+'] = function()
return _G.content
end,
},
}
vim.o.clipboard = 'unnamedplus'
]])
cursors({ '', 'aa' }, 'Qj') -- Cursor on the empty line, primary on the non-empty line.
feed(']C') -- Make the empty-line cursor primary.
feed('C')
n.assert_alive()
feed('<Esc>')
eq({ '', '' }, get_lines())
end)
it("perf: provider syncs once per cascade with 'clipboard'", function()
n.exec_lua([[
_G.copies = 0