0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

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)
This commit is contained in:
Bram Moolenaar
2020-11-27 11:00:38 +01:00
parent fccbf068f8
commit 3482be6a33
4 changed files with 76 additions and 3 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2058,
/**/
2057,
/**/