Patch 9.0.1277
Problem:    Cursor may move with autocmd in Visual mode.
Solution:   Restore "VIsual_active" before calling check_cursor().
            (closes #11939)
Files:      src/autocmd.c, src/testdir/test_functions.vim


*** ../vim-9.0.1276/src/autocmd.c       2023-01-09 19:04:19.296528376 +0000
--- src/autocmd.c       2023-02-04 10:57:32.179779507 +0000
***************
*** 1695,1700 ****
--- 1695,1701 ----
        globaldir = aco->globaldir;
  
        // the buffer contents may have changed
+       VIsual_active = aco->save_VIsual_active;
        check_cursor();
        if (curwin->w_topline > curbuf->b_ml.ml_line_count)
        {
***************
*** 1741,1754 ****
            curwin = save_curwin;
            curbuf = curwin->w_buffer;
            prevwin = win_find_by_id(aco->save_prevwin_id);
            // In case the autocommand moves the cursor to a position that
            // does not exist in curbuf.
            check_cursor();
        }
      }
  
-     check_cursor();       // just in case lines got deleted
      VIsual_active = aco->save_VIsual_active;
      if (VIsual_active)
        check_pos(curbuf, &VIsual);
  }
--- 1742,1757 ----
            curwin = save_curwin;
            curbuf = curwin->w_buffer;
            prevwin = win_find_by_id(aco->save_prevwin_id);
+ 
            // In case the autocommand moves the cursor to a position that
            // does not exist in curbuf.
+           VIsual_active = aco->save_VIsual_active;
            check_cursor();
        }
      }
  
      VIsual_active = aco->save_VIsual_active;
+     check_cursor();       // just in case lines got deleted
      if (VIsual_active)
        check_pos(curbuf, &VIsual);
  }
*** ../vim-9.0.1276/src/testdir/test_functions.vim      2023-01-02 
11:59:22.352412451 +0000
--- src/testdir/test_functions.vim      2023-02-04 10:53:32.716093809 +0000
***************
*** 1648,1654 ****
  
  func Test_setbufvar_options()
    " This tests that aucmd_prepbuf() and aucmd_restbuf() properly restore the
!   " window layout.
    call assert_equal(1, winnr('$'))
    split dummy_preview
    resize 2
--- 1648,1654 ----
  
  func Test_setbufvar_options()
    " This tests that aucmd_prepbuf() and aucmd_restbuf() properly restore the
!   " window layout and cursor position.
    call assert_equal(1, winnr('$'))
    split dummy_preview
    resize 2
***************
*** 1662,1672 ****
--- 1662,1681 ----
    execute 'belowright vertical split #' . dummy_buf
    call assert_equal(wh, winheight(0))
    let dum1_id = win_getid()
+   call setline(1, 'foo')
+   normal! V$
+   call assert_equal(4, col('.'))
+   call setbufvar('dummy_preview', '&buftype', 'nofile')
+   call assert_equal(4, col('.'))
  
    wincmd h
    let wh = winheight(0)
+   call setline(1, 'foo')
+   normal! V$
+   call assert_equal(4, col('.'))
    let dummy_buf = bufnr('dummy_buf2', v:true)
    eval 'nofile'->setbufvar(dummy_buf, '&buftype')
+   call assert_equal(4, col('.'))
    execute 'belowright vertical split #' . dummy_buf
    call assert_equal(wh, winheight(0))
  
*** ../vim-9.0.1276/src/version.c       2023-02-03 12:28:00.303287569 +0000
--- src/version.c       2023-02-04 10:55:10.319967376 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1277,
  /**/

-- 
>From "know your smileys":
 :-X    My lips are sealed

 /// 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/20230204105910.50C931C0ABE%40moolenaar.net.

Raspunde prin e-mail lui