Skip to content

Commit 6d5f4a0

Browse files
Millychrisbra
authored andcommitted
patch 9.1.0808: Terminal scrollback doesn't shrink when decreasing 'termwinscroll'
Problem: Terminal scrollback doesn't shrink when reducing 'termwinscroll' Solution: Check if option value was decreased (Milly). closes: #15904 Signed-off-by: Milly <milly.ca@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 3e5bbb8 commit 6d5f4a0

8 files changed

Lines changed: 45 additions & 2 deletions

File tree

src/option.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4259,6 +4259,26 @@ did_set_termguicolors(optset_T *args UNUSED)
42594259
}
42604260
#endif
42614261

4262+
#if defined(FEAT_TERMINAL) || defined(PROTO)
4263+
/*
4264+
* Process the updated 'termwinscroll' option value.
4265+
*/
4266+
char *
4267+
did_set_termwinscroll(optset_T *args)
4268+
{
4269+
long *pp = (long *)args->os_varp;
4270+
char *errmsg = NULL;
4271+
4272+
if (*pp < 1)
4273+
{
4274+
errmsg = e_argument_must_be_positive;
4275+
*pp = 1;
4276+
}
4277+
4278+
return errmsg;
4279+
}
4280+
#endif
4281+
42624282
/*
42634283
* Process the updated 'terse' option value.
42644284
*/

src/optiondefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2563,7 +2563,7 @@ static struct vimoption options[] =
25632563
SCTX_INIT},
25642564
{"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
25652565
#ifdef FEAT_TERMINAL
2566-
(char_u *)&p_twsl, PV_TWSL, NULL, NULL,
2566+
(char_u *)&p_twsl, PV_TWSL, did_set_termwinscroll, NULL,
25672567
{(char_u *)10000L, (char_u *)10000L}
25682568
#else
25692569
(char_u *)NULL, PV_NONE, NULL, NULL,

src/proto/option.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ char *did_set_spell(optset_T *args);
7171
char *did_set_swapfile(optset_T *args);
7272
char *did_set_tabclose(optset_T *args);
7373
char *did_set_termguicolors(optset_T *args);
74+
char *did_set_termwinscroll(optset_T *args);
7475
char *did_set_terse(optset_T *args);
7576
char *did_set_textauto(optset_T *args);
7677
char *did_set_textmode(optset_T *args);

src/terminal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3436,7 +3436,8 @@ limit_scrollback(term_T *term, garray_T *gap, int update_buffer)
34363436
if (gap->ga_len < term->tl_buffer->b_p_twsl)
34373437
return;
34383438

3439-
int todo = term->tl_buffer->b_p_twsl / 10;
3439+
int todo = MAX(term->tl_buffer->b_p_twsl / 10,
3440+
gap->ga_len - term->tl_buffer->b_p_twsl);
34403441
int i;
34413442

34423443
curbuf = term->tl_buffer;

src/testdir/gen_opt_test.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ let test_values = {
103103
\ 'sidescroll': [[0, 1, 8, 999], [-1]],
104104
\ 'sidescrolloff': [[0, 1, 8, 999], [-1]],
105105
\ 'tabstop': [[1, 4, 8, 12, 9999], [-1, 0, 10000]],
106+
\ 'termwinscroll': [[1, 100, 99999], [-1, 0]],
106107
\ 'textwidth': [[0, 1, 8, 99], [-1]],
107108
\ 'timeoutlen': [[0, 8, 99999], [-1]],
108109
\ 'titlelen': [[0, 1, 8, 9999], [-1]],

src/testdir/test_options.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ func Test_set_option_errors()
752752
call assert_fails('set tabstop=10000', 'E474:')
753753
call assert_fails('let &tabstop = 10000', 'E474:')
754754
call assert_fails('set tabstop=5500000000', 'E474:')
755+
if has('terminal')
756+
call assert_fails('set termwinscroll=-1', 'E487:')
757+
endif
755758
call assert_fails('set textwidth=-1', 'E487:')
756759
call assert_fails('set timeoutlen=-1', 'E487:')
757760
call assert_fails('set updatecount=-1', 'E487:')

src/testdir/test_terminal.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,21 @@ func Test_terminal_scrollback()
501501
let lines = line('$')
502502
call assert_inrange(91, 100, lines)
503503

504+
" When 'termwinscroll' becomes small, the scrollback should become small.
505+
set termwinscroll=20
506+
call term_sendkeys(buf, "echo set20\<CR>")
507+
call WaitForAssert({-> assert_true([term_getline(buf, rows - 1), term_getline(buf, rows - 2)]->index('set20') >= 0)})
508+
let lines = line('$')
509+
call assert_inrange(19, 20, lines)
510+
511+
" When 'termwinscroll' under 10 which means 10% of it will be 0,
512+
" the scrollback should become small.
513+
set termwinscroll=1
514+
call term_sendkeys(buf, "echo set1\<CR>")
515+
call WaitForAssert({-> assert_true([term_getline(buf, rows - 1), term_getline(buf, rows - 2)]->index('set1') >= 0)})
516+
let lines = line('$')
517+
call assert_inrange(1, 2, lines)
518+
504519
call StopShellInTerminal(buf)
505520
exe buf . 'bwipe'
506521
set termwinscroll&

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
808,
707709
/**/
708710
807,
709711
/**/

0 commit comments

Comments
 (0)