]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0808: Terminal scrollback doesn't shrink when decreasing 'termwinscroll' v9.1.0808
authorMilly <milly.ca@gmail.com>
Tue, 22 Oct 2024 21:17:45 +0000 (23:17 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 22 Oct 2024 21:17:45 +0000 (23:17 +0200)
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>
src/option.c
src/optiondefs.h
src/proto/option.pro
src/terminal.c
src/testdir/gen_opt_test.vim
src/testdir/test_options.vim
src/testdir/test_terminal.vim
src/version.c

index 179c61ea3128593774d8caf905a5cbb6a57ea167..84c469ea6061f0172d581f47fac88400f4e0cce0 100644 (file)
@@ -4259,6 +4259,26 @@ did_set_termguicolors(optset_T *args UNUSED)
 }
 #endif
 
+#if defined(FEAT_TERMINAL) || defined(PROTO)
+/*
+ * Process the updated 'termwinscroll' option value.
+ */
+    char *
+did_set_termwinscroll(optset_T *args)
+{
+    long       *pp = (long *)args->os_varp;
+    char       *errmsg = NULL;
+
+    if (*pp < 1)
+    {
+       errmsg = e_argument_must_be_positive;
+       *pp = 1;
+    }
+
+    return errmsg;
+}
+#endif
+
 /*
  * Process the updated 'terse' option value.
  */
index 42e62e7d2b583d7f2a27776ed77252bb00abb605..ccc527e08d3e5bf838e1c9b634dd5504bbe59c67 100644 (file)
@@ -2563,7 +2563,7 @@ static struct vimoption options[] =
                            SCTX_INIT},
     {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
 #ifdef FEAT_TERMINAL
-                           (char_u *)&p_twsl, PV_TWSL, NULL, NULL,
+                           (char_u *)&p_twsl, PV_TWSL, did_set_termwinscroll, NULL,
                            {(char_u *)10000L, (char_u *)10000L}
 #else
                            (char_u *)NULL, PV_NONE, NULL, NULL,
index 1659131a3213418c61a9f5695873649c7269de45..db92bf253ea73b535d9d1d47764886c4dbf677d3 100644 (file)
@@ -71,6 +71,7 @@ char *did_set_spell(optset_T *args);
 char *did_set_swapfile(optset_T *args);
 char *did_set_tabclose(optset_T *args);
 char *did_set_termguicolors(optset_T *args);
+char *did_set_termwinscroll(optset_T *args);
 char *did_set_terse(optset_T *args);
 char *did_set_textauto(optset_T *args);
 char *did_set_textmode(optset_T *args);
index f61a54f7f0d91d936bc37c09a03f31764d406b15..6edc21a11d9c56fe90b0c4ae2ca5b3cc6982c185 100644 (file)
@@ -3436,7 +3436,8 @@ limit_scrollback(term_T *term, garray_T *gap, int update_buffer)
     if (gap->ga_len < term->tl_buffer->b_p_twsl)
        return;
 
-    int        todo = term->tl_buffer->b_p_twsl / 10;
+    int        todo = MAX(term->tl_buffer->b_p_twsl / 10,
+                                    gap->ga_len - term->tl_buffer->b_p_twsl);
     int        i;
 
     curbuf = term->tl_buffer;
index 1c231f9c529568f69b311c5553ae6fb4fce9c428..34fffeff6dffb899245bbae3341aea5e16f051f9 100644 (file)
@@ -103,6 +103,7 @@ let test_values = {
       \ 'sidescroll': [[0, 1, 8, 999], [-1]],
       \ 'sidescrolloff': [[0, 1, 8, 999], [-1]],
       \ 'tabstop': [[1, 4, 8, 12, 9999], [-1, 0, 10000]],
+      \ 'termwinscroll': [[1, 100, 99999], [-1, 0]],
       \ 'textwidth': [[0, 1, 8, 99], [-1]],
       \ 'timeoutlen': [[0, 8, 99999], [-1]],
       \ 'titlelen': [[0, 1, 8, 9999], [-1]],
index cbc84a4719eaa51645a8913c5efbfa914cb932ba..73e6d850c672d806111c0425520c6c3aeffa4ddf 100644 (file)
@@ -752,6 +752,9 @@ func Test_set_option_errors()
   call assert_fails('set tabstop=10000', 'E474:')
   call assert_fails('let &tabstop = 10000', 'E474:')
   call assert_fails('set tabstop=5500000000', 'E474:')
+  if has('terminal')
+    call assert_fails('set termwinscroll=-1', 'E487:')
+  endif
   call assert_fails('set textwidth=-1', 'E487:')
   call assert_fails('set timeoutlen=-1', 'E487:')
   call assert_fails('set updatecount=-1', 'E487:')
index fa644d33586b03730bf948e831e64b56aa67eb1f..5343efb954dfe11c05a940a73c2bfcd7139b2f40 100644 (file)
@@ -501,6 +501,21 @@ func Test_terminal_scrollback()
   let lines = line('$')
   call assert_inrange(91, 100, lines)
 
+  " When 'termwinscroll' becomes small, the scrollback should become small.
+  set termwinscroll=20
+  call term_sendkeys(buf, "echo set20\<CR>")
+  call WaitForAssert({-> assert_true([term_getline(buf, rows - 1), term_getline(buf, rows - 2)]->index('set20') >= 0)})
+  let lines = line('$')
+  call assert_inrange(19, 20, lines)
+
+  " When 'termwinscroll' under 10 which means 10% of it will be 0,
+  " the scrollback should become small.
+  set termwinscroll=1
+  call term_sendkeys(buf, "echo set1\<CR>")
+  call WaitForAssert({-> assert_true([term_getline(buf, rows - 1), term_getline(buf, rows - 2)]->index('set1') >= 0)})
+  let lines = line('$')
+  call assert_inrange(1, 2, lines)
+
   call StopShellInTerminal(buf)
   exe buf . 'bwipe'
   set termwinscroll&
index 2a85be94319aa118cc9ebfb8e678f5c9376916a8..5b4a853076e3b87b5aa327994f5d0659a6ebf398 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    808,
 /**/
     807,
 /**/