diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/buffer.c | 6 | ||||
-rw-r--r-- | src/nvim/buffer_defs.h | 1 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 24 | ||||
-rw-r--r-- | src/nvim/globals.h | 3 | ||||
-rw-r--r-- | src/nvim/testdir/test_changelist.vim | 69 | ||||
-rw-r--r-- | src/nvim/testdir/test_normal.vim | 27 | ||||
-rw-r--r-- | src/nvim/window.c | 7 |
7 files changed, 95 insertions, 42 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..3bb22a89b8 100644 --- a/src/nvim/testdir/test_changelist.vim +++ b/src/nvim/testdir/test_changelist.vim @@ -1,12 +1,65 @@ " Tests for the changelist functionality +" When splitting a window the changelist position is wrong. +" Test the changelist position after splitting a window. +" Test for the bug fixed by 7.4.386 +func Test_changelist() + let save_ul = &ul + enew! + call append('$', ['1', '2']) + exe "normal i\<C-G>u" + exe "normal Gkylpa\<C-G>u" + set ul=100 + exe "normal Gylpa\<C-G>u" + set ul=100 + normal gg + vsplit + normal g; + call assert_equal([3, 2], [line('.'), col('.')]) + normal g; + call assert_equal([2, 2], [line('.'), col('.')]) + call assert_fails('normal g;', 'E662:') + new + call assert_fails('normal g;', 'E664:') + %bwipe! + let &ul = save_ul +endfunc + +" Moving a split should not change its changelist index. +func Test_changelist_index_move_split() + exe "norm! iabc\<C-G>u\ndef\<C-G>u\nghi" + vsplit + normal 99g; + call assert_equal(0, getchangelist('%')[1]) + wincmd L + call assert_equal(0, getchangelist('%')[1]) +endfunc + " 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 +68,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 +80,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 +92,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') diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index 9fbd1f774a..ffa0cd1807 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -2849,35 +2849,10 @@ func Test_gr_command() enew! endfunc -" When splitting a window the changelist position is wrong. -" Test the changelist position after splitting a window. -" Test for the bug fixed by 7.4.386 -func Test_changelist() - let save_ul = &ul - enew! - call append('$', ['1', '2']) - exe "normal i\<C-G>u" - exe "normal Gkylpa\<C-G>u" - set ul=100 - exe "normal Gylpa\<C-G>u" - set ul=100 - normal gg - vsplit - normal g; - call assert_equal([3, 2], [line('.'), col('.')]) - normal g; - call assert_equal([2, 2], [line('.'), col('.')]) - call assert_fails('normal g;', 'E662:') - new - call assert_fails('normal g;', 'E664:') - %bwipe! - let &ul = save_ul -endfunc - func Test_nv_hat_count() %bwipeout! let l:nr = bufnr('%') + 1 - call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92') + call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92:') edit Xfoo let l:foo_nr = bufnr('Xfoo') diff --git a/src/nvim/window.c b/src/nvim/window.c index 8f52f40ef2..97ca45662e 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -1501,9 +1501,6 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) } } - // Keep same changelist position in new window. - wp->w_changelistidx = oldwin->w_changelistidx; - // make the new window the current window win_enter_ext(wp, WEE_TRIGGER_NEW_AUTOCMDS | WEE_TRIGGER_ENTER_AUTOCMDS | WEE_TRIGGER_LEAVE_AUTOCMDS); @@ -1574,6 +1571,10 @@ static void win_init(win_T *newp, win_T *oldp, int flags) } newp->w_tagstackidx = oldp->w_tagstackidx; newp->w_tagstacklen = oldp->w_tagstacklen; + + // Keep same changelist position in new window. + newp->w_changelistidx = oldp->w_changelistidx; + copyFoldingState(oldp, newp); win_init_some(newp, oldp); |