patch 9.1.1407: Can't use getpos('v') in OptionSet when using setbufvar()
Commit:
https://github.com/vim/vim/commit/5717ee33db0048a496e8bed0b0cb20133b3f76ca
Author: zeertzjq <[email protected]>
Date: Sun May 25 16:59:50 2025 +0200
patch 9.1.1407: Can't use getpos('v') in OptionSet when using setbufvar()
Problem: Can't use getpos('v') in OptionSet when using setbufvar().
Solution: Don't reset Visual selection when switching to the same
buffer (zeertzjq).
closes: #17373
Signed-off-by: zeertzjq <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/autocmd.c b/src/autocmd.c
index 3d21a937b..6a5f035d2 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -1585,9 +1585,10 @@ aucmd_prepbuf(
#ifdef FEAT_AUTOCHDIR
int save_acd;
#endif
+ int same_buffer = buf == curbuf;
// Find a window that is for the new buffer
- if (buf == curbuf) // be quick when buf is curbuf
+ if (same_buffer) // be quick when buf is curbuf
win = curwin;
else
FOR_ALL_WINDOWS(win)
@@ -1677,9 +1678,10 @@ aucmd_prepbuf(
aco->new_curwin_id = curwin->w_id;
set_bufref(&aco->new_curbuf, curbuf);
- // disable the Visual area, the position may be invalid in another buffer
aco->save_VIsual_active = VIsual_active;
- VIsual_active = FALSE;
+ if (!same_buffer)
+ // disable the Visual area, position may be invalid in another buffer
+ VIsual_active = FALSE;
}
/*
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 1988807f7..dfeb93f06 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -3761,6 +3761,27 @@ func Test_Visual_doautoall_redraw()
%bwipe!
endfunc
+func Test_get_Visual_selection_in_curbuf_autocmd()
+ call test_override('starting', 1)
+ new
+ autocmd OptionSet list let b:text = getregion(getpos('.'), getpos('v'))
+ call setline(1, 'foo bar baz')
+
+ normal! gg0fbvtb
+ setlocal list
+ call assert_equal(['bar '], b:text)
+ exe "normal! \<Esc>"
+
+ normal! v0
+ call setbufvar('%', '&list', v:false)
+ call assert_equal(['foo bar '], b:text)
+ exe "normal! \<Esc>"
+
+ autocmd! OptionSet list
+ bwipe!
+ call test_override('starting', 0)
+endfunc
+
" This was using freed memory.
func Test_BufNew_arglocal()
arglocal
diff --git a/src/version.c b/src/version.c
index b9af08a7d..637f178a0 100644
--- a/src/version.c
+++ b/src/version.c
@@ -709,6 +709,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1407,
/**/
1406,
/**/
--
--
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 visit
https://groups.google.com/d/msgid/vim_dev/E1uJD4A-00ErXK-1J%40256bit.org.