0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.1.1276: cannot combine text properties with syntax highlighting

Problem:    Cannot combine text properties with syntax highlighting.
Solution:   Add the "combine" field to prop_type_add(). (closes #4343)
This commit is contained in:
Bram Moolenaar
2019-05-05 15:48:00 +02:00
parent cf6a55c4b0
commit de24a87013
6 changed files with 49 additions and 14 deletions

View File

@@ -7218,6 +7218,9 @@ prop_type_add({name}, {props}) *prop_type_add()* *E969* *E970*
properties the one with the highest priority properties the one with the highest priority
will be used; negative values can be used, the will be used; negative values can be used, the
default priority is zero default priority is zero
combine when TRUE combine the highlight with any
syntax highlight; when omitted of FALSE syntax
highlight will not be used
start_incl when TRUE inserts at the start position will start_incl when TRUE inserts at the start position will
be included in the text property be included in the text property
end_incl when TRUE inserts at the end position will be end_incl when TRUE inserts at the end position will be

View File

@@ -1,4 +1,4 @@
*textprop.txt* For Vim version 8.1. Last change: 2019 Jan 08 *textprop.txt* For Vim version 8.1. Last change: 2019 May 05
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@@ -57,6 +57,10 @@ Property Types ~
A text property normally has the name of a property type, which defines A text property normally has the name of a property type, which defines
how to highlight the text. The property type can have these entries: how to highlight the text. The property type can have these entries:
"highlight" name of the highlight group to use "highlight" name of the highlight group to use
"combine" when TRUE the text property highlighting is combined
with any syntax highligting, when omitted or FALSE the
text property highlighting replaces the syntax
highlighting
"priority" when properties overlap, the one with the highest "priority" when properties overlap, the one with the highest
priority will be used. priority will be used.
"start_incl" when TRUE inserts at the start position will be "start_incl" when TRUE inserts at the start position will be

View File

@@ -3059,6 +3059,7 @@ win_line(
int text_props_active = 0; int text_props_active = 0;
proptype_T *text_prop_type = NULL; proptype_T *text_prop_type = NULL;
int text_prop_attr = 0; int text_prop_attr = 0;
int text_prop_combine = FALSE;
#endif #endif
#ifdef FEAT_SPELL #ifdef FEAT_SPELL
int has_spell = FALSE; /* this buffer has spell checking */ int has_spell = FALSE; /* this buffer has spell checking */
@@ -4261,6 +4262,7 @@ win_line(
text_prop_idxs[text_props_active++] = text_prop_next++; text_prop_idxs[text_props_active++] = text_prop_next++;
text_prop_attr = 0; text_prop_attr = 0;
text_prop_combine = FALSE;
if (text_props_active > 0) if (text_props_active > 0)
{ {
// Sort the properties on priority and/or starting last. // Sort the properties on priority and/or starting last.
@@ -4273,17 +4275,17 @@ win_line(
for (pi = 0; pi < text_props_active; ++pi) for (pi = 0; pi < text_props_active; ++pi)
{ {
int tpi = text_prop_idxs[pi]; int tpi = text_prop_idxs[pi];
proptype_T *pt = text_prop_type_by_id(wp->w_buffer, text_props[tpi].tp_type); proptype_T *pt = text_prop_type_by_id(
wp->w_buffer, text_props[tpi].tp_type);
if (pt != NULL) if (pt != NULL)
{ {
int pt_attr = syn_id2attr(pt->pt_hl_id); int pt_attr = syn_id2attr(pt->pt_hl_id);
text_prop_type = pt; text_prop_type = pt;
if (text_prop_attr == 0) text_prop_attr =
text_prop_attr = pt_attr; hl_combine_attr(text_prop_attr, pt_attr);
else text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
text_prop_attr = hl_combine_attr(text_prop_attr, pt_attr);
} }
} }
} }
@@ -4314,7 +4316,13 @@ win_line(
attr_pri = FALSE; attr_pri = FALSE;
#ifdef FEAT_TEXT_PROP #ifdef FEAT_TEXT_PROP
if (text_prop_type != NULL) if (text_prop_type != NULL)
char_attr = text_prop_attr; {
if (text_prop_combine)
char_attr = hl_combine_attr(
syntax_attr, text_prop_attr);
else
char_attr = text_prop_attr;
}
else else
#endif #endif
#ifdef FEAT_SYN_HL #ifdef FEAT_SYN_HL
@@ -4664,14 +4672,18 @@ win_line(
ptr = line + v; ptr = line + v;
# ifdef FEAT_TEXT_PROP # ifdef FEAT_TEXT_PROP
// Text properties overrule syntax highlighting. // Text properties overrule syntax highlighting or combine.
if (text_prop_attr == 0) if (text_prop_attr == 0 || text_prop_combine)
#endif # endif
{ {
int comb_attr = syntax_attr;
# ifdef FEAT_TEXT_PROP
comb_attr = hl_combine_attr(text_prop_attr, comb_attr);
# endif
if (!attr_pri) if (!attr_pri)
char_attr = syntax_attr; char_attr = comb_attr;
else else
char_attr = hl_combine_attr(syntax_attr, char_attr); char_attr = hl_combine_attr(comb_attr, char_attr);
} }
# ifdef FEAT_CONCEAL # ifdef FEAT_CONCEAL
/* no concealing past the end of the line, it interferes /* no concealing past the end of the line, it interferes

View File

@@ -727,6 +727,7 @@ typedef struct proptype_S
#define PT_FLAG_INS_START_INCL 1 // insert at start included in property #define PT_FLAG_INS_START_INCL 1 // insert at start included in property
#define PT_FLAG_INS_END_INCL 2 // insert at end included in property #define PT_FLAG_INS_END_INCL 2 // insert at end included in property
#define PT_FLAG_COMBINE 4 // combine with syntax highlight
// Sign group // Sign group
typedef struct signgroup_S typedef struct signgroup_S

View File

@@ -559,14 +559,23 @@ funct Test_textprop_screenshots()
return return
endif endif
call writefile([ call writefile([
\ "call setline(1, ['One two', 'Numbér 123 änd thœn 4¾7.', '--aa--bb--cc--dd--'])", \ "call setline(1, ["
\ .. "'One two',"
\ .. "'Numbér 123 änd thœn 4¾7.',"
\ .. "'--aa--bb--cc--dd--',"
\ .. "'// comment with error in it',"
\ .. "])",
\ "hi NumberProp ctermfg=blue", \ "hi NumberProp ctermfg=blue",
\ "hi LongProp ctermbg=yellow", \ "hi LongProp ctermbg=yellow",
\ "hi BackgroundProp ctermbg=lightgrey",
\ "hi UnderlineProp cterm=underline",
\ "call prop_type_add('number', {'highlight': 'NumberProp'})", \ "call prop_type_add('number', {'highlight': 'NumberProp'})",
\ "call prop_type_add('long', {'highlight': 'LongProp'})", \ "call prop_type_add('long', {'highlight': 'LongProp'})",
\ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})", \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})",
\ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})", \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})",
\ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})", \ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})",
\ "call prop_type_add('background', {'highlight': 'BackgroundProp', 'combine': 1})",
\ "call prop_type_add('error', {'highlight': 'UnderlineProp', 'combine': 1})",
\ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})", \ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})",
\ "call prop_add(2, 9, {'length': 3, 'type': 'number'})", \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})",
\ "call prop_add(2, 24, {'length': 4, 'type': 'number'})", \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})",
@@ -574,13 +583,17 @@ funct Test_textprop_screenshots()
\ "call prop_add(3, 7, {'length': 2, 'type': 'start'})", \ "call prop_add(3, 7, {'length': 2, 'type': 'start'})",
\ "call prop_add(3, 11, {'length': 2, 'type': 'end'})", \ "call prop_add(3, 11, {'length': 2, 'type': 'end'})",
\ "call prop_add(3, 15, {'length': 2, 'type': 'both'})", \ "call prop_add(3, 15, {'length': 2, 'type': 'both'})",
\ "call prop_add(4, 12, {'length': 10, 'type': 'background'})",
\ "call prop_add(4, 17, {'length': 5, 'type': 'error'})",
\ "set number", \ "set number",
\ "hi clear SpellBad", \ "hi clear SpellBad",
\ "set spell", \ "set spell",
\ "syn match Comment '//.*'",
\ "hi Comment ctermfg=green",
\ "normal 3G0llix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>", \ "normal 3G0llix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>",
\ "normal 3G0lli\<BS>\<Esc>", \ "normal 3G0lli\<BS>\<Esc>",
\], 'XtestProp') \], 'XtestProp')
let buf = RunVimInTerminal('-S XtestProp', {'rows': 6}) let buf = RunVimInTerminal('-S XtestProp', {'rows': 7})
call VerifyScreenDump(buf, 'Test_textprop_01', {}) call VerifyScreenDump(buf, 'Test_textprop_01', {})
" clean up " clean up

View File

@@ -767,6 +767,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1276,
/**/ /**/
1275, 1275,
/**/ /**/