patch 8.1.0638: text property highlighting is off by one column
Problem: Text property highlighting is off by one column. (Bjorn Linse)
Solution: Update text property highlighting earlier. Let it overrule syntax
highlighting.
diff --git a/src/screen.c b/src/screen.c
index ed1d4a3..62f0d13 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -4294,6 +4294,66 @@
}
#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
+
/* Decide which of the highlight attributes to use. */
attr_pri = TRUE;
#ifdef LINE_ATTR
@@ -4653,8 +4713,8 @@
#endif
#ifdef FEAT_SYN_HL
- /* Get syntax attribute, unless still at the start of the line
- * (double-wide char that doesn't fit). */
+ // Get syntax attribute, unless still at the start of the line
+ // (double-wide char that doesn't fit).
v = (long)(ptr - line);
if (has_syntax && v > 0)
{
@@ -4686,10 +4746,16 @@
line = ml_get_buf(wp->w_buffer, lnum, FALSE);
ptr = line + v;
- if (!attr_pri)
- char_attr = syntax_attr;
- else
- char_attr = hl_combine_attr(syntax_attr, char_attr);
+# ifdef FEAT_TEXT_PROP
+ // Text properties overrule syntax highlighting.
+ if (text_prop_attr == 0)
+#endif
+ {
+ if (!attr_pri)
+ char_attr = syntax_attr;
+ else
+ char_attr = hl_combine_attr(syntax_attr, char_attr);
+ }
# ifdef FEAT_CONCEAL
/* no concealing past the end of the line, it interferes
* with line highlighting */
@@ -4701,66 +4767,6 @@
}
#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
diff --git a/src/structs.h b/src/structs.h
index 2f2795a..aa59bff 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -705,7 +705,7 @@
*/
typedef struct textprop_S
{
- colnr_T tp_col; // start column
+ colnr_T tp_col; // start column (one based)
colnr_T tp_len; // length in bytes
int tp_id; // identifier
int tp_type; // property type
diff --git a/src/version.c b/src/version.c
index c51a46d..5cffe09 100644
--- a/src/version.c
+++ b/src/version.c
@@ -800,6 +800,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 638,
+/**/
637,
/**/
636,