]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0158: Visual highlighting might be incorrect v9.2.0158
authorShane Harper <shane@shaneharper.net>
Fri, 13 Mar 2026 21:39:46 +0000 (21:39 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 13 Mar 2026 21:39:46 +0000 (21:39 +0000)
Problem:  Vim could use the VisualNOS highlight group when not connected
          to an X server.
Solution: Always highlight visual selections with Visual when not
          connected to an X server (Shane Harper)

When Vim is running with X11 support it chooses between the Visual and
VisualNOS highlight groups for a visual selection based on whether it
believes it owns the X selection. According to :help hl-VisualNOS,
VisualNOS should only be used by the X11 GUI or when using the
xterm-clipboard feature, however, prior to this commit Vim could choose
VisualNOS when a clipboard provider was used, even when Vim was not
connected to an X server.

closes: #19659

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/drawline.c
src/testdir/test_visual.vim
src/version.c

index 8880cb9a83c723a106ea9353c025b6490133fe8c..b3f6560a23ef2cc3ecab4a9d2d084cc5811ce6ef 100644 (file)
@@ -1462,10 +1462,11 @@ win_line(
                area_highlighting = TRUE;
                vi_attr = HL_ATTR(HLF_V);
 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
-               if ((clip_star.available && !clip_star.owned
-                                                     && clip_isautosel_star())
-                       || (clip_plus.available && !clip_plus.owned
-                                                    && clip_isautosel_plus()))
+               if (xterm_dpy
+                       && ((clip_star.available && !clip_star.owned
+                                                   && clip_isautosel_star())
+                           || (clip_plus.available && !clip_plus.owned
+                                                   && clip_isautosel_plus())))
                    vi_attr = HL_ATTR(HLF_VNC);
 #endif
            }
index f4a010635e284f722d957ef507ffb54381c3527d..361868d86ca9be2e305078f0e866f98506d15689 100644 (file)
@@ -1618,6 +1618,40 @@ func Test_visual_hl_with_showbreak()
   call StopVimInTerminal(buf)
 endfunc
 
+func Test_visual_highlight_when_using_a_clipboard_provider()
+  " The test assumes different screen attributes will be used for Visual and for VisualNOS.
+  CheckFeature clipboard_provider
+  if exists('$DISPLAY')
+     throw 'Skipped: requires non-X11 setup ($DISPLAY must be empty)'
+  endif
+
+  func s:get_attr_for_first_char_in_buf()
+    let pos = screenpos(win_getid(), 1, 1)
+    call assert_true(pos.row > 0 && pos.col > 0)
+    redraw
+    return screenattr(pos.row, pos.col)
+  endfunc
+
+  new +0put='X'
+  call matchadd('Visual', '.')
+  const Visual_attr = s:get_attr_for_first_char_in_buf()
+  call clearmatches()
+
+  normal! V$
+
+  let v:clipproviders['custom'] = {}
+  set clipmethod=custom
+  " The following assert originally failed; VisualNOS, not Visual, was used.
+  call assert_equal(Visual_attr, s:get_attr_for_first_char_in_buf())
+
+  set clipmethod=
+  call assert_equal(Visual_attr, s:get_attr_for_first_char_in_buf())
+
+  unlet v:clipproviders['custom']
+  set clipmethod&
+  bwipe!
+endfunc
+
 func Test_Visual_r_CTRL_C()
   new
   " visual r_cmd
index dd050e2b31483fff1e18f540e27b718ce9baa0f8..3874a37784200d86853daeee527f4b1e97b367fb 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    158,
 /**/
     157,
 /**/