aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/buffer.c6
-rw-r--r--src/nvim/buffer_defs.h1
-rw-r--r--src/nvim/eval/funcs.c24
-rw-r--r--src/nvim/globals.h3
-rw-r--r--src/nvim/testdir/test_changelist.vim34
5 files changed, 55 insertions, 13 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 4830b200af..10ce893fe8 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -2483,6 +2483,9 @@ void buflist_setfpos(buf_T *const buf, win_T *const win, linenr_T lnum, colnr_T
wip->wi_mark.view = mark_view_make(win->w_topline, wip->wi_mark.mark);
}
}
+ if (win != NULL) {
+ wip->wi_changelistidx = win->w_changelistidx;
+ }
if (copy_options && win != NULL) {
// Save the window-specific option values.
copy_winopt(&win->w_onebuf_opt, &wip->wi_opt);
@@ -2586,6 +2589,9 @@ void get_winopts(buf_T *buf)
} else {
copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt);
}
+ if (wip != NULL) {
+ curwin->w_changelistidx = wip->wi_changelistidx;
+ }
if (curwin->w_float_config.style == kWinStyleMinimal) {
didset_window_options(curwin);
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 8c70765d30..c052c2fdfd 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -289,6 +289,7 @@ struct wininfo_S {
winopt_T wi_opt; // local window options
bool wi_fold_manual; // copy of w_fold_manual
garray_T wi_folds; // clone of w_folds
+ int wi_changelistidx; // copy of w_changelistidx
};
/*
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 5ee499e006..dac6bb6e34 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -2824,13 +2824,23 @@ static void f_getchangelist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
list_T *const l = tv_list_alloc(buf->b_changelistlen);
tv_list_append_list(rettv->vval.v_list, l);
- // The current window change list index tracks only the position in the
- // current buffer change list. For other buffers, use the change list
- // length as the current index.
- tv_list_append_number(rettv->vval.v_list,
- (buf == curwin->w_buffer)
- ? curwin->w_changelistidx
- : buf->b_changelistlen);
+ // The current window change list index tracks only the position for the
+ // current buffer. For other buffers use the stored index for the current
+ // window, or, if that's not available, the change list length.
+ int changelistindex;
+ if (buf == curwin->w_buffer) {
+ changelistindex = curwin->w_changelistidx;
+ } else {
+ wininfo_T *wip;
+
+ FOR_ALL_BUF_WININFO(buf, wip) {
+ if (wip->wi_win == curwin) {
+ break;
+ }
+ }
+ changelistindex = wip != NULL ? wip->wi_changelistidx : buf->b_changelistlen;
+ }
+ tv_list_append_number(rettv->vval.v_list, (varnumber_T)changelistindex);
for (int i = 0; i < buf->b_changelistlen; i++) {
if (buf->b_changelist[i].mark.lnum == 0) {
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index b585467bd0..9946085703 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -467,6 +467,9 @@ EXTERN buf_T *curbuf INIT(= NULL); // currently active buffer
#define FOR_ALL_BUFFERS_BACKWARDS(buf) \
for (buf_T *buf = lastbuf; buf != NULL; buf = buf->b_prev)
+#define FOR_ALL_BUF_WININFO(buf, wip) \
+ for ((wip) = (buf)->b_wininfo; (wip) != NULL; (wip) = (wip)->wi_next) // NOLINT
+
// Iterate through all the signs placed in a buffer
#define FOR_ALL_SIGNS_IN_BUF(buf, sign) \
for ((sign) = (buf)->b_signlist; (sign) != NULL; (sign) = (sign)->se_next) // NOLINT
diff --git a/src/nvim/testdir/test_changelist.vim b/src/nvim/testdir/test_changelist.vim
index 3741f32e69..f429968218 100644
--- a/src/nvim/testdir/test_changelist.vim
+++ b/src/nvim/testdir/test_changelist.vim
@@ -1,12 +1,30 @@
" Tests for the changelist functionality
" Tests for the getchangelist() function
-func Test_getchangelist()
- if !has("jumplist")
- return
- endif
+func Test_changelist_index()
+ edit Xfile1.txt
+ exe "normal iabc\<C-G>u\ndef\<C-G>u\nghi"
+ call assert_equal(3, getchangelist('%')[1])
+ " Move one step back in the changelist.
+ normal 2g;
+
+ hide edit Xfile2.txt
+ exe "normal iabcd\<C-G>u\ndefg\<C-G>u\nghij"
+ call assert_equal(3, getchangelist('%')[1])
+ " Move to the beginning of the changelist.
+ normal 99g;
+
+ " Check the changelist indices.
+ call assert_equal(0, getchangelist('%')[1])
+ call assert_equal(1, getchangelist('#')[1])
bwipe!
+ call delete('Xfile1.txt')
+ call delete('Xfile2.txt')
+endfunc
+
+func Test_getchangelist()
+ bwipe!
enew
call assert_equal([], 10->getchangelist())
call assert_equal([[], 0], getchangelist())
@@ -15,6 +33,7 @@ func Test_getchangelist()
call writefile(['line1', 'line2', 'line3'], 'Xfile2.txt')
edit Xfile1.txt
+ let buf_1 = bufnr()
exe "normal 1Goline\<C-G>u1.1"
exe "normal 3Goline\<C-G>u2.1"
exe "normal 5Goline\<C-G>u3.1"
@@ -26,6 +45,7 @@ func Test_getchangelist()
\ getchangelist('%'))
hide edit Xfile2.txt
+ let buf_2 = bufnr()
exe "normal 1GOline\<C-G>u1.0"
exe "normal 2Goline\<C-G>u2.0"
call assert_equal([[
@@ -37,10 +57,12 @@ func Test_getchangelist()
call assert_equal([[
\ {'lnum' : 2, 'col' : 4, 'coladd' : 0},
\ {'lnum' : 4, 'col' : 4, 'coladd' : 0},
- \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 3], getchangelist(2))
+ \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 2],
+ \ getchangelist(buf_1))
call assert_equal([[
\ {'lnum' : 1, 'col' : 6, 'coladd' : 0},
- \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2], getchangelist(3))
+ \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2],
+ \ getchangelist(buf_2))
bwipe!
call delete('Xfile1.txt')