]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.1.0665: text property display wrong when 'spell' is set v8.1.0665
authorBram Moolenaar <Bram@vim.org>
Mon, 31 Dec 2018 12:57:36 +0000 (13:57 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 31 Dec 2018 12:57:36 +0000 (13:57 +0100)
Problem:    Text property display wrong when 'spell' is set. (Dominique Pelle)
Solution:   Remove unnecessary assignment to char_attr.  Combine attributes if
            needed.  Add a screenshot test.

src/screen.c
src/testdir/dumps/Test_textprop_01.dump [new file with mode: 0644]
src/testdir/test_textprop.vim
src/version.c

index 4166928fe084508b62bea364eeb19c80ada6dbb3..322efceedba347e9aeeb9412320814c1358a204b 100644 (file)
@@ -3051,6 +3051,38 @@ fill_foldcolumn(
 }
 #endif /* FEAT_FOLDING */
 
+#ifdef FEAT_TEXT_PROP
+static textprop_T      *current_text_props = NULL;
+static buf_T           *current_buf = NULL;
+
+    static int
+#ifdef __BORLANDC__
+_RTLENTRYF
+#endif
+text_prop_compare(const void *s1, const void *s2)
+{
+    int  idx1, idx2;
+    proptype_T  *pt1, *pt2;
+    colnr_T col1, col2;
+
+    idx1 = *(int *)s1;
+    idx2 = *(int *)s2;
+    pt1 = text_prop_type_by_id(current_buf, current_text_props[idx1].tp_type);
+    pt2 = text_prop_type_by_id(current_buf, current_text_props[idx2].tp_type);
+    if (pt1 == pt2)
+       return 0;
+    if (pt1 == NULL)
+       return -1;
+    if (pt2 == NULL)
+       return 1;
+    if (pt1->pt_priority != pt2->pt_priority)
+       return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
+    col1 = current_text_props[idx1].tp_col;
+    col2 = current_text_props[idx2].tp_col;
+    return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
+}
+#endif
+
 /*
  * Display line "lnum" of window 'wp' on the screen.
  * Start at row "startrow", stop when "endrow" is reached.
@@ -4322,34 +4354,32 @@ win_line(
                           && vcol >= text_props[text_prop_next].tp_col - 1)
                    text_prop_idxs[text_props_active++] = text_prop_next++;
 
-               text_prop_type = NULL;
+               text_prop_attr = 0;
                if (text_props_active > 0)
                {
-                   int max_priority = INT_MIN;
-                   int max_col = 0;
+                   // Sort the properties on priority and/or starting last.
+                   // Then combine the attributes, highest priority last.
+                   current_text_props = text_props;
+                   current_buf = wp->w_buffer;
+                   qsort((void *)text_prop_idxs, (size_t)text_props_active,
+                                              sizeof(int), text_prop_compare);
 
-                   // 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)))
+                       int         tpi = text_prop_idxs[pi];
+                       proptype_T  *pt = text_prop_type_by_id(wp->w_buffer, text_props[tpi].tp_type);
+
+                       if (pt != NULL)
                        {
+                           int pt_attr = syn_id2attr(pt->pt_hl_id);
+
                            text_prop_type = pt;
-                           max_priority = pt->pt_priority;
-                           max_col = text_props[tpi].tp_col;
+                           if (text_prop_attr == 0)
+                               text_prop_attr = pt_attr;
+                           else
+                               text_prop_attr = hl_combine_attr(text_prop_attr, pt_attr);
                        }
                    }
-                   if (text_prop_type != NULL)
-                       text_prop_attr =
-                                    syn_id2attr(text_prop_type->pt_hl_id);
                }
            }
 #endif
@@ -4775,10 +4805,6 @@ win_line(
                if (has_spell && v >= word_end && v > cur_checked_col)
                {
                    spell_attr = 0;
-# ifdef FEAT_SYN_HL
-                   if (!attr_pri)
-                       char_attr = syntax_attr;
-# endif
                    if (c != 0 && (
 # ifdef FEAT_SYN_HL
                                !has_syntax ||
diff --git a/src/testdir/dumps/Test_textprop_01.dump b/src/testdir/dumps/Test_textprop_01.dump
new file mode 100644 (file)
index 0000000..ae80e53
--- /dev/null
@@ -0,0 +1,20 @@
+| +0#af5f00255#ffffff0@1|1| >O+0#0000000&|n|e| +0&#ffff4012|t|w|o| +0&#ffffff0@63
+| +0#af5f00255&@1|2| |N+0#0000000#ffff4012|u|m|b|e|r| |1+0#4040ff13#ffffff0|2|3| +0#0000000#ffff4012|a|n|d| |t|h|e|n| |4+0#4040ff13#ffffff0|5|6|7|.+0#0000000#ffff4012| +0&#ffffff0@45
+| +0#af5f00255&@1|3| |T+0#0000000#ffff4012|h|r|e+0&#ffffff0@1| @65
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|1|,|1| @10|A|l@1| 
index 44e54bb9addea213474b8118272410202b2e2a45..e938a58bc46f969eab5635e3702fb4c328a15a0a 100644 (file)
@@ -5,6 +5,8 @@ if !has('textprop')
   finish
 endif
 
+source screendump.vim
+
 func Test_proptype_global()
   call prop_type_add('comment', {'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1})
   let proptypes = prop_type_list()
@@ -283,5 +285,27 @@ func Test_prop_byteoff()
   call prop_type_delete('comment')
 endfunc
 
-
-" TODO: screenshot test with highlighting
+" screenshot test with textprop highlighting
+funct Test_textprop_screenshots()
+  if !CanRunVimInTerminal()
+    return
+  endif
+  call writefile([
+       \ "call setline(1, ['One two', 'Number 123 and then 4567.', 'Three'])",
+       \ "hi NumberProp ctermfg=blue",
+       \ "hi LongProp ctermbg=yellow",
+       \ "call prop_type_add('number', {'highlight': 'NumberProp'})",
+       \ "call prop_type_add('long', {'highlight': 'LongProp'})",
+       \ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})",
+       \ "call prop_add(2, 8, {'length': 3, 'type': 'number'})",
+       \ "call prop_add(2, 21, {'length': 4, 'type': 'number'})",
+       \ "set number",
+       \ "set spell",
+       \], 'XtestProp')
+  let buf = RunVimInTerminal('-S XtestProp', {})
+  call VerifyScreenDump(buf, 'Test_textprop_01', {})
+
+  " clean up
+  call StopVimInTerminal(buf)
+  call delete('Xtest_folds_with_rnu')
+endfunc
index b976ba522155e9f3dcbeeb04a02b1557cb057ce1..ce53f2e4e0ebf6a0bf5241ebfc0cd151800ad583 100644 (file)
@@ -799,6 +799,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    665,
 /**/
     664,
 /**/