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);
}
/// 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.
@ -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);
}
/// 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.

View File

@ -2029,14 +2029,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);
@ -2168,7 +2163,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);
@ -2177,8 +2171,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--;
}
@ -2190,21 +2184,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);
@ -2214,7 +2208,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;
@ -2235,10 +2228,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++;
}
}