aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/terminal.c
diff options
context:
space:
mode:
authorJavier Lopez <graulopezjavier@gmail.com>2022-06-08 19:46:57 -0500
committerGitHub <noreply@github.com>2022-06-08 17:46:57 -0700
commit916d848049979e7b3974fbf4b6fdf2cf58ae98c3 (patch)
treed2a7df62c939f30a6f206f279cc01a74e5e37d2a /src/nvim/terminal.c
parent10291bb8541e461cd3b089bb05c1e3b3946955c5 (diff)
downloadrneovim-916d848049979e7b3974fbf4b6fdf2cf58ae98c3.tar.gz
rneovim-916d848049979e7b3974fbf4b6fdf2cf58ae98c3.tar.bz2
rneovim-916d848049979e7b3974fbf4b6fdf2cf58ae98c3.zip
fix(terminal): scrollback delete lines immediately #18832
* on_scrollback_option_changed renamed to adjust_scrollback. The function name did not correspond to what it was doing. It is called unconditionally in every refresh of the terminal unrelated if the scrollback option was changed. * new on_scrollback_option_changed function, which calls refresh_terminal, which then calls adjust_scrollback * terminal_check_size is not the appropriate function to call when the option is changed since it only conditionally adjusts the scrollback. Use the new on_scrollback_option_changed fixes #15477 fixes #11811
Diffstat (limited to 'src/nvim/terminal.c')
-rw-r--r--src/nvim/terminal.c16
1 files changed, 13 insertions, 3 deletions
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