aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbby <33922797+SleepySwords@users.noreply.github.com>2023-04-05 00:29:05 +1000
committerbfredl <bjorn.linse@gmail.com>2023-05-22 13:49:42 +0200
commit75f350aac6cd952341d7ce88e64b0d6ed2aa694d (patch)
treedcd05364fe033b84b180b574c8ed637973671e4e
parent332b70d2ed310084fe382affddbef3126c12751c (diff)
downloadrneovim-75f350aac6cd952341d7ce88e64b0d6ed2aa694d.tar.gz
rneovim-75f350aac6cd952341d7ce88e64b0d6ed2aa694d.tar.bz2
rneovim-75f350aac6cd952341d7ce88e64b0d6ed2aa694d.zip
fix(ui): fix incorrect highlighting when virtual text next to match
-rw-r--r--src/nvim/drawline.c8
-rw-r--r--test/functional/ui/decorations_spec.lua53
2 files changed, 54 insertions, 7 deletions
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index 466fe8f8f1..23b88413b1 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -102,7 +102,6 @@ typedef struct {
///< when c_extra and c_final are NUL
char *p_extra_free; ///< p_extra buffer that needs to be freed
int extra_attr; ///< attributes for p_extra
- ///< with win_attr if needed
int c_extra; ///< extra chars, all the same
int c_final; ///< final char, mandatory if set
@@ -1026,6 +1025,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
int prev_c1 = 0; // first composing char for prev_c
bool search_attr_from_match = false; // if search_attr is from :match
+ bool saved_search_attr_from_match = false; // if search_attr is from :match
bool has_decor = false; // this buffer has decoration
int win_col_offset = 0; // offset for window columns
@@ -1786,6 +1786,8 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
// is down to zero
saved_search_attr = search_attr;
saved_area_attr = area_attr;
+ saved_search_attr_from_match = search_attr_from_match;
+ search_attr_from_match = false;
search_attr = 0;
area_attr = 0;
extmark_attr = 0;
@@ -1815,7 +1817,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
}
}
- if (!wlv.n_extra) {
+ if (wlv.n_extra == 0) {
// Check for start/end of 'hlsearch' and other matches.
// After end, check for start/end of next match.
// When another match, have to check for start again.
@@ -2606,6 +2608,8 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
if (reset_extra_attr) {
reset_extra_attr = false;
wlv.extra_attr = 0;
+ // search_attr_from_match can be restored now that the extra_attr has been applied
+ search_attr_from_match = saved_search_attr_from_match;
}
}
diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua
index 2d0f3e7a17..292743e21a 100644
--- a/test/functional/ui/decorations_spec.lua
+++ b/test/functional/ui/decorations_spec.lua
@@ -1746,9 +1746,9 @@ bbbbbbb]])
insert('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz')
command("set nowrap")
meths.buf_set_extmark(0, ns, 0, 50,
- { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline', right_gravity = false })
+ { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
meths.buf_set_extmark(0, ns, 0, 2,
- { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline', right_gravity = false })
+ { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
feed('$')
screen:expect { grid = [[
opqrstuvwxyzabcdefghijklmnopqrstuvwx{28:virtual text}y^z|
@@ -1773,7 +1773,7 @@ bbbbbbb]])
insert('abcdefghi')
command("set nowrap")
meths.buf_set_extmark(0, ns, 0, 2,
- { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline', right_gravity = false })
+ { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline' })
feed('$')
screen:expect { grid = [[
{28:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}cdefgh^i|
@@ -1823,7 +1823,7 @@ bbbbbbb]])
insert('abcdef')
command("set nowrap")
meths.buf_set_extmark(0, ns, 0, 3,
- { virt_text = { { string.rep('X', 50), 'Special' } }, virt_text_pos = 'inline', right_gravity = false })
+ { virt_text = { { string.rep('X', 50), 'Special' } }, virt_text_pos = 'inline' })
feed('$')
screen:expect { grid = [[
{28:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}de^f|
@@ -1850,7 +1850,7 @@ bbbbbbb]])
test]])
command('set number')
meths.buf_set_extmark(0, ns, 0, 1,
- { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline', right_gravity = false })
+ { virt_text = { { string.rep('X', 55), 'Special' } }, virt_text_pos = 'inline' })
feed('gg0')
screen:expect { grid = [[
{2: 1 }^t{28:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}|
@@ -1870,6 +1870,49 @@ bbbbbbb]])
|
]]}
end)
+
+ it('highlighting is correct when virtual text is proceeded with a match', function()
+ insert([[test]])
+ meths.buf_set_extmark(0, ns, 0, 2,
+ { virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
+ feed('gg0')
+ command('match ErrorMsg /e/')
+ screen:expect { grid = [[
+ ^t{4:e}{28:virtual text}st |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ command('match ErrorMsg /s/')
+ screen:expect { grid = [[
+ ^te{28:virtual text}{4:s}t |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]]}
+ end)
end)
describe('decorations: virtual lines', function()