From 0451391ec514eb83c7e366b80fcab21de9f8d4ed Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 10 Apr 2023 22:49:32 +0800 Subject: [PATCH] fix(mark): properly init mark views (#22996) --- src/nvim/mark.c | 2 +- src/nvim/mark.h | 2 +- src/nvim/shada.c | 2 ++ test/functional/editor/mark_spec.lua | 44 ++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 855fcb33ae..59ff3026b3 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -84,7 +84,7 @@ void clear_fmark(fmark_T *fm) FUNC_ATTR_NONNULL_ALL { free_fmark(*fm); - CLEAR_POINTER(fm); + *fm = (fmark_T)INIT_FMARK; } // Set named mark "c" to position "pos". diff --git a/src/nvim/mark.h b/src/nvim/mark.h index af0abba864..8c72579d0f 100644 --- a/src/nvim/mark.h +++ b/src/nvim/mark.h @@ -36,7 +36,7 @@ /// Clear given fmark #define CLEAR_FMARK(fmarkp_) \ - RESET_FMARK(fmarkp_, ((pos_T) { 0, 0, 0 }), 0, ((fmarkv_T) { 0 })) + RESET_FMARK(fmarkp_, ((pos_T) { 0, 0, 0 }), 0, ((fmarkv_T)INIT_FMARKV)) /// Set given extended mark (regular mark + file name) #define SET_XFMARK(xfmarkp_, mark_, fnum_, view_, fname_) \ diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 2d5eee7eec..78499922bf 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1307,6 +1307,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) .mark = cur_entry.data.filemark.mark, .fnum = (buf == NULL ? 0 : buf->b_fnum), .timestamp = cur_entry.timestamp, + .view = INIT_FMARKV, .additional_data = cur_entry.data.filemark.additional_data, }, }; @@ -1388,6 +1389,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) .mark = cur_entry.data.filemark.mark, .fnum = 0, .timestamp = cur_entry.timestamp, + .view = INIT_FMARKV, .additional_data = cur_entry.data.filemark.additional_data, }; if (cur_entry.type == kSDItemLocalMark) { diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua index 365f8527a0..a6e4b0c5eb 100644 --- a/test/functional/editor/mark_spec.lua +++ b/test/functional/editor/mark_spec.lua @@ -417,4 +417,48 @@ describe('named marks view', function() | ]]) end) + + it('fallback to standard behavior when mark is loaded from shada', function() + local screen = Screen.new(10, 6) + screen:attach() + command('edit ' .. file1) + feed('G') + feed('mA') + screen:expect([[ + 26 line | + 27 line | + 28 line | + 29 line | + ^30 line | + | + ]]) + command('set shadafile=Xtestfile-functional-editor-marks-shada') + finally(function() + command('set shadafile=NONE') + os.remove('Xtestfile-functional-editor-marks-shada') + end) + command('wshada!') + command('bwipe!') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + | + ]]) + command('rshada!') + command('edit ' .. file1) + feed('`"') + screen:expect([[ + 26 line | + 27 line | + 28 line | + 29 line | + ^30 line | + | + ]]) + feed('`A') + screen:expect_unchanged() + end) end)