Skip to content

Commit 6f84ea7

Browse files
zeertzjqgithub-actions[bot]
authored andcommitted
fix(buffer): switching buffer should respect jumpoptions+=view (#36969)
Also add missing change to buflist_findfmark() from #19224. (cherry picked from commit 2700f66)
1 parent 45cda1b commit 6f84ea7

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/nvim/buffer.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,8 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
22192219
/// Go to the last known line number for the current buffer.
22202220
void buflist_getfpos(void)
22212221
{
2222-
pos_T *fpos = &buflist_findfmark(curbuf)->mark;
2222+
fmark_T *fm = buflist_findfmark(curbuf);
2223+
const pos_T *fpos = &fm->mark;
22232224

22242225
curwin->w_cursor.lnum = fpos->lnum;
22252226
check_cursor_lnum(curwin);
@@ -2232,6 +2233,10 @@ void buflist_getfpos(void)
22322233
curwin->w_cursor.coladd = 0;
22332234
curwin->w_set_curswant = true;
22342235
}
2236+
2237+
if (jop_flags & kOptJopFlagView) {
2238+
mark_view_restore(fm);
2239+
}
22352240
}
22362241

22372242
/// Find file in buffer list by name (it has to be for the current window).
@@ -2812,7 +2817,7 @@ void get_winopts(buf_T *buf)
28122817
fmark_T *buflist_findfmark(buf_T *buf)
28132818
FUNC_ATTR_PURE
28142819
{
2815-
static fmark_T no_position = { { 1, 0, 0 }, 0, 0, { 0 }, NULL };
2820+
static fmark_T no_position = { { 1, 0, 0 }, 0, 0, INIT_FMARKV, NULL };
28162821

28172822
WinInfo *const wip = find_wininfo(buf, false, false);
28182823
return (wip == NULL) ? &no_position : &(wip->wi_mark);

test/functional/editor/jump_spec.lua

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -423,27 +423,36 @@ describe('jumpoptions=view', function()
423423
]])
424424
end)
425425

426-
it('restores the view across files with <C-^>', function()
426+
it('restores the view across files with <C-^>/:bprevious/:bnext', function()
427427
local screen = Screen.new(5, 5)
428428
command('args ' .. file1 .. ' ' .. file2)
429429
feed('12Gzt')
430+
local s1 = [[
431+
^12 line |
432+
13 line |
433+
14 line |
434+
15 line |
435+
|
436+
]]
437+
screen:expect(s1)
430438
command('next')
431439
feed('G')
432-
screen:expect([[
440+
local s2 = [[
433441
27 line |
434442
28 line |
435443
29 line |
436444
^30 line |
437445
|
438-
]])
446+
]]
447+
screen:expect(s2)
439448
feed('<C-^>')
440-
screen:expect([[
441-
^12 line |
442-
13 line |
443-
14 line |
444-
15 line |
445-
|
446-
]])
449+
screen:expect(s1)
450+
feed('<C-^>')
451+
screen:expect(s2)
452+
command('bprevious')
453+
screen:expect(s1)
454+
command('bnext')
455+
screen:expect(s2)
447456
end)
448457

449458
it("falls back to standard behavior when view can't be recovered", function()

0 commit comments

Comments
 (0)