vim-patch:9.2.1038: CursorLineFold/Sign highlighting depends on 'cursorlineopt' (#41785)

Problem:  CursorLineFold and CursorLineSign are only applied when
          'cursorlineopt' contains "number" or is "both"
          (Evgeni Chasnovski).
Solution: Apply those groups whenever 'cursorline' is set, independent
          of 'cursorlineopt' (Vrushali Zampalkar).

fixes:  vim/vim#20480
closes: vim/vim#21112

1f8d3c44c5

Co-authored-by: Vrushali-Z <zampalkarvasu@gmail.com>
This commit is contained in:
zeertzjq
2026-09-08 23:24:45 +08:00
committed by GitHub
parent 623508dc06
commit e66fdc1eac
8 changed files with 84 additions and 12 deletions

View File

@@ -551,6 +551,8 @@ These existing features changed their behavior.
requires it to be installed).
• `:helptags ALL` reports |E152| for "doc" directories it cannot write,
instead of silently skipping them.
• The highlighting groups |hl-CursorLineFold| and |hl-CursorLineSign| are
always used when 'cursorline' is set.
==============================================================================
REMOVED FEATURES *news-removed*

View File

@@ -2098,7 +2098,14 @@ A jump table for the options with a short description can be found at |Q_op|.
*'cursorline'* *'cul'* *'nocursorline'* *'nocul'*
'cursorline' 'cul' boolean (default off)
local to window
Highlight the text line of the cursor with CursorLine |hl-CursorLine|.
Highlighting used for the line the cursor is on:
CursorLine the text line |hl-CursorLine|
CursorLineFold the fold column |hl-CursorLineFold|
CursorLineSign the sign column |hl-CursorLineSign|
CursorLineNr the line number, when 'cursorlineopt' contains
"number" |hl-CursorLineNr|
Useful to easily spot the cursor. Will make screen redrawing slower.
When Visual mode is active the highlighting isn't used to make it
easier to see the selected text.

View File

@@ -1624,7 +1624,14 @@ vim.o.cuc = vim.o.cursorcolumn
vim.wo.cursorcolumn = vim.o.cursorcolumn
vim.wo.cuc = vim.wo.cursorcolumn
--- Highlight the text line of the cursor with CursorLine `hl-CursorLine`.
--- Highlighting used for the line the cursor is on:
---
--- CursorLine the text line `hl-CursorLine`
--- CursorLineFold the fold column `hl-CursorLineFold`
--- CursorLineSign the sign column `hl-CursorLineSign`
--- CursorLineNr the line number, when 'cursorlineopt' contains
--- "number" `hl-CursorLineNr`
---
--- Useful to easily spot the cursor. Will make screen redrawing slower.
--- When Visual mode is active the highlighting isn't used to make it
--- easier to see the selected text.

View File

@@ -480,12 +480,11 @@ static void draw_col_fill(winlinevars_T *wlv, schar_T fillchar, int width, int a
}
}
/// Return true if CursorLineSign highlight is to be used.
/// Return true if CursorLineSign / CursorLineFold highlight is to be used.
/// This depends only on 'cursorline', not on 'cursorlineopt'.
bool use_cursor_line_highlight(win_T *wp, linenr_T lnum)
{
return wp->w_p_cul
&& lnum == wp->w_cursorline
&& (wp->w_p_culopt_flags & kOptCuloptFlagNumber);
return wp->w_p_cul && lnum == wp->w_cursorline;
}
/// Setup for drawing the 'foldcolumn', if there is one.

View File

@@ -2233,7 +2233,14 @@ local options = {
abbreviation = 'cul',
defaults = false,
desc = [=[
Highlight the text line of the cursor with CursorLine |hl-CursorLine|.
Highlighting used for the line the cursor is on:
CursorLine the text line |hl-CursorLine|
CursorLineFold the fold column |hl-CursorLineFold|
CursorLineSign the sign column |hl-CursorLineSign|
CursorLineNr the line number, when 'cursorlineopt' contains
"number" |hl-CursorLineNr|
Useful to easily spot the cursor. Will make screen redrawing slower.
When Visual mode is active the highlighting isn't used to make it
easier to see the selected text.

View File

@@ -194,7 +194,7 @@ describe('folded lines', function()
[2:---------------------------------------------]|*7
[3:---------------------------------------------]|
## grid 2
{7:+ }{8: 1 }{101:^+-- 4 lines: This is a················}|
{10:+ }{8: 1 }{101:^+-- 4 lines: This is a················}|
{7: }{8: 5 }in his cave. |
{7: }{8: 6 } |
{1:~ }|*4
@@ -207,7 +207,7 @@ describe('folded lines', function()
[2:---------------------------------------------]|*7
[3:---------------------------------------------]|
## grid 2
{7:+ }{8: 1 }{101:^This is a······························}|
{10:+ }{8: 1 }{101:^This is a······························}|
{7: }{8: 5 }in his cave. |
{7: }{8: 6 } |
{1:~ }|*4
@@ -218,7 +218,7 @@ describe('folded lines', function()
else
if foldtext then
screen:expect([[
{7:+ }{8: 1 }{101:^+-- 4 lines: This is a················}|
{10:+ }{8: 1 }{101:^+-- 4 lines: This is a················}|
{7: }{8: 5 }in his cave. |
{7: }{8: 6 } |
{1:~ }|*4
@@ -226,7 +226,7 @@ describe('folded lines', function()
]])
else
screen:expect([[
{7:+ }{8: 1 }{101:^This is a······························}|
{10:+ }{8: 1 }{101:^This is a······························}|
{7: }{8: 5 }in his cave. |
{7: }{8: 6 } |
{1:~ }|*4

View File

@@ -162,7 +162,7 @@ describe('Signs', function()
exec('set cursorline cursorlineopt=line')
screen:expect([[
{101:>>}a |
{101:>>}{21:^b }|
{9:>>}{21:^b }|
{101:>>}c |
{1:~ }|*10
|

View File

@@ -107,6 +107,56 @@ func Test_cursorline_highlight2()
endtry
endfunc
func Test_cursorline_fold_sign_independent_of_culopt()
" CursorLineFold/CursorLineSign follow 'cursorline', not 'cursorlineopt'.
CheckOption cursorlineopt
CheckFeature signs
CheckFeature folding
call s:test_windows(10, 20)
try
call setline(1, repeat(['aaaa'], 5))
setl number numberwidth=4 signcolumn=yes foldcolumn=1
hi FoldColumn ctermbg=1 guibg=Red
hi CursorLineFold ctermbg=2 guibg=Green
hi SignColumn ctermbg=3 guibg=Yellow
hi CursorLineSign ctermbg=4 guibg=Blue
setl nocursorline
redraw
let fold_off = screenattr(1, 1)
let sign_off = screenattr(1, 2)
" 'cursorlineopt' is "line" only: fold/sign on the cursor line still
" use CursorLineFold / CursorLineSign.
setl cursorline cursorlineopt=line
redraw
call assert_notequal(fold_off, screenattr(1, 1))
call assert_notequal(sign_off, screenattr(1, 2))
call assert_equal(fold_off, screenattr(2, 1))
call assert_equal(sign_off, screenattr(2, 2))
setl cursorlineopt=number
redraw
call assert_notequal(fold_off, screenattr(1, 1))
call assert_notequal(sign_off, screenattr(1, 2))
setl cursorlineopt=both
redraw
call assert_notequal(fold_off, screenattr(1, 1))
call assert_notequal(sign_off, screenattr(1, 2))
finally
setl number& numberwidth& signcolumn& foldcolumn& cursorline& cursorlineopt&
hi clear FoldColumn
hi clear CursorLineFold
hi clear SignColumn
hi clear CursorLineSign
hi default link CursorLineFold FoldColumn
hi default link CursorLineSign SignColumn
call s:close_windows()
endtry
endfunc
func Test_cursorline_screenline()
CheckScreendump
CheckOption cursorlineopt