commit 2700f6642aef8f6f51e7623da8701a542fddb82b
parent 02e10d5101da33bde6e050c258ccf29ae6d858c9
Author: zeertzjq <zeertzjq@outlook.com>
Date: Mon, 15 Dec 2025 14:45:11 +0800
fix(buffer): switching buffer should respect jumpoptions+=view (#36969)
Also add missing change to buflist_findfmark() from #19224.
Diffstat:
2 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
@@ -2238,7 +2238,8 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
/// Go to the last known line number for the current buffer.
static void buflist_getfpos(void)
{
- pos_T *fpos = &buflist_findfmark(curbuf)->mark;
+ fmark_T *fm = buflist_findfmark(curbuf);
+ const pos_T *fpos = &fm->mark;
curwin->w_cursor.lnum = fpos->lnum;
check_cursor_lnum(curwin);
@@ -2251,6 +2252,10 @@ static void buflist_getfpos(void)
curwin->w_cursor.coladd = 0;
curwin->w_set_curswant = true;
}
+
+ if (jop_flags & kOptJopFlagView) {
+ mark_view_restore(fm);
+ }
}
/// Find file in buffer list by name (it has to be for the current window).
@@ -2831,7 +2836,7 @@ void get_winopts(buf_T *buf)
fmark_T *buflist_findfmark(buf_T *buf)
FUNC_ATTR_PURE
{
- static fmark_T no_position = { { 1, 0, 0 }, 0, 0, { 0 }, NULL };
+ static fmark_T no_position = { { 1, 0, 0 }, 0, 0, INIT_FMARKV, NULL };
WinInfo *const wip = find_wininfo(buf, false, false);
return (wip == NULL) ? &no_position : &(wip->wi_mark);
diff --git a/test/functional/editor/jump_spec.lua b/test/functional/editor/jump_spec.lua
@@ -423,27 +423,36 @@ describe('jumpoptions=view', function()
]])
end)
- it('restores the view across files with <C-^>', function()
+ it('restores the view across files with <C-^>/:bprevious/:bnext', function()
local screen = Screen.new(5, 5)
command('args ' .. file1 .. ' ' .. file2)
feed('12Gzt')
+ local s1 = [[
+ ^12 line |
+ 13 line |
+ 14 line |
+ 15 line |
+ |
+ ]]
+ screen:expect(s1)
command('next')
feed('G')
- screen:expect([[
+ local s2 = [[
27 line |
28 line |
29 line |
^30 line |
|
- ]])
+ ]]
+ screen:expect(s2)
feed('<C-^>')
- screen:expect([[
- ^12 line |
- 13 line |
- 14 line |
- 15 line |
- |
- ]])
+ screen:expect(s1)
+ feed('<C-^>')
+ screen:expect(s2)
+ command('bprevious')
+ screen:expect(s1)
+ command('bnext')
+ screen:expect(s2)
end)
it("falls back to standard behavior when view can't be recovered", function()