diff --git a/src/nvim/change.c b/src/nvim/change.c index 5c83db82d5..544574ffe6 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -460,12 +460,20 @@ void inserted_bytes(linenr_T lnum, colnr_T start_col, int old_col, int new_col) changed_bytes(lnum, start_col); } +/// Appended "count" lines below line "lnum" in the given buffer. +/// Must be called AFTER the change and after mark_adjust(). +/// Takes care of marking the buffer to be redrawn and sets the changed flag. +void appended_lines_buf(buf_T *buf, linenr_T lnum, linenr_T count) +{ + changed_lines(buf, lnum + 1, 0, lnum + 1, count, true); +} + /// Appended "count" lines below line "lnum" in the current buffer. /// Must be called AFTER the change and after mark_adjust(). /// Takes care of marking the buffer to be redrawn and sets the changed flag. void appended_lines(linenr_T lnum, linenr_T count) { - changed_lines(curbuf, lnum + 1, 0, lnum + 1, count, true); + appended_lines_buf(curbuf, lnum, count); } /// Like appended_lines(), but adjust marks first. @@ -475,12 +483,20 @@ void appended_lines_mark(linenr_T lnum, int count) changed_lines(curbuf, lnum + 1, 0, lnum + 1, (linenr_T)count, true); } +/// Deleted "count" lines at line "lnum" in the given buffer. +/// Must be called AFTER the change and after mark_adjust(). +/// Takes care of marking the buffer to be redrawn and sets the changed flag. +void deleted_lines_buf(buf_T *buf, linenr_T lnum, linenr_T count) +{ + changed_lines(buf, lnum, 0, lnum + count, -count, true); +} + /// Deleted "count" lines at line "lnum" in the current buffer. /// Must be called AFTER the change and after mark_adjust(). /// Takes care of marking the buffer to be redrawn and sets the changed flag. void deleted_lines(linenr_T lnum, linenr_T count) { - changed_lines(curbuf, lnum, 0, lnum + count, -count, true); + deleted_lines_buf(curbuf, lnum, count); } /// Like deleted_lines(), but adjust marks first. diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index aa5222748b..38b21f2b9a 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -2017,14 +2017,9 @@ static void refresh_terminal(Terminal *term) } linenr_T ml_before = buf->b_ml.ml_line_count; - // Some refresh_ functions assume the terminal buffer is current. Don't call refresh_cursor here, - // as we don't want a terminal that was possibly made temporarily current influencing the cursor. - aco_save_T aco; - aucmd_prepbuf(&aco, buf); refresh_size(term, buf); refresh_scrollback(term, buf); refresh_screen(term, buf); - aucmd_restbuf(&aco); int ml_added = buf->b_ml.ml_line_count - ml_before; adjust_topline(term, buf, ml_added); @@ -2156,7 +2151,6 @@ static void adjust_scrollback(Terminal *term, buf_T *buf) // Refresh the scrollback of an invalidated terminal. static void refresh_scrollback(Terminal *term, buf_T *buf) { - assert(buf == curbuf); // TODO(seandewar): remove this condition int width, height; vterm_get_size(term->vt, &height, &width); @@ -2165,8 +2159,8 @@ static void refresh_scrollback(Terminal *term, buf_T *buf) int row_offset = term->sb_pending; while (term->sb_pending > 0 && buf->b_ml.ml_line_count < height) { fetch_row(term, term->sb_pending - row_offset - 1, width); - ml_append(0, term->textbuf, 0, false); - appended_lines(0, 1); + ml_append_buf(buf, 0, term->textbuf, 0, false); + appended_lines_buf(buf, 0, 1); term->sb_pending--; } @@ -2178,21 +2172,21 @@ static void refresh_scrollback(Terminal *term, buf_T *buf) // section of the buffer if (((int)buf->b_ml.ml_line_count - height) >= (int)term->sb_size) { // scrollback full, delete lines at the top - ml_delete(1, false); - deleted_lines(1, 1); + ml_delete_buf(buf, 1, false); + deleted_lines_buf(buf, 1, 1); } fetch_row(term, -term->sb_pending - row_offset, width); int buf_index = (int)buf->b_ml.ml_line_count - height; - ml_append(buf_index, term->textbuf, 0, false); - appended_lines(buf_index, 1); + ml_append_buf(buf, buf_index, term->textbuf, 0, false); + appended_lines_buf(buf, buf_index, 1); term->sb_pending--; } // Remove extra lines at the bottom int max_line_count = (int)term->sb_current + height; while (buf->b_ml.ml_line_count > max_line_count) { - ml_delete(buf->b_ml.ml_line_count, false); - deleted_lines(buf->b_ml.ml_line_count, 1); + ml_delete_buf(buf, buf->b_ml.ml_line_count, false); + deleted_lines_buf(buf, buf->b_ml.ml_line_count, 1); } adjust_scrollback(term, buf); @@ -2202,7 +2196,6 @@ static void refresh_scrollback(Terminal *term, buf_T *buf) // focused) of a invalidated terminal static void refresh_screen(Terminal *term, buf_T *buf) { - assert(buf == curbuf); // TODO(bfredl): remove this condition int changed = 0; int added = 0; int height; @@ -2223,10 +2216,10 @@ static void refresh_screen(Terminal *term, buf_T *buf) fetch_row(term, r, width); if (linenr <= buf->b_ml.ml_line_count) { - ml_replace(linenr, term->textbuf, true); + ml_replace_buf(buf, linenr, term->textbuf, true, false); changed++; } else { - ml_append(linenr - 1, term->textbuf, 0, false); + ml_append_buf(buf, linenr - 1, term->textbuf, 0, false); added++; } }