]> granicus.if.org Git - vim/commitdiff
patch 9.0.0511: unnecessary scrolling for message of only one line v9.0.0511
authorzeertzjq <zeertzjq@outlook.com>
Tue, 20 Sep 2022 11:45:15 +0000 (12:45 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 20 Sep 2022 11:45:15 +0000 (12:45 +0100)
Problem:    Unnecessary scrolling for message of only one line.
Solution:   Only set msg_scroll when needed. (closes #11178)

src/message.c
src/testdir/test_messages.vim
src/version.c

index 57197c1a8364002438391789bd8748d0ad3cc680..9c3554303173debe8c68066020314e6bbdd1b638 100644 (file)
@@ -535,11 +535,11 @@ msg_source(int attr)
        return;
     recursive = TRUE;
 
-    msg_scroll = TRUE;  // this will take more than one line
     ++no_wait_return;
     p = get_emsg_source();
     if (p != NULL)
     {
+       msg_scroll = TRUE;  // this will take more than one line
        msg_attr((char *)p, attr);
        vim_free(p);
     }
@@ -767,8 +767,8 @@ emsg_core(char_u *s)
 #endif
     /*
      * Display name and line number for the source of the error.
-     * Sets "msg_scroll".
      */
+    msg_scroll = TRUE;
     msg_source(attr);
 
     /*
index e35fb0c383f58f3abf9eeff62e55329f64e0a5fc..140f1c3512f758fc707541579ed553bbc0cbe53f 100644 (file)
@@ -166,6 +166,38 @@ func Test_echospace()
   set ruler& showcmd&
 endfunc
 
+func Test_warning_scroll()
+  CheckRunVimInTerminal
+  let lines =<< trim END
+      call test_override('ui_delay', 50)
+      set noruler
+      set readonly
+      undo
+  END
+  call writefile(lines, 'XTestWarningScroll', 'D')
+  let buf = RunVimInTerminal('', #{rows: 8})
+
+  " When the warning comes from a script, messages are scrolled so that the
+  " stacktrace is visible.
+  call term_sendkeys(buf, ":source XTestWarningScroll\n")
+  " only match the final colon in the line that shows the source
+  call WaitForAssert({-> assert_match(':$', term_getline(buf, 5))})
+  call WaitForAssert({-> assert_equal('line    4:W10: Warning: Changing a readonly file', term_getline(buf, 6))})
+  call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 7))})
+  call WaitForAssert({-> assert_equal('Press ENTER or type command to continue', term_getline(buf, 8))})
+  call term_sendkeys(buf, "\n")
+
+  " When the warning does not come from a script, messages are not scrolled.
+  call term_sendkeys(buf, ":enew\n")
+  call term_sendkeys(buf, ":set readonly\n")
+  call term_sendkeys(buf, 'u')
+  call WaitForAssert({-> assert_equal('W10: Warning: Changing a readonly file', term_getline(buf, 8))})
+  call WaitForAssert({-> assert_equal('Already at oldest change', term_getline(buf, 8))})
+
+  " clean up
+  call StopVimInTerminal(buf)
+endfunc
+
 " Test more-prompt (see :help more-prompt).
 func Test_message_more()
   CheckRunVimInTerminal
index d7d5bd3936105cfb5e08ea36928b4fb501049649..c6f76acb834ab3d40c6f2faa2f492dbe80a4d760 100644 (file)
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    511,
 /**/
     510,
 /**/