Skip to content

Commit

Permalink
lower the priority of cursorline, close neovim#7383 and neovim#6380
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou13 committed Jun 18, 2018
1 parent b006771 commit 22c1a1f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 23 deletions.
62 changes: 42 additions & 20 deletions src/nvim/screen.c
Expand Up @@ -2184,6 +2184,8 @@ win_line (
int prev_c1 = 0; // first composing char for prev_c
int did_line_attr = 0;

int line_attr_low_priority = 0; // attribute for current line with
// low priority, e.g., cursorline
bool search_attr_from_match = false; // if search_attr is from :match
bool has_bufhl = false; // this buffer has highlight matches
int bufhl_attr = 0; // attributes desired by bufhl
Expand Down Expand Up @@ -2398,6 +2400,31 @@ win_line (
filler_lines = wp->w_topfill;
filler_todo = filler_lines;

// Cursor line highlighting for 'cursorline' in the current window. Not
// when Visual mode is active, because it's not clear what is selected
// then.
if (wp->w_p_cul && lnum == wp->w_cursor.lnum
&& !(wp == curwin && VIsual_active)) {
int cul_attr = win_hl_attr(wp, HLF_CUL);
HlAttrs *aep = syn_cterm_attr2entry(cul_attr);

// According to #7383, we make a compromise here:
// * low-priority CursorLine if only background is set (foreground is not
// set)
// * high-priority ("same as Vim" priority) CursorLine if foreground and
// background are set
if (aep->rgb_fg_color == -1 && aep->cterm_fg_color == 0) {
line_attr_low_priority = cul_attr;
} else {
if (line_attr != 0 && !(State & INSERT) && bt_quickfix(wp->w_buffer)
&& qf_current_entry(wp) == lnum) {
line_attr = hl_combine_attr(cul_attr, line_attr);
} else {
line_attr = cul_attr;
}
}
}

// If this line has a sign with line highlighting set line_attr.
v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL);
if (v != 0) {
Expand All @@ -2409,7 +2436,7 @@ win_line (
line_attr = win_hl_attr(wp, HLF_QFL);
}

if (line_attr != 0) {
if (line_attr_low_priority || line_attr) {
area_highlighting = true;
}

Expand Down Expand Up @@ -2631,20 +2658,6 @@ win_line (
cur = cur->next;
}

// Cursor line highlighting for 'cursorline' in the current window. Not
// when Visual mode is active, because it's not clear what is selected
// then.
if (wp->w_p_cul && lnum == wp->w_cursor.lnum
&& !(wp == curwin && VIsual_active)) {
if (line_attr != 0 && !(State & INSERT) && bt_quickfix(wp->w_buffer)
&& qf_current_entry(wp) == lnum) {
line_attr = hl_combine_attr(win_hl_attr(wp, HLF_CUL), line_attr);
} else {
line_attr = win_hl_attr(wp, HLF_CUL);
}
area_highlighting = true;
}

off = (unsigned)(current_ScreenLine - ScreenLines);
int col = 0; // Visual column on screen.
if (wp->w_p_rl) {
Expand Down Expand Up @@ -3566,9 +3579,12 @@ win_line (
&& lcs_eol_one > 0) {
// Display a '$' after the line or highlight an extra
// character if the line break is included.
// For a diff line the highlighting continues after the "$".
if (diff_hlf == (hlf_T)0 && line_attr == 0) {
// In virtualedit, visual selections may extend beyond end of line.
// For a diff line the highlighting continues after the
// "$".
if (diff_hlf == (hlf_T)0
&& line_attr == 0
&& line_attr_low_priority == 0) {
// In virtualedit, visual selections may extend beyond end of line
if (area_highlighting && virtual_active()
&& tocol != MAXCOL && vcol < tocol) {
n_extra = 0;
Expand Down Expand Up @@ -3631,7 +3647,7 @@ win_line (
(col < wp->w_width))) {
c = ' ';
ptr--; // put it back at the NUL
} else if ((diff_hlf != (hlf_T)0 || line_attr != 0)
} else if ((diff_hlf != (hlf_T)0 || line_attr_low_priority || line_attr)
&& (wp->w_p_rl
? (col >= 0)
: (col - boguscols < wp->w_width))) {
Expand All @@ -3643,7 +3659,8 @@ win_line (
did_line_attr++;

// don't do search HL for the rest of the line
if (line_attr != 0 && char_attr == search_attr && col > 0) {
if ((line_attr_low_priority || line_attr)
&& char_attr == search_attr && col > 0) {
char_attr = line_attr;
}
if (diff_hlf == HLF_TXD) {
Expand Down Expand Up @@ -4007,6 +4024,11 @@ win_line (
}
}

// apply line attr with lowest priority so that everthing can override it
if (draw_state == WL_LINE) {
char_attr = hl_combine_attr(line_attr_low_priority, char_attr);
}

/*
* Store character to be displayed.
* Skip characters that are left of the screen for 'nowrap'.
Expand Down
46 changes: 43 additions & 3 deletions test/functional/ui/highlight_spec.lua
Expand Up @@ -541,15 +541,15 @@ describe("'listchars' highlight", function()
]])
feed_command('set cursorline')
screen:expect([[
{2:^>-------.}{1:abcd}{2:.}{1:Lorem}{4:>}|
{2:^>-------.}{1:abcd}{2:.}{1:Lorem}{3:>}|
{5:>-------.}abcd{5:*}{4:¬} |
{4:¬} |
{4:~ }|
:set cursorline |
]])
feed('$')
screen:expect([[
{4:<}{1:r}{2:.}{1:sit}{2:.}{1:ame^t}{3:¬}{1: }|
{3:<}{1:r}{2:.}{1:sit}{2:.}{1:ame^t}{3:¬}{1: }|
{4:<} |
{4:<} |
{4:~ }|
Expand Down Expand Up @@ -630,7 +630,7 @@ describe("'listchars' highlight", function()
feed('<esc>$')
screen:expect([[
{4:<} |
{4:<}{1:r}{2:.}{1:sit}{2:.}{1:ame^t}{3:¬}{1: }|
{3:<}{1:r}{2:.}{1:sit}{2:.}{1:ame^t}{3:¬}{1: }|
{4:<} |
{4:~ }|
|
Expand Down Expand Up @@ -675,6 +675,46 @@ describe("'listchars' highlight", function()
end)
end)

describe("Cursorline", function()
before_each(clear)
it("is overrided by Error and ColorColumn", function()
local screen = Screen.new(50,5)
screen:set_default_attr_ids({
[1] = {foreground = Screen.colors.SlateBlue},
[2] = {bold = true, foreground = Screen.colors.Brown},
[3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
[4] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.Gray90},
[5] = {background = Screen.colors.Gray90},
[6] = {bold = true, foreground = Screen.colors.Blue1},
[7] = {background = Screen.colors.LightRed},
})
screen:attach()

feed_command('filetype on')
feed_command('syntax on')
feed_command('set cursorline ft=json')
feed('i{<cr>"a" : abc // 10;<cr>}<cr><esc>')
screen:expect([[
{1:{} |
"{2:a}" : {3:abc} {3:// 10;} |
{1:}} |
{5:^ }|
|
]])

feed_command('set colorcolumn=3')
feed('i <esc>')
screen:expect([[
{1:{} {7: } |
"{2:a}{7:"} : {3:abc} {3:// 10;} |
{1:}} {7: } |
{5: ^ }{7: }{5: }|
|
]])
end)
end)


describe("MsgSeparator highlight and msgsep fillchar", function()
before_each(clear)
it("works", function()
Expand Down

0 comments on commit 22c1a1f

Please sign in to comment.