From 33486c8ebd57074d9c92c4de06ea4dcab573c01e Mon Sep 17 00:00:00 2001 From: Yichao Zhou Date: Wed, 11 May 2016 19:16:07 -0700 Subject: [PATCH 1/6] Let the highlight of listchars override cursorline Closes #3670 --- src/nvim/screen.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 10b5b6bba4..a1f74279ce 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3402,11 +3402,9 @@ win_line ( if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') { c = lcs_trail; - if (!attr_pri) { - n_attr = 1; - extra_attr = hl_attr(HLF_8); - saved_attr2 = char_attr; /* save current attr */ - } + n_attr = 1; + extra_attr = hl_attr(HLF_8); + saved_attr2 = char_attr; /* save current attr */ mb_c = c; if (enc_utf8 && (*mb_char2len)(c) > 1) { mb_utf8 = TRUE; @@ -3555,10 +3553,8 @@ win_line ( } lcs_eol_one = -1; --ptr; /* put it back at the NUL */ - if (!attr_pri) { - extra_attr = hl_attr(HLF_AT); - n_attr = 1; - } + extra_attr = hl_attr(HLF_AT); + n_attr = 1; mb_c = c; if (enc_utf8 && (*mb_char2len)(c) > 1) { mb_utf8 = TRUE; @@ -3587,11 +3583,9 @@ win_line ( n_extra = byte2cells(c) - 1; c = *p_extra++; } - if (!attr_pri) { - n_attr = n_extra + 1; - extra_attr = hl_attr(HLF_8); - saved_attr2 = char_attr; /* save current attr */ - } + n_attr = n_extra + 1; + extra_attr = hl_attr(HLF_8); + saved_attr2 = char_attr; /* save current attr */ mb_utf8 = FALSE; /* don't draw as UTF-8 */ } else if (VIsual_active && (VIsual_mode == Ctrl_V @@ -3703,10 +3697,8 @@ win_line ( } /* Don't override visual selection highlighting. */ - if (n_attr > 0 - && draw_state == WL_LINE - && !attr_pri) - char_attr = extra_attr; + if (n_attr > 0 && draw_state == WL_LINE) + char_attr = hl_combine_attr(char_attr, extra_attr); /* * Handle the case where we are in column 0 but not on the first From 9dc08dd692ed97290fc5c8ebcb20438616b891b8 Mon Sep 17 00:00:00 2001 From: Yichao Zhou Date: Thu, 12 May 2016 00:49:05 -0700 Subject: [PATCH 2/6] test: Update to meet new expectations. --- test/functional/ui/mouse_spec.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index d0d791308b..993bbd5b0e 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -23,7 +23,12 @@ describe('Mouse input', function() screen:attach() screen:set_default_attr_ids({ [1] = {background = hlgroup_colors.Visual}, - [2] = {bold = true} + [2] = {bold = true}, + [3] = { + foreground = hlgroup_colors.NonText, + background = hlgroup_colors.Visual, + bold = true, + }, }) screen:set_default_attr_ignore( {{bold=true, foreground=hlgroup_colors.NonText}} ) feed('itestingmousesupport and selection') @@ -225,14 +230,14 @@ describe('Mouse input', function() feed('<2,2>') screen:expect([[ testing | - mo{1:use } | + mo{1:use}{3: } | {1:su}^pport and selection | ~ | {2:-- VISUAL --} | ]]) feed('<0,0>') screen:expect([[ - ^t{1:esting } | + ^t{1:esting}{3: } | {1:mou}se | support and selection | ~ | @@ -293,7 +298,7 @@ describe('Mouse input', function() screen:expect([[ testing | mouse | - {1:su}^p{1:port and selection } | + {1:su}^p{1:port and selection}{3: } | ~ | {2:-- VISUAL LINE --} | ]]) @@ -321,8 +326,8 @@ describe('Mouse input', function() ]]) feed('<2,2>') screen:expect([[ - {1:testing } | - {1:mouse } | + {1:testing}{3: } | + {1:mouse}{3: } | {1:su}^pport and selection | ~ | {2:-- VISUAL --} | From 391d8ff3d8d2edfe56f7d14baddec7ddc38466ae Mon Sep 17 00:00:00 2001 From: Yichao Zhou Date: Sat, 14 May 2016 00:24:41 -0700 Subject: [PATCH 3/6] lint --- src/nvim/screen.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/nvim/screen.c b/src/nvim/screen.c index a1f74279ce..7d358ab7b6 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3404,7 +3404,7 @@ win_line ( c = lcs_trail; n_attr = 1; extra_attr = hl_attr(HLF_8); - saved_attr2 = char_attr; /* save current attr */ + saved_attr2 = char_attr; // save current attr mb_c = c; if (enc_utf8 && (*mb_char2len)(c) > 1) { mb_utf8 = TRUE; @@ -3552,7 +3552,7 @@ win_line ( c = ' '; } lcs_eol_one = -1; - --ptr; /* put it back at the NUL */ + ptr--; // put it back at the NUL extra_attr = hl_attr(HLF_AT); n_attr = 1; mb_c = c; @@ -3585,8 +3585,8 @@ win_line ( } n_attr = n_extra + 1; extra_attr = hl_attr(HLF_8); - saved_attr2 = char_attr; /* save current attr */ - mb_utf8 = FALSE; /* don't draw as UTF-8 */ + saved_attr2 = char_attr; // save current attr + mb_utf8 = false; // don't draw as UTF-8 } else if (VIsual_active && (VIsual_mode == Ctrl_V || VIsual_mode == 'v') @@ -3696,9 +3696,10 @@ win_line ( did_wcol = true; } - /* Don't override visual selection highlighting. */ - if (n_attr > 0 && draw_state == WL_LINE) + // Don't override visual selection highlighting. + if (n_attr > 0 && draw_state == WL_LINE) { char_attr = hl_combine_attr(char_attr, extra_attr); + } /* * Handle the case where we are in column 0 but not on the first @@ -3726,13 +3727,12 @@ win_line ( mb_utf8 = TRUE; u8cc[0] = 0; c = 0xc0; - } else - mb_utf8 = FALSE; /* don't draw as UTF-8 */ - if (!attr_pri) { - saved_attr3 = char_attr; /* save current attr */ - char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ - n_attr3 = 1; + } else { + mb_utf8 = false; // don't draw as UTF-8 } + saved_attr3 = char_attr; // save current attr + char_attr = hl_attr(HLF_AT); // later copied to char_attr + n_attr3 = 1; } /* From f598bb7b3c3cebaab7a4812ca4f3f490efc037f9 Mon Sep 17 00:00:00 2001 From: Yichao Zhou Date: Sat, 14 May 2016 01:54:05 -0700 Subject: [PATCH 4/6] test: cursorline, listchars --- test/functional/ui/highlight_spec.lua | 144 ++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index d0df99677a..fca1dcec87 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -361,3 +361,147 @@ describe('guisp (special/undercurl)', function() end) end) + +describe("'cursorline' with 'listchars'", function() + local screen + + local hlgroup_colors = { + NonText = Screen.colors.Blue, + Cursorline = Screen.colors.Grey90, + SpecialKey = Screen.colors.Red, + } + + before_each(function() + clear() + screen = Screen.new(20,5) + screen:attach() + end) + + after_each(function() + screen:detach() + end) + + it("'cursorline' and 'cursorcolumn'", function() + screen:set_default_attr_ids({[1] = {background=hlgroup_colors.Cursorline}}) + screen:set_default_attr_ignore( {{bold=true, foreground=hlgroup_colors.NonText}} ) + execute('highlight clear ModeMsg') + execute('set cursorline') + feed('i') + screen:expect([[ + {1:^ }| + ~ | + ~ | + ~ | + -- INSERT -- | + ]]) + feed('abcdefgkkasdf') + screen:expect([[ + abcdefg | + {1:kkasdf^ }| + ~ | + ~ | + -- INSERT -- | + ]]) + feed('') + screen:expect([[ + abcdefg | + {1:kkasd^f }| + ~ | + ~ | + | + ]]) + execute('set nocursorline') + screen:expect([[ + abcdefg | + kkasd^f | + ~ | + ~ | + :set nocursorline | + ]]) + feed('k') + screen:expect([[ + abcde^fg | + kkasdf | + ~ | + ~ | + :set nocursorline | + ]]) + feed('jjji') + screen:expect([[ + kkasd | + | + | + ^f | + | + ]]) + execute('set cursorline') + execute('set cursorcolumn') + feed('kkiabcdefghijkhh') + screen:expect([[ + kkasd {1: } | + {1:abcdefgh^ijk }| + {1: } | + f {1: } | + | + ]]) + feed('khh') + screen:expect([[ + {1:kk^asd }| + ab{1:c}defghijk | + {1: } | + f {1: } | + | + ]]) + end) + + it("'cursorline' and with 'listchar' option: space, eol, tab, and trail", function() + screen:set_default_attr_ids({ + [1] = {background=hlgroup_colors.Cursorline}, + [2] = { + foreground=hlgroup_colors.SpecialKey, + background=hlgroup_colors.Cursorline, + }, + [3] = { + background=hlgroup_colors.Cursorline, + foreground=hlgroup_colors.NonText, + bold=true, + }, + [4] = { + foreground=hlgroup_colors.NonText, + bold=true, + }, + [5] = { + foreground=hlgroup_colors.SpecialKey, + }, + }) + execute('highlight clear ModeMsg') + execute('highlight SpecialKey guifg=#FF0000') + execute('set cursorline') + execute('set tabstop=8') + execute('set listchars=space:.,eol:¬,tab:>-,extends:],precedes:[,trail:* list') + feed('i\t abcd \t abcd k') + screen:expect([[ + {5:>-------.}abcd{5:*}{4:¬} | + {2:^>-------.}{1:abcd}{2:*}{3:¬}{1: }| + {4:¬} | + {4:~ }| + | + ]]) + feed('k') + screen:expect([[ + {2:^>-------.}{1:abcd}{2:*}{3:¬}{1: }| + {5:>-------.}abcd{5:*}{4:¬} | + {4:¬} | + {4:~ }| + | + ]]) + execute('set nocursorline') + screen:expect([[ + {5:^>-------.}abcd{5:*}{4:¬} | + {5:>-------.}abcd{5:*}{4:¬} | + {4:¬} | + {4:~ }| + :set nocursorline | + ]]) + end) +end) From 4eb4a5cdb2f022a6a5ceb81fe615a259191ec2d9 Mon Sep 17 00:00:00 2001 From: Yichao Zhou Date: Sun, 15 May 2016 21:53:15 -0700 Subject: [PATCH 5/6] screen.c: Fix listchars hl for space/nbsp in visual mode. --- src/nvim/screen.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 7d358ab7b6..34eef83164 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3385,11 +3385,9 @@ win_line ( && lcs_nbsp) || (c == ' ' && lcs_space && ptr - line <= trailcol))) { c = (c == ' ') ? lcs_space : lcs_nbsp; - if (area_attr == 0 && search_attr == 0) { - n_attr = 1; - extra_attr = hl_attr(HLF_8); - saved_attr2 = char_attr; // save current attr - } + n_attr = 1; + extra_attr = hl_attr(HLF_8); + saved_attr2 = char_attr; // save current attr mb_c = c; if (enc_utf8 && (*mb_char2len)(c) > 1) { mb_utf8 = true; From 723497f030c76e07453b0cdd24ed404e6fb5a2a6 Mon Sep 17 00:00:00 2001 From: Yichao Zhou Date: Tue, 17 May 2016 16:26:03 -0700 Subject: [PATCH 6/6] test: listchars --- test/functional/ui/highlight_spec.lua | 108 +++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index fca1dcec87..0229b8bbf7 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -369,6 +369,7 @@ describe("'cursorline' with 'listchars'", function() NonText = Screen.colors.Blue, Cursorline = Screen.colors.Grey90, SpecialKey = Screen.colors.Red, + Visual = Screen.colors.LightGrey, } before_each(function() @@ -478,7 +479,7 @@ describe("'cursorline' with 'listchars'", function() execute('highlight SpecialKey guifg=#FF0000') execute('set cursorline') execute('set tabstop=8') - execute('set listchars=space:.,eol:¬,tab:>-,extends:],precedes:[,trail:* list') + execute('set listchars=space:.,eol:¬,tab:>-,extends:>,precedes:<,trail:* list') feed('i\t abcd \t abcd k') screen:expect([[ {5:>-------.}abcd{5:*}{4:¬} | @@ -503,5 +504,110 @@ describe("'cursorline' with 'listchars'", function() {4:~ }| :set nocursorline | ]]) + execute('set nowrap') + feed('ALorem ipsum dolor sit amet0') + screen:expect([[ + {5:^>-------.}abcd{5:.}Lorem{4:>}| + {5:>-------.}abcd{5:*}{4:¬} | + {4:¬} | + {4:~ }| + | + ]]) + execute('set cursorline') + screen:expect([[ + {2:^>-------.}{1:abcd}{2:.}{1:Lorem}{4:>}| + {5:>-------.}abcd{5:*}{4:¬} | + {4:¬} | + {4:~ }| + :set cursorline | + ]]) + feed('$') + screen:expect([[ + {4:<}{1:r}{2:.}{1:sit}{2:.}{1:ame^t}{3:¬}{1: }| + {4:<} | + {4:<} | + {4:~ }| + :set cursorline | + ]]) + feed('G') + screen:expect([[ + {5:>-------.}abcd{5:.}Lorem{4:>}| + {5:>-------.}abcd{5:*}{4:¬} | + {3:^¬}{1: }| + {4:~ }| + :set cursorline | + ]]) + end) + + it("'listchar' in visual mode", function() + screen:set_default_attr_ids({ + [1] = {background=hlgroup_colors.Cursorline}, + [2] = { + foreground=hlgroup_colors.SpecialKey, + background=hlgroup_colors.Cursorline, + }, + [3] = { + background=hlgroup_colors.Cursorline, + foreground=hlgroup_colors.NonText, + bold=true, + }, + [4] = { + foreground=hlgroup_colors.NonText, + bold=true, + }, + [5] = { + foreground=hlgroup_colors.SpecialKey, + }, + [6] = { + background=hlgroup_colors.Visual, + }, + [7] = { + background=hlgroup_colors.Visual, + foreground=hlgroup_colors.SpecialKey, + }, + [8] = { + background=hlgroup_colors.Visual, + foreground=hlgroup_colors.NonText, + bold=true, + }, + }) + execute('highlight clear ModeMsg') + execute('highlight SpecialKey guifg=#FF0000') + execute('set cursorline') + execute('set tabstop=8') + execute('set nowrap') + execute('set listchars=space:.,eol:¬,tab:>-,extends:>,precedes:<,trail:* list') + feed('i\t abcd \t abcd Lorem ipsum dolor sit ametkkk0') + screen:expect([[ + {2:^>-------.}{1:abcd}{2:*}{3:¬}{1: }| + {5:>-------.}abcd{5:.}Lorem{4:>}| + {4:¬} | + {4:~ }| + | + ]]) + feed('lllvj') + screen:expect([[ + {5:>-------.}a{6:bcd}{7:*}{8:¬} | + {7:>-------.}{6:a}^bcd{5:.}Lorem{4:>}| + {4:¬} | + {4:~ }| + -- VISUAL -- | + ]]) + feed('V') + screen:expect([[ + {5:>-------.}abcd{5:*}{4:¬} | + {7:>-------.}{6:a}^b{6:cd}{7:.}{6:Lorem}{4:>}| + {4:¬} | + {4:~ }| + -- VISUAL LINE -- | + ]]) + feed('$') + screen:expect([[ + {4:<} | + {4:<}{1:r}{2:.}{1:sit}{2:.}{1:ame^t}{3:¬}{1: }| + {4:<} | + {4:~ }| + | + ]]) end) end)