From 9b9030ff2ca820d4c4f4b559f86b0f9a3496645b Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 27 Aug 2023 11:20:59 +0200 Subject: fix(api): fix inconsistent behavior of topline touched in recent refactor The change in #24824 0081549 was not a regression, however it was an incomplete change. Unfortunately some common plugins come to depend on this exising self-inconsistent behavior. These plugins are going to need to update for 0.10 nvim_buf_set_lines used to NOT adjust the topline correctly if a buffer was displayed in just one window. However, if displayed in multiple windows, it was correctly adjusted for any window not deemed the current window for the buffer (which could be an arbitrary choice if the buffer was not already current, as noted in the last rafactor) This fixes so that all windows have their topline adjusted. The added tests show this behavior, which should be the reasonable one. --- src/nvim/api/buffer.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/nvim/api/buffer.c') diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 775b6e8ea7..d36f0dd050 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -472,9 +472,11 @@ void nvim_buf_set_lines(uint64_t channel_id, Buffer buffer, Integer start, Integ kExtmarkUndo); changed_lines(buf, (linenr_T)start, 0, (linenr_T)end, (linenr_T)extra, true); - if (curwin->w_buffer == buf) { - // mark_adjust_buf handles non-current windows - fix_cursor(curwin, (linenr_T)start, (linenr_T)end, (linenr_T)extra); + + FOR_ALL_TAB_WINDOWS(tp, win) { + if (win->w_buffer == buf) { + fix_cursor(win, (linenr_T)start, (linenr_T)end, (linenr_T)extra); + } } end: @@ -710,7 +712,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In // changed range, and move any in the remainder of the buffer. // Do not adjust any cursors. need to use column-aware logic (below) mark_adjust_buf(buf, (linenr_T)start_row, (linenr_T)end_row, MAXLNUM, (linenr_T)extra, - true, false, kExtmarkNOOP); + true, true, kExtmarkNOOP); extmark_splice(buf, (int)start_row - 1, (colnr_T)start_col, (int)(end_row - start_row), col_extent, old_byte, -- cgit