mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 00:08:19 +00:00
vim-patch:8.2.4731: the changelist index is not remembered per buffer
Problem: The changelist index is not remembered per buffer.
Solution: Keep the changelist index per window and buffer. (closes vim/vim#10135,
closes vim/vim#2173)
db0ea7f2b0
Cherry-pick FOR_ALL_BUF_WININFO from patch 8.2.0500.
Cherry-pick test_changelist.vim change from patch 8.2.3795.
This commit is contained in:
@@ -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);
|
||||
|
@@ -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
|
||||
};
|
||||
|
||||
/*
|
||||
|
@@ -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) {
|
||||
|
@@ -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
|
||||
|
@@ -1,11 +1,29 @@
|
||||
" 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())
|
||||
@@ -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')
|
||||
|
Reference in New Issue
Block a user