From 36dbd2686f450e5bf5ff7ac7a0cd42ef104e022d Mon Sep 17 00:00:00 2001 From: Andre Toerien Date: Sat, 19 Apr 2025 14:57:13 +0200 Subject: [PATCH] fix(shada): don't add '0' mark if f0 in 'shada' --- src/nvim/shada.c | 6 +- test/functional/shada/marks_spec.lua | 94 ++++++++++++++++++++++++++-- 2 files changed, 93 insertions(+), 7 deletions(-) diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 71ce4ce9ee..b70ee62674 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -2559,9 +2559,9 @@ static ShaDaWriteResult shada_write(FileDescriptor *const sd_writer, } } - // Update numbered marks: '0' should be replaced with the current position, - // '9' should be removed and all other marks shifted. - if (!ignore_buf(curbuf, &removable_bufs) && curwin->w_cursor.lnum != 0) { + // Update numbered marks: replace '0 mark with the current position, + // remove '9 and shift all other marks. Skip if f0 in 'shada'. + if (dump_global_marks && !ignore_buf(curbuf, &removable_bufs) && curwin->w_cursor.lnum != 0) { replace_numbered_mark(wms, 0, (PossiblyFreedShadaEntry) { .can_free_entry = false, .data = { diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index 528fa3a008..8463a2d675 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -51,29 +51,115 @@ describe('ShaDa support code', function() eq(2, nvim_current_line()) end) - it('does not dump global mark with `f0` in shada', function() + it('can dump and read back numbered marks', function() + local function move(cmd) + feed(cmd) + nvim_command('wshada') + end + nvim_command('edit ' .. testfilename) + move('l') + move('l') + move('j') + move('l') + move('l') + nvim_command('edit ' .. testfilename_2) + move('l') + move('l') + move('j') + move('l') + move('l') + -- we have now populated marks 0 through 9 + nvim_command('edit ' .. testfilename) + feed('gg0') + -- during shada save on exit, mark 0 will become the current position, + -- 9 will be removed, and all other marks shifted + expect_exit(nvim_command, 'qall') + reset() + nvim_command('edit ' .. testfilename) + nvim_command('edit ' .. testfilename_2) + local marklist = fn.getmarklist() + for _, mark in ipairs(marklist) do + mark.file = fn.fnamemodify(mark.file, ':t') + end + eq({ + { + file = testfilename, + mark = "'0", + pos = { 1, 1, 1, 0 }, + }, + { + file = testfilename_2, + mark = "'1", + pos = { 2, 2, 5, 0 }, + }, + { + file = testfilename_2, + mark = "'2", + pos = { 2, 2, 4, 0 }, + }, + { + file = testfilename_2, + mark = "'3", + pos = { 2, 2, 3, 0 }, + }, + { + file = testfilename_2, + mark = "'4", + pos = { 2, 1, 3, 0 }, + }, + { + file = testfilename_2, + mark = "'5", + pos = { 2, 1, 2, 0 }, + }, + { + file = testfilename, + mark = "'6", + pos = { 1, 2, 5, 0 }, + }, + { + file = testfilename, + mark = "'7", + pos = { 1, 2, 4, 0 }, + }, + { + file = testfilename, + mark = "'8", + pos = { 1, 2, 3, 0 }, + }, + { + file = testfilename, + mark = "'9", + pos = { 1, 1, 3, 0 }, + }, + }, marklist) + end) + + it('does not dump global or numbered marks with `f0` in shada', function() nvim_command('set shada+=f0') nvim_command('edit ' .. testfilename) nvim_command('mark A') nvim_command('2') - nvim_command('kB') nvim_command('wshada') reset() nvim_command('language C') eq('Vim(normal):E20: Mark not set', exc_exec('normal! `A')) + eq('Vim(normal):E20: Mark not set', exc_exec('normal! `0')) end) - it("does read back global mark even with `'0` and `f0` in shada", function() + it("restores global and numbered marks even with `'0` and `f0` in shada", function() nvim_command('edit ' .. testfilename) nvim_command('mark A') nvim_command('2') - nvim_command('kB') nvim_command('wshada') reset("set shada='0,f0") nvim_command('language C') nvim_command('normal! `A') eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) eq(1, nvim_current_line()) + nvim_command('normal! `0') + eq(testfilename, fn.fnamemodify(api.nvim_buf_get_name(0), ':t')) + eq(2, nvim_current_line()) end) it('is able to dump and read back local mark', function()