fix(terminal): remove condition that buf is curbuf (#33721)

This commit is contained in:
Gregory Anders
2025-04-29 16:35:27 -05:00
committed by GitHub
parent 08c484f2ca
commit 99e754ae02
2 changed files with 28 additions and 19 deletions

View File

@@ -461,12 +461,20 @@ void inserted_bytes(linenr_T lnum, colnr_T start_col, int old_col, int new_col)
changed_bytes(lnum, start_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. /// Appended "count" lines below line "lnum" in the current buffer.
/// Must be called AFTER the change and after mark_adjust(). /// Must be called AFTER the change and after mark_adjust().
/// Takes care of marking the buffer to be redrawn and sets the changed flag. /// Takes care of marking the buffer to be redrawn and sets the changed flag.
void appended_lines(linenr_T lnum, linenr_T count) 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. /// Like appended_lines(), but adjust marks first.
@@ -476,12 +484,20 @@ void appended_lines_mark(linenr_T lnum, int count)
changed_lines(curbuf, lnum + 1, 0, lnum + 1, (linenr_T)count, true); 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. /// Deleted "count" lines at line "lnum" in the current buffer.
/// Must be called AFTER the change and after mark_adjust(). /// Must be called AFTER the change and after mark_adjust().
/// Takes care of marking the buffer to be redrawn and sets the changed flag. /// Takes care of marking the buffer to be redrawn and sets the changed flag.
void deleted_lines(linenr_T lnum, linenr_T count) 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. /// Like deleted_lines(), but adjust marks first.

View File

@@ -2029,14 +2029,9 @@ static void refresh_terminal(Terminal *term)
} }
linenr_T ml_before = buf->b_ml.ml_line_count; 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_size(term, buf);
refresh_scrollback(term, buf); refresh_scrollback(term, buf);
refresh_screen(term, buf); refresh_screen(term, buf);
aucmd_restbuf(&aco);
int ml_added = buf->b_ml.ml_line_count - ml_before; int ml_added = buf->b_ml.ml_line_count - ml_before;
adjust_topline(term, buf, ml_added); adjust_topline(term, buf, ml_added);
@@ -2168,7 +2163,6 @@ static void adjust_scrollback(Terminal *term, buf_T *buf)
// Refresh the scrollback of an invalidated terminal. // Refresh the scrollback of an invalidated terminal.
static void refresh_scrollback(Terminal *term, buf_T *buf) static void refresh_scrollback(Terminal *term, buf_T *buf)
{ {
assert(buf == curbuf); // TODO(seandewar): remove this condition
int width, height; int width, height;
vterm_get_size(term->vt, &height, &width); vterm_get_size(term->vt, &height, &width);
@@ -2177,8 +2171,8 @@ static void refresh_scrollback(Terminal *term, buf_T *buf)
int row_offset = term->sb_pending; int row_offset = term->sb_pending;
while (term->sb_pending > 0 && buf->b_ml.ml_line_count < height) { while (term->sb_pending > 0 && buf->b_ml.ml_line_count < height) {
fetch_row(term, term->sb_pending - row_offset - 1, width); fetch_row(term, term->sb_pending - row_offset - 1, width);
ml_append(0, term->textbuf, 0, false); ml_append_buf(buf, 0, term->textbuf, 0, false);
appended_lines(0, 1); appended_lines_buf(buf, 0, 1);
term->sb_pending--; term->sb_pending--;
} }
@@ -2190,21 +2184,21 @@ static void refresh_scrollback(Terminal *term, buf_T *buf)
// section of the buffer // section of the buffer
if (((int)buf->b_ml.ml_line_count - height) >= (int)term->sb_size) { if (((int)buf->b_ml.ml_line_count - height) >= (int)term->sb_size) {
// scrollback full, delete lines at the top // scrollback full, delete lines at the top
ml_delete(1, false); ml_delete_buf(buf, 1, false);
deleted_lines(1, 1); deleted_lines_buf(buf, 1, 1);
} }
fetch_row(term, -term->sb_pending - row_offset, width); fetch_row(term, -term->sb_pending - row_offset, width);
int buf_index = (int)buf->b_ml.ml_line_count - height; int buf_index = (int)buf->b_ml.ml_line_count - height;
ml_append(buf_index, term->textbuf, 0, false); ml_append_buf(buf, buf_index, term->textbuf, 0, false);
appended_lines(buf_index, 1); appended_lines_buf(buf, buf_index, 1);
term->sb_pending--; term->sb_pending--;
} }
// Remove extra lines at the bottom // Remove extra lines at the bottom
int max_line_count = (int)term->sb_current + height; int max_line_count = (int)term->sb_current + height;
while (buf->b_ml.ml_line_count > max_line_count) { while (buf->b_ml.ml_line_count > max_line_count) {
ml_delete(buf->b_ml.ml_line_count, false); ml_delete_buf(buf, buf->b_ml.ml_line_count, false);
deleted_lines(buf->b_ml.ml_line_count, 1); deleted_lines_buf(buf, buf->b_ml.ml_line_count, 1);
} }
adjust_scrollback(term, buf); adjust_scrollback(term, buf);
@@ -2214,7 +2208,6 @@ static void refresh_scrollback(Terminal *term, buf_T *buf)
// focused) of a invalidated terminal // focused) of a invalidated terminal
static void refresh_screen(Terminal *term, buf_T *buf) static void refresh_screen(Terminal *term, buf_T *buf)
{ {
assert(buf == curbuf); // TODO(bfredl): remove this condition
int changed = 0; int changed = 0;
int added = 0; int added = 0;
int height; int height;
@@ -2235,10 +2228,10 @@ static void refresh_screen(Terminal *term, buf_T *buf)
fetch_row(term, r, width); fetch_row(term, r, width);
if (linenr <= buf->b_ml.ml_line_count) { if (linenr <= buf->b_ml.ml_line_count) {
ml_replace(linenr, term->textbuf, true); ml_replace_buf(buf, linenr, term->textbuf, true, false);
changed++; changed++;
} else { } else {
ml_append(linenr - 1, term->textbuf, 0, false); ml_append_buf(buf, linenr - 1, term->textbuf, 0, false);
added++; added++;
} }
} }