Patch 8.2.4567
Problem:    Bracketed paste doesn't work well in Visual linewise mode.
Solution:   Handle linewise Visual mode differently. (closes #9947)
Files:      src/normal.c, src/testdir/test_paste.vim


*** ../vim-8.2.4566/src/normal.c        2022-02-16 19:24:03.626162408 +0000
--- src/normal.c        2022-03-14 20:38:23.128238194 +0000
***************
*** 6880,6885 ****
--- 6880,6886 ----
      {
        pos_T old_pos = curwin->w_cursor;
        pos_T old_visual = VIsual;
+       int old_visual_mode = VIsual_mode;
  
        // In Visual mode the selected text is deleted.
        if (VIsual_mode == 'V' || curwin->w_cursor.lnum != VIsual.lnum)
***************
*** 6895,6905 ****
        do_pending_operator(cap, 0, FALSE);
        cap->cmdchar = K_PS;
  
!       // When the last char in the line was deleted then append. Detect this
!       // by checking if the cursor moved to before the Visual area.
!       if (*ml_get_cursor() != NUL && LT_POS(curwin->w_cursor, old_pos)
!                                      && LT_POS(curwin->w_cursor, old_visual))
!           inc_cursor();
  
        // Insert to replace the deleted text with the pasted text.
        invoke_edit(cap, FALSE, cap->cmdchar, FALSE);
--- 6896,6927 ----
        do_pending_operator(cap, 0, FALSE);
        cap->cmdchar = K_PS;
  
!       if (*ml_get_cursor() != NUL)
!       {
!           if (old_visual_mode == 'V')
!           {
!               // In linewise Visual mode insert before the beginning of the
!               // next line.
!               // When the last line in the buffer was deleted then create a
!               // new line, otherwise there is not need to move cursor.
!               // Detect this by checking if cursor moved above Visual area.
!               if (curwin->w_cursor.lnum < old_pos.lnum
!                               && curwin->w_cursor.lnum < old_visual.lnum)
!               {
!                   if (u_save_cursor() == OK)
!                   {
!                       ml_append(curwin->w_cursor.lnum, (char_u *)"", 0,
!                                                                       FALSE);
!                       appended_lines(curwin->w_cursor.lnum++, 1L);
!                   }
!               }
!           }
!           // When the last char in the line was deleted then append.
!           // Detect this by checking if cursor moved before Visual area.
!           else if (curwin->w_cursor.col < old_pos.col
!                               && curwin->w_cursor.col < old_visual.col)
!               inc_cursor();
!       }
  
        // Insert to replace the deleted text with the pasted text.
        invoke_edit(cap, FALSE, cap->cmdchar, FALSE);
*** ../vim-8.2.4566/src/testdir/test_paste.vim  2022-01-25 20:45:13.210333180 
+0000
--- src/testdir/test_paste.vim  2022-03-14 20:43:34.518690390 +0000
***************
*** 109,131 ****
--- 109,177 ----
    call feedkeys("0fsve\<Esc>[200~more\<Esc>[201~", 'xt')
    call assert_equal('here are more words', getline(1))
    call assert_equal('some', getreg('-'))
+   normal! u
+   call assert_equal('here are some words', getline(1))
+   exe "normal! \<C-R>"
+   call assert_equal('here are more words', getline(1))
  
    " include last char in the line
    call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt')
    call assert_equal('here are more noises', getline(1))
    call assert_equal('words', getreg('-'))
+   normal! u
+   call assert_equal('here are more words', getline(1))
+   exe "normal! \<C-R>"
+   call assert_equal('here are more noises', getline(1))
  
    " exclude last char in the line
    call setline(1, 'some words!')
    call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt')
    call assert_equal('some noises!', getline(1))
    call assert_equal('words', getreg('-'))
+   normal! u
+   call assert_equal('some words!', getline(1))
+   exe "normal! \<C-R>"
+   call assert_equal('some noises!', getline(1))
  
    " multi-line selection
    call setline(1, ['some words', 'and more'])
    call feedkeys("0fwvj0fd\<Esc>[200~letters\<Esc>[201~", 'xt')
    call assert_equal('some letters more', getline(1))
    call assert_equal("words\nand", getreg('1'))
+   normal! u
+   call assert_equal(['some words', 'and more'], getline(1, 2))
+   exe "normal! \<C-R>"
+   call assert_equal('some letters more', getline(1))
+ 
+   " linewise non-last line, cursor at start of line
+   call setline(1, ['some words', 'and more'])
+   call feedkeys("0V\<Esc>[200~letters\<Esc>[201~", 'xt')
+   call assert_equal('lettersand more', getline(1))
+   call assert_equal("some words\n", getreg('1'))
+   normal! u
+   call assert_equal(['some words', 'and more'], getline(1, 2))
+   exe "normal! \<C-R>"
+   call assert_equal('lettersand more', getline(1))
+ 
+   " linewise non-last line, cursor in the middle of line
+   call setline(1, ['some words', 'and more'])
+   call feedkeys("0fwV\<Esc>[200~letters\<Esc>[201~", 'xt')
+   call assert_equal('lettersand more', getline(1))
+   call assert_equal("some words\n", getreg('1'))
+   normal! u
+   call assert_equal(['some words', 'and more'], getline(1, 2))
+   exe "normal! \<C-R>"
+   call assert_equal('lettersand more', getline(1))
+ 
+   " linewise last line
+   call setline(1, ['some words', 'and more'])
+   call feedkeys("j0V\<Esc>[200~letters\<Esc>[201~", 'xt')
+   call assert_equal(['some words', 'letters'], getline(1, 2))
+   call assert_equal("and more\n", getreg('1'))
+   normal! u
+   call assert_equal(['some words', 'and more'], getline(1, 2))
+   exe "normal! \<C-R>"
+   call assert_equal(['some words', 'letters'], getline(1, 2))
  
    bwipe!
  endfunc
*** ../vim-8.2.4566/src/version.c       2022-03-14 20:24:45.751034907 +0000
--- src/version.c       2022-03-14 20:40:06.575692507 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4567,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
260. Co-workers have to E-mail you about the fire alarm to get
     you out of the building.

 /// 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/20220314204715.36C6C1C1285%40moolenaar.net.

Raspunde prin e-mail lui