summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-11-27 11:00:38 +0100
committerBram Moolenaar <Bram@vim.org>2020-11-27 11:00:38 +0100
commit3482be6a33c3a00fe1e8e604310ad3034f593045 (patch)
treed62e001dd9d50fc10d58d7a63c22aef9ac24531b
parentfccbf068f8c85474db8d8dead1530321d1f3e5b8 (diff)
downloadvim-git-8.2.2058.tar.gz
patch 8.2.2058: using mkview/loadview changes the jumplistv8.2.2058
Problem: Using mkview/loadview changes the jumplist. Solution: Use ":keepjumps". Don't let ":badd" or ":balt" change the jumplist. (closes #7371)
-rw-r--r--src/ex_docmd.c3
-rw-r--r--src/session.c4
-rw-r--r--src/testdir/test_mksession.vim70
-rw-r--r--src/version.c2
4 files changed, 76 insertions, 3 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 582791af6..a06e8a89d 100644
--- 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
diff --git a/src/session.c b/src/session.c
index 9731bd3a4..d0373bb39 100644
--- 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.
diff --git a/src/testdir/test_mksession.vim b/src/testdir/test_mksession.vim
index 7ae42f336..c2b8fb955 100644
--- 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
diff --git a/src/version.c b/src/version.c
index cebba1555..5bf2ef6d4 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2058,
+/**/
2057,
/**/
2056,