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 #10135,
closes #2173)
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 4829673..e56b505 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -4724,6 +4724,7 @@
int i;
list_T *l;
dict_T *d;
+ int changelistindex;
if (rettv_list_alloc(rettv) != OK)
return;
@@ -4745,13 +4746,25 @@
if (list_append_list(rettv->vval.v_list, l) == FAIL)
return;
/*
- * 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.
+ * 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.
*/
- list_append_number(rettv->vval.v_list,
- (varnumber_T)((buf == curwin->w_buffer)
- ? curwin->w_changelistidx : buf->b_changelistlen));
+ 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;
+ }
+ list_append_number(rettv->vval.v_list, (varnumber_T)changelistindex);
for (i = 0; i < buf->b_changelistlen; ++i)
{