1
0
forked from aniani/vim

patch 8.1.0579: cannot attach properties to text

Problem:    Cannot attach properties to text.
Solution:   First part of adding text properties.
This commit is contained in:
Bram Moolenaar
2018-12-13 22:20:09 +01:00
parent 5c5697f298
commit 98aefe7c32
26 changed files with 1747 additions and 46 deletions

View File

@@ -3128,6 +3128,15 @@ win_line(
int draw_color_col = FALSE; /* highlight colorcolumn */
int *color_cols = NULL; /* pointer to according columns array */
#endif
#ifdef FEAT_TEXT_PROP
int text_prop_count;
int text_prop_next = 0; // next text property to use
textprop_T *text_props = NULL;
int *text_prop_idxs = NULL;
int text_props_active = 0;
proptype_T *text_prop_type = NULL;
int text_prop_attr = 0;
#endif
#ifdef FEAT_SPELL
int has_spell = FALSE; /* this buffer has spell checking */
# define SPWORDLEN 150
@@ -3144,7 +3153,7 @@ win_line(
static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */
int cur_checked_col = 0; /* checked column for current line */
#endif
int extra_check = 0; // has syntax or linebreak
int extra_check = 0; // has extra highlighting
#ifdef FEAT_MBYTE
int multi_attr = 0; /* attributes desired by multibyte */
int mb_l = 1; /* multi-byte byte length */
@@ -3784,6 +3793,30 @@ win_line(
}
#endif
#ifdef FEAT_TEXT_PROP
{
char_u *prop_start;
text_prop_count = get_text_props(wp->w_buffer, lnum,
&prop_start, FALSE);
if (text_prop_count > 0)
{
// Make a copy of the properties, so that they are properly
// aligned.
text_props = (textprop_T *)alloc(
text_prop_count * sizeof(textprop_T));
if (text_props != NULL)
mch_memmove(text_props, prop_start,
text_prop_count * sizeof(textprop_T));
// Allocate an array for the indexes.
text_prop_idxs = (int *)alloc(text_prop_count * sizeof(int));
area_highlighting = TRUE;
extra_check = TRUE;
}
}
#endif
off = (unsigned)(current_ScreenLine - ScreenLines);
col = 0;
#ifdef FEAT_RIGHTLEFT
@@ -4283,6 +4316,11 @@ win_line(
else
{
attr_pri = FALSE;
#ifdef FEAT_TEXT_PROP
if (text_prop_type != NULL)
char_attr = text_prop_attr;
else
#endif
#ifdef FEAT_SYN_HL
if (has_syntax)
char_attr = syntax_attr;
@@ -4663,6 +4701,66 @@ win_line(
}
#endif
#ifdef FEAT_TEXT_PROP
if (text_props != NULL)
{
int pi;
// Check if any active property ends.
for (pi = 0; pi < text_props_active; ++pi)
{
int tpi = text_prop_idxs[pi];
if (col >= text_props[tpi].tp_col - 1
+ text_props[tpi].tp_len)
{
if (pi + 1 < text_props_active)
mch_memmove(text_prop_idxs + pi,
text_prop_idxs + pi + 1,
sizeof(int)
* (text_props_active - (pi + 1)));
--text_props_active;
--pi;
}
}
// Add any text property that starts in this column.
while (text_prop_next < text_prop_count
&& col >= text_props[text_prop_next].tp_col - 1)
text_prop_idxs[text_props_active++] = text_prop_next++;
text_prop_type = NULL;
if (text_props_active > 0)
{
int max_priority = INT_MIN;
int max_col = 0;
// Get the property type with the highest priority
// and/or starting last.
for (pi = 0; pi < text_props_active; ++pi)
{
int tpi = text_prop_idxs[pi];
proptype_T *pt;
pt = text_prop_type_by_id(
curwin->w_buffer, text_props[tpi].tp_type);
if (pt != NULL
&& (pt->pt_priority > max_priority
|| (pt->pt_priority == max_priority
&& text_props[tpi].tp_col >= max_col)))
{
text_prop_type = pt;
max_priority = pt->pt_priority;
max_col = text_props[tpi].tp_col;
}
}
if (text_prop_type != NULL)
text_prop_attr =
syn_id2attr(text_prop_type->pt_hl_id);
}
}
#endif
#ifdef FEAT_SPELL
/* Check spelling (unless at the end of the line).
* Only do this when there is no syntax highlighting, the
@@ -6025,6 +6123,10 @@ win_line(
cap_col = 0;
}
#endif
#ifdef FEAT_TEXT_PROP
vim_free(text_props);
vim_free(text_prop_idxs);
#endif
vim_free(p_extra_free);
return row;