From: Shane Harper Date: Fri, 13 Mar 2026 21:39:46 +0000 (+0000) Subject: patch 9.2.0158: Visual highlighting might be incorrect X-Git-Tag: v9.2.0158^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b009a3bbf31a2dc29e1d9f1759ded0ee290388d;p=thirdparty%2Fvim.git patch 9.2.0158: Visual highlighting might be incorrect 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 --- diff --git a/src/drawline.c b/src/drawline.c index 8880cb9a83..b3f6560a23 100644 --- a/src/drawline.c +++ b/src/drawline.c @@ -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 } diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim index f4a010635e..361868d86c 100644 --- a/src/testdir/test_visual.vim +++ b/src/testdir/test_visual.vim @@ -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 diff --git a/src/version.c b/src/version.c index dd050e2b31..3874a37784 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 158, /**/ 157, /**/