aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/option.c6
-rw-r--r--src/nvim/terminal.c16
2 files changed, 16 insertions, 6 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 5565e6f167..a15c6f4854 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -4544,9 +4544,9 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf,
check_colorcolumn(wp);
}
} else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) {
- if (curbuf->terminal) {
- // Force the scrollback to take effect.
- terminal_check_size(curbuf->terminal);
+ if (curbuf->terminal && value < old_value) {
+ // Force the scrollback to take immediate effect only when decreasing it.
+ on_scrollback_option_changed(curbuf->terminal);
}
} else if (pp == &curwin->w_p_nuw) {
curwin->w_nrwidth_line_count = 0;
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index e4262c2ca9..c5b3bbcb01 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -233,6 +233,8 @@ Terminal *terminal_open(buf_T *buf, TerminalOptions opts)
RESET_BINDING(curwin);
// Reset cursor in current window.
curwin->w_cursor = (pos_T){ .lnum = 1, .col = 0, .coladd = 0 };
+ // Initialize to check if the scrollback buffer has been allocated inside a TermOpen autocmd
+ rv->sb_buffer = NULL;
// Apply TermOpen autocmds _before_ configuring the scrollback buffer.
apply_autocmds(EVENT_TERMOPEN, NULL, NULL, false, buf);
// Local 'scrollback' _after_ autocmds.
@@ -1481,8 +1483,16 @@ static void refresh_size(Terminal *term, buf_T *buf)
term->opts.resize_cb((uint16_t)width, (uint16_t)height, term->opts.data);
}
-/// Adjusts scrollback storage after 'scrollback' option changed.
-static void on_scrollback_option_changed(Terminal *term, buf_T *buf)
+void on_scrollback_option_changed(Terminal *term)
+{
+ // Scrollback buffer may not exist yet, e.g. if 'scrollback' is set in a TermOpen autocmd.
+ if (term->sb_buffer != NULL) {
+ refresh_terminal(term);
+ }
+}
+
+/// Adjusts scrollback storage and the terminal buffer scrollback lines
+static void adjust_scrollback(Terminal *term, buf_T *buf)
{
if (buf->b_p_scbk < 1) { // Local 'scrollback' was set to -1.
buf->b_p_scbk = SB_MAX;
@@ -1554,7 +1564,7 @@ static void refresh_scrollback(Terminal *term, buf_T *buf)
deleted_lines(buf->b_ml.ml_line_count, 1);
}
- on_scrollback_option_changed(term, buf);
+ adjust_scrollback(term, buf);
}
// Refresh the screen (visible part of the buffer when the terminal is