Mercurial > vim
changeset 23023:4384c44c031a v8.2.2058
patch 8.2.2058: using mkview/loadview changes the jumplist
Commit: https://github.com/vim/vim/commit/3482be6a33c3a00fe1e8e604310ad3034f593045
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Nov 27 11:00:38 2020 +0100
patch 8.2.2058: using mkview/loadview changes the jumplist
Problem: Using mkview/loadview changes the jumplist.
Solution: Use ":keepjumps". Don't let ":badd" or ":balt" change the
jumplist. (closes #7371)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 27 Nov 2020 11:15:06 +0100 |
parents | feae46642f33 |
children | 201ca8c66377 |
files | src/ex_docmd.c src/session.c src/testdir/test_mksession.vim src/version.c |
diffstat | 4 files changed, 76 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -6638,7 +6638,8 @@ do_exedit( else if (eap->cmdidx == CMD_enew) readonlymode = FALSE; // 'readonly' doesn't make sense in an // empty buffer - setpcmark(); + if (eap->cmdidx != CMD_balt && eap->cmdidx != CMD_badd) + setpcmark(); if (do_ecmd(0, (eap->cmdidx == CMD_enew ? NULL : eap->arg), NULL, eap, // ":edit" goes to first line if Vi compatible
--- a/src/session.c +++ b/src/session.c @@ -460,9 +460,9 @@ put_view( (long)wp->w_height / 2, (long)wp->w_height) < 0 || put_eol(fd) == FAIL || put_line(fd, "if s:l < 1 | let s:l = 1 | endif") == FAIL - || put_line(fd, "exe s:l") == FAIL + || put_line(fd, "keepjumps exe s:l") == FAIL || put_line(fd, "normal! zt") == FAIL - || fprintf(fd, "%ld", (long)wp->w_cursor.lnum) < 0 + || fprintf(fd, "keepjumps %ld", (long)wp->w_cursor.lnum) < 0 || put_eol(fd) == FAIL) return FAIL; // Restore the cursor column and left offset when not wrapping.
--- a/src/testdir/test_mksession.vim +++ b/src/testdir/test_mksession.vim @@ -586,6 +586,53 @@ func Test_mkview_no_file_name() %bwipe endfunc +func Test_mkview_loadview_jumplist() + set viewdir=Xviewdir + au BufWinLeave * silent mkview + au BufWinEnter * silent loadview + + edit Xfile1 + call setline(1, ['a', 'bbbbbbb', 'c']) + normal j3l + call assert_equal([2, 4], getcurpos()[1:2]) + write + + edit Xfile2 + call setline(1, ['d', 'eeeeeee', 'f']) + normal j5l + call assert_equal([2, 6], getcurpos()[1:2]) + write + + edit Xfile3 + call setline(1, ['g', 'h', 'iiiii']) + normal jj3l + call assert_equal([3, 4], getcurpos()[1:2]) + write + + edit Xfile1 + call assert_equal([2, 4], getcurpos()[1:2]) + edit Xfile2 + call assert_equal([2, 6], getcurpos()[1:2]) + edit Xfile3 + call assert_equal([3, 4], getcurpos()[1:2]) + + exe "normal \<C-O>" + call assert_equal('Xfile2', expand('%')) + call assert_equal([2, 6], getcurpos()[1:2]) + exe "normal \<C-O>" + call assert_equal('Xfile1', expand('%')) + call assert_equal([2, 4], getcurpos()[1:2]) + + au! BufWinLeave + au! BufWinEnter + bwipe! + call delete('Xviewdir', 'rf') + call delete('Xfile1') + call delete('Xfile2') + call delete('Xfile3') + set viewdir& +endfunc + " A clean session (one empty buffer, one window, and one tab) should not " set any error messages when sourced because no commands should fail. func Test_mksession_no_errmsg() @@ -872,4 +919,27 @@ func Test_scrolloff() set sessionoptions& endfunc +func Test_altfile() + edit Xone + split Xtwo + edit Xtwoalt + edit # + wincmd w + edit Xonealt + edit # + mksession! Xtest_altfile + only + bwipe Xonealt + bwipe Xtwoalt + bwipe! + source Xtest_altfile + call assert_equal('Xone', bufname()) + call assert_equal('Xonealt', bufname('#')) + wincmd w + call assert_equal('Xtwo', bufname()) + call assert_equal('Xtwoalt', bufname('#')) + only + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab