summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-08-10 16:00:33 +0100
committerBram Moolenaar <Bram@vim.org>2022-08-10 16:00:33 +0100
commit952c9b02f8a7c2386b66ed643eef0acd35e842ae (patch)
treecf97f4f161b97b1f524c4a36fa6109c38cbd9b83
parent1d8844aa59416dd306912b5563b8e928dfd387ba (diff)
patch 9.0.0185: virtual text does not show if text prop at same positionv9.0.0185
Problem: Virtual text does not show if tehre is a text prop at same position. (Ben Jackson) Solution: Fix the sorting of properties. (closes #10879)
-rw-r--r--src/drawline.c37
-rw-r--r--src/testdir/dumps/Test_prop_at_same_pos.dump5
-rw-r--r--src/testdir/test_textprop.vim27
-rw-r--r--src/version.c2
4 files changed, 61 insertions, 10 deletions
diff --git a/src/drawline.c b/src/drawline.c
index 5d9dcc37e2..2b47648308 100644
--- a/src/drawline.c
+++ b/src/drawline.c
@@ -281,6 +281,11 @@ get_sign_display_info(
static textprop_T *current_text_props = NULL;
static buf_T *current_buf = NULL;
+/*
+ * Function passed to qsort() to sort text properties.
+ * Return 1 if "s1" has priority over "s2", -1 if the other way around, zero if
+ * both have the same priority.
+ */
static int
text_prop_compare(const void *s1, const void *s2)
{
@@ -300,7 +305,8 @@ text_prop_compare(const void *s1, const void *s2)
int flags1 = 0;
int flags2 = 0;
- // order on 0: after, 1: right, 2: below
+ // both props add text are after the line, order on 0: after (default),
+ // 1: right, 2: below (comes last)
if (tp1->tp_flags & TP_FLAG_ALIGN_RIGHT)
flags1 = 1;
if (tp1->tp_flags & TP_FLAG_ALIGN_BELOW)
@@ -312,17 +318,28 @@ text_prop_compare(const void *s1, const void *s2)
if (flags1 != flags2)
return flags1 < flags2 ? 1 : -1;
}
+
+ // property that inserts text has priority over one that doesn't
+ if ((tp1->tp_id < 0) != (tp2->tp_id < 0))
+ return tp1->tp_id < 0 ? 1 : -1;
+
+ // check highest priority, defined by the type
pt1 = text_prop_type_by_id(current_buf, tp1->tp_type);
pt2 = text_prop_type_by_id(current_buf, tp2->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;
- return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
+ if (pt1 != pt2)
+ {
+ 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;
+ }
+
+ // same priority, one that starts first wins
+ if (col1 != col2)
+ return col1 < col2 ? 1 : -1;
+ return 0;
}
#endif
diff --git a/src/testdir/dumps/Test_prop_at_same_pos.dump b/src/testdir/dumps/Test_prop_at_same_pos.dump
new file mode 100644
index 0000000000..95f01faffe
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_at_same_pos.dump
@@ -0,0 +1,5 @@
+>f+0&#ffffff0|u|n|c|t|i|o|n|(| |o+0#ffffff16#ff404010|n|e|:| |c+0#0000000#ffff4012|a|l@1|,+0&#ffffff0| |t+0#00e0e07&|w|o|:| |a+0#0000000#ffff4012|r|g|u|m|e|n|t|,+0&#ffffff0| |t+0&#ffd7ff255|h|r|e@1|:| |h+0&#ffff4012|e|r|e| +0&#ffffff0|)| @25
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|1|,|1| @10|A|l@1|
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index 8533af3cd2..29cd599682 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -1334,6 +1334,33 @@ func Test_textprop_nowrap_scrolled()
call delete('XtestNowrap')
endfunc
+func Test_textprop_text_priority()
+ CheckScreendump
+
+ let lines =<< trim END
+ call setline(1, "function( call, argument, here )")
+
+ call prop_type_add('one', #{highlight: 'Error'})
+ call prop_type_add('two', #{highlight: 'Function'})
+ call prop_type_add('three', #{highlight: 'DiffChange'})
+ call prop_type_add('arg', #{highlight: 'Search'})
+
+ call prop_add(1, 27, #{type: 'arg', length: len('here')})
+ call prop_add(1, 27, #{type: 'three', text: 'three: '})
+ call prop_add(1, 11, #{type: 'one', text: 'one: '})
+ call prop_add(1, 11, #{type: 'arg', length: len('call')})
+ call prop_add(1, 17, #{type: 'two', text: 'two: '})
+ call prop_add(1, 17, #{type: 'arg', length: len('argument')})
+ END
+ call writefile(lines, 'XtestPropPrio')
+ let buf = RunVimInTerminal('-S XtestPropPrio', {'rows': 5})
+ call VerifyScreenDump(buf, 'Test_prop_at_same_pos', {})
+
+ " clean up
+ call StopVimInTerminal(buf)
+ call delete('XtestPropPrio')
+endfunc
+
func Test_textprop_with_syntax()
CheckScreendump
diff --git a/src/version.c b/src/version.c
index 27503b5951..eb9566cc23 100644
--- a/src/version.c
+++ b/src/version.c
@@ -736,6 +736,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 185,
+/**/
184,
/**/
183,