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 <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/autocmd.c b/src/autocmd.c
index 3d21a93..6a5f035 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -1585,9 +1585,10 @@
 #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 @@
     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;
 }
 
 /*