Patch 9.0.0099
Problem:    Scrollback can be wrong after redrawing the command line.
Solution:   Clear unfinished scrollback when redrawing. (closes #10807)
Files:      src/ex_getln.c, src/message.c, src/proto/message.pro,
            src/testdir/test_messages.vim


*** ../vim-9.0.0098/src/ex_getln.c      2022-07-26 20:42:21.822448308 +0100
--- src/ex_getln.c      2022-07-28 12:28:25.999926525 +0100
***************
*** 3892,3897 ****
--- 3892,3898 ----
        return;
      }
  
+     sb_text_restart_cmdline();
      msg_start();
      redrawcmdprompt();
  
***************
*** 4106,4112 ****
  
  #if defined(FEAT_EVAL) || defined(FEAT_CMDWIN) || defined(PROTO)
  /*
!  * Get pointer to the command line info to use. save_ccline() may clear
   * ccline and put the previous value in prev_ccline.
   */
      static cmdline_info_T *
--- 4107,4113 ----
  
  #if defined(FEAT_EVAL) || defined(FEAT_CMDWIN) || defined(PROTO)
  /*
!  * Get pointer to the command line info to use. save_cmdline() may clear
   * ccline and put the previous value in prev_ccline.
   */
      static cmdline_info_T *
*** ../vim-9.0.0098/src/message.c       2022-07-25 19:50:53.954361274 +0100
--- src/message.c       2022-07-28 12:28:25.999926525 +0100
***************
*** 2535,2540 ****
--- 2535,2541 ----
            || do_clear_sb_text == SB_CLEAR_CMDLINE_DONE)
      {
        clear_sb_text(do_clear_sb_text == SB_CLEAR_ALL);
+       msg_sb_eol();  // prevent messages from overlapping
        do_clear_sb_text = SB_CLEAR_NONE;
      }
  
***************
*** 2579,2601 ****
  }
  
  /*
!  * Starting to edit the command line, do not clear messages now.
   */
      void
  sb_text_start_cmdline(void)
  {
      do_clear_sb_text = SB_CLEAR_CMDLINE_BUSY;
!     msg_sb_eol();
  }
  
  /*
!  * Ending to edit the command line.  Clear old lines but the last one later.
   */
      void
  sb_text_end_cmdline(void)
  {
      do_clear_sb_text = SB_CLEAR_CMDLINE_DONE;
-     msg_sb_eol();
  }
  
  /*
--- 2580,2637 ----
  }
  
  /*
!  * Starting to edit the command line: do not clear messages now.
   */
      void
  sb_text_start_cmdline(void)
  {
+     if (do_clear_sb_text == SB_CLEAR_CMDLINE_BUSY)
+       // Invoking command line recursively: the previous-level command line
+       // doesn't need to be remembered as it will be redrawn when returning
+       // to that level.
+       sb_text_restart_cmdline();
+     else
+     {
+       msg_sb_eol();
+       do_clear_sb_text = SB_CLEAR_CMDLINE_BUSY;
+     }
+ }
+ 
+ /*
+  * Redrawing the command line: clear the last unfinished line.
+  */
+     void
+ sb_text_restart_cmdline(void)
+ {
+     msgchunk_T *tofree;
+ 
+     // Needed when returning from nested command line.
      do_clear_sb_text = SB_CLEAR_CMDLINE_BUSY;
! 
!     if (last_msgchunk == NULL || last_msgchunk->sb_eol)
!       // No unfinished line: don't clear anything.
!       return;
! 
!     tofree = msg_sb_start(last_msgchunk);
!     last_msgchunk = tofree->sb_prev;
!     if (last_msgchunk != NULL)
!       last_msgchunk->sb_next = NULL;
!     while (tofree != NULL)
!     {
!       msgchunk_T *tofree_next = tofree->sb_next;
! 
!       vim_free(tofree);
!       tofree = tofree_next;
!     }
  }
  
  /*
!  * Ending to edit the command line: clear old lines but the last one later.
   */
      void
  sb_text_end_cmdline(void)
  {
      do_clear_sb_text = SB_CLEAR_CMDLINE_DONE;
  }
  
  /*
*** ../vim-9.0.0098/src/proto/message.pro       2022-06-27 23:15:15.000000000 
+0100
--- src/proto/message.pro       2022-07-28 12:28:25.999926525 +0100
***************
*** 48,53 ****
--- 48,54 ----
  int message_filtered(char_u *msg);
  void may_clear_sb_text(void);
  void sb_text_start_cmdline(void);
+ void sb_text_restart_cmdline(void);
  void sb_text_end_cmdline(void);
  void clear_sb_text(int all);
  void show_sb_text(void);
*** ../vim-9.0.0098/src/testdir/test_messages.vim       2022-07-25 
19:50:53.954361274 +0100
--- src/testdir/test_messages.vim       2022-07-28 12:28:25.999926525 +0100
***************
*** 176,182 ****
    let buf = RunVimInTerminal('', {'rows': 6})
    call term_sendkeys(buf, ":call setline(1, range(1, 100))\n")
  
!   call term_sendkeys(buf, ":%p#\n")
    call WaitForAssert({-> assert_equal('  5 5', term_getline(buf, 5))})
    call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
  
--- 176,184 ----
    let buf = RunVimInTerminal('', {'rows': 6})
    call term_sendkeys(buf, ":call setline(1, range(1, 100))\n")
  
!   call term_sendkeys(buf, ":%pfoo\<C-H>\<C-H>\<C-H>#")
!   call WaitForAssert({-> assert_equal(':%p#', term_getline(buf, 6))})
!   call term_sendkeys(buf, "\n")
    call WaitForAssert({-> assert_equal('  5 5', term_getline(buf, 5))})
    call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
  
***************
*** 252,257 ****
--- 254,266 ----
    call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 5))})
    call WaitForAssert({-> assert_equal('Press ENTER or type command to 
continue', term_getline(buf, 6))})
  
+   " A command line that doesn't print text is appended to scrollback,
+   " even if it invokes a nested command line.
+   call term_sendkeys(buf, ":\<C-R>=':'\<CR>:\<CR>g<")
+   call WaitForAssert({-> assert_equal('100 100', term_getline(buf, 4))})
+   call WaitForAssert({-> assert_equal(':::', term_getline(buf, 5))})
+   call WaitForAssert({-> assert_equal('Press ENTER or type command to 
continue', term_getline(buf, 6))})
+ 
    call term_sendkeys(buf, ":%p#\n")
    call WaitForAssert({-> assert_equal('  5 5', term_getline(buf, 5))})
    call WaitForAssert({-> assert_equal('-- More --', term_getline(buf, 6))})
*** ../vim-9.0.0098/src/version.c       2022-07-28 12:09:00.605870804 +0100
--- src/version.c       2022-07-28 12:29:52.175778831 +0100
***************
*** 737,738 ****
--- 737,740 ----
  {   /* Add new patch number below this line */
+ /**/
+     99,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
166. You have been on your computer soo long that you didn't realize
     you had grandchildren.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220728113442.360181C0A39%40moolenaar.net.

Raspunde prin e-mail lui