Skip to content

Commit 99e754a

Browse files
authored
fix(terminal): remove condition that buf is curbuf (#33721)
1 parent 08c484f commit 99e754a

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

src/nvim/change.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,20 @@ void inserted_bytes(linenr_T lnum, colnr_T start_col, int old_col, int new_col)
461461
changed_bytes(lnum, start_col);
462462
}
463463

464+
/// Appended "count" lines below line "lnum" in the given buffer.
465+
/// Must be called AFTER the change and after mark_adjust().
466+
/// Takes care of marking the buffer to be redrawn and sets the changed flag.
467+
void appended_lines_buf(buf_T *buf, linenr_T lnum, linenr_T count)
468+
{
469+
changed_lines(buf, lnum + 1, 0, lnum + 1, count, true);
470+
}
471+
464472
/// Appended "count" lines below line "lnum" in the current buffer.
465473
/// Must be called AFTER the change and after mark_adjust().
466474
/// Takes care of marking the buffer to be redrawn and sets the changed flag.
467475
void appended_lines(linenr_T lnum, linenr_T count)
468476
{
469-
changed_lines(curbuf, lnum + 1, 0, lnum + 1, count, true);
477+
appended_lines_buf(curbuf, lnum, count);
470478
}
471479

472480
/// Like appended_lines(), but adjust marks first.
@@ -476,12 +484,20 @@ void appended_lines_mark(linenr_T lnum, int count)
476484
changed_lines(curbuf, lnum + 1, 0, lnum + 1, (linenr_T)count, true);
477485
}
478486

487+
/// Deleted "count" lines at line "lnum" in the given buffer.
488+
/// Must be called AFTER the change and after mark_adjust().
489+
/// Takes care of marking the buffer to be redrawn and sets the changed flag.
490+
void deleted_lines_buf(buf_T *buf, linenr_T lnum, linenr_T count)
491+
{
492+
changed_lines(buf, lnum, 0, lnum + count, -count, true);
493+
}
494+
479495
/// Deleted "count" lines at line "lnum" in the current buffer.
480496
/// Must be called AFTER the change and after mark_adjust().
481497
/// Takes care of marking the buffer to be redrawn and sets the changed flag.
482498
void deleted_lines(linenr_T lnum, linenr_T count)
483499
{
484-
changed_lines(curbuf, lnum, 0, lnum + count, -count, true);
500+
deleted_lines_buf(curbuf, lnum, count);
485501
}
486502

487503
/// Like deleted_lines(), but adjust marks first.

src/nvim/terminal.c

+10-17
Original file line numberDiff line numberDiff line change
@@ -2029,14 +2029,9 @@ static void refresh_terminal(Terminal *term)
20292029
}
20302030
linenr_T ml_before = buf->b_ml.ml_line_count;
20312031

2032-
// Some refresh_ functions assume the terminal buffer is current. Don't call refresh_cursor here,
2033-
// as we don't want a terminal that was possibly made temporarily current influencing the cursor.
2034-
aco_save_T aco;
2035-
aucmd_prepbuf(&aco, buf);
20362032
refresh_size(term, buf);
20372033
refresh_scrollback(term, buf);
20382034
refresh_screen(term, buf);
2039-
aucmd_restbuf(&aco);
20402035

20412036
int ml_added = buf->b_ml.ml_line_count - ml_before;
20422037
adjust_topline(term, buf, ml_added);
@@ -2168,7 +2163,6 @@ static void adjust_scrollback(Terminal *term, buf_T *buf)
21682163
// Refresh the scrollback of an invalidated terminal.
21692164
static void refresh_scrollback(Terminal *term, buf_T *buf)
21702165
{
2171-
assert(buf == curbuf); // TODO(seandewar): remove this condition
21722166
int width, height;
21732167
vterm_get_size(term->vt, &height, &width);
21742168

@@ -2177,8 +2171,8 @@ static void refresh_scrollback(Terminal *term, buf_T *buf)
21772171
int row_offset = term->sb_pending;
21782172
while (term->sb_pending > 0 && buf->b_ml.ml_line_count < height) {
21792173
fetch_row(term, term->sb_pending - row_offset - 1, width);
2180-
ml_append(0, term->textbuf, 0, false);
2181-
appended_lines(0, 1);
2174+
ml_append_buf(buf, 0, term->textbuf, 0, false);
2175+
appended_lines_buf(buf, 0, 1);
21822176
term->sb_pending--;
21832177
}
21842178

@@ -2190,21 +2184,21 @@ static void refresh_scrollback(Terminal *term, buf_T *buf)
21902184
// section of the buffer
21912185
if (((int)buf->b_ml.ml_line_count - height) >= (int)term->sb_size) {
21922186
// scrollback full, delete lines at the top
2193-
ml_delete(1, false);
2194-
deleted_lines(1, 1);
2187+
ml_delete_buf(buf, 1, false);
2188+
deleted_lines_buf(buf, 1, 1);
21952189
}
21962190
fetch_row(term, -term->sb_pending - row_offset, width);
21972191
int buf_index = (int)buf->b_ml.ml_line_count - height;
2198-
ml_append(buf_index, term->textbuf, 0, false);
2199-
appended_lines(buf_index, 1);
2192+
ml_append_buf(buf, buf_index, term->textbuf, 0, false);
2193+
appended_lines_buf(buf, buf_index, 1);
22002194
term->sb_pending--;
22012195
}
22022196

22032197
// Remove extra lines at the bottom
22042198
int max_line_count = (int)term->sb_current + height;
22052199
while (buf->b_ml.ml_line_count > max_line_count) {
2206-
ml_delete(buf->b_ml.ml_line_count, false);
2207-
deleted_lines(buf->b_ml.ml_line_count, 1);
2200+
ml_delete_buf(buf, buf->b_ml.ml_line_count, false);
2201+
deleted_lines_buf(buf, buf->b_ml.ml_line_count, 1);
22082202
}
22092203

22102204
adjust_scrollback(term, buf);
@@ -2214,7 +2208,6 @@ static void refresh_scrollback(Terminal *term, buf_T *buf)
22142208
// focused) of a invalidated terminal
22152209
static void refresh_screen(Terminal *term, buf_T *buf)
22162210
{
2217-
assert(buf == curbuf); // TODO(bfredl): remove this condition
22182211
int changed = 0;
22192212
int added = 0;
22202213
int height;
@@ -2235,10 +2228,10 @@ static void refresh_screen(Terminal *term, buf_T *buf)
22352228
fetch_row(term, r, width);
22362229

22372230
if (linenr <= buf->b_ml.ml_line_count) {
2238-
ml_replace(linenr, term->textbuf, true);
2231+
ml_replace_buf(buf, linenr, term->textbuf, true, false);
22392232
changed++;
22402233
} else {
2241-
ml_append(linenr - 1, term->textbuf, 0, false);
2234+
ml_append_buf(buf, linenr - 1, term->textbuf, 0, false);
22422235
added++;
22432236
}
22442237
}

0 commit comments

Comments
 (0)