[vim/vim] prop_find(): fix virtual text search on first line (PR #20019)

2 views
Skip to first unread message

Furkan Sahin

unread,
Apr 19, 2026, 3:11:25 PM (yesterday) Apr 19
to vim/vim, Subscribed

The column matching logic incorrectly skipped virtual text properties with tp_col == MAXCOL on the starting line. Exclude such properties from the column range check so they are always found.

Fixes #20013.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/20019

Commit Summary

  • 12e5c11 prop_find(): fix virtual text search on first line

File Changes

(2 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/20019@github.com>

h_east

unread,
Apr 19, 2026, 3:52:38 PM (yesterday) Apr 19
to vim/vim, Subscribed

@h-east commented on this pull request.

Thanks for the patch.


In src/textprop.c:

>  		if (dir == BACKWARD)
 		{
-		    if (prop.tp_col > col)
+		    // Virtual text with MAXCOL always matches any column
+		    if (!(prop.tp_id < 0 && prop.tp_col == MAXCOL) && prop.tp_col > col)
 			continue;
 		}
-		else if (prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col)
+		else if (!(prop.tp_id < 0 && prop.tp_col == MAXCOL) &&
+			 prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col)
 		    continue;

!(prop.tp_id < 0 && prop.tp_col == MAXCOL) appears in both the backward and
forward branches. Extracting it into a local bool improves readability:

		// Floating virtual text (above/below/right) uses MAXCOL and
		// should not be filtered out by the column range check on the
		// starting line.
		bool is_floating_vtext = prop.tp_id < 0
					    && prop.tp_col == MAXCOL;

		if (dir == BACKWARD)
		{
		    if (!is_floating_vtext && prop.tp_col > col)
			continue;
		}
		else if (!is_floating_vtext
			&& prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col)
		    continue;

In src/testdir/test_textprop.vim:

> +  let found = prop_find({'type': tn, 'lnum': 1, 'col': 1})
+  call assert_equal(1, found.lnum)
+  call assert_equal('-----', found.text)
+  bwipe!
+  call prop_type_delete(tn)

The added test Test_prop_find_floating_vtext only checks
prop_find({lnum:1, col:1}) (forward). The same regression also affected the
backward direction, so please add a backward case as well:

Also, text_align: 'below' and 'right' are likewise tp_col == MAXCOL.
Covering at least one of them in the test would make the regression-prevention
stronger.

⬇️ Suggested change
-  let found = prop_find({'type': tn, 'lnum': 1, 'col': 1})
-  call assert_equal(1, found.lnum)
-  call assert_equal('-----', found.text)
-  bwipe!
-  call prop_type_delete(tn)
+  " forward search must find the virtual text on the starting line
+  let found = prop_find({'type': tn, 'lnum': 1, 'col': 1})
+  call assert_equal(1, found.lnum)
+  call assert_equal('-----', found.text)
+  " backward search must also find the virtual text on the starting line
+  let found = prop_find({'type': tn, 'lnum': 1, 'col': 1}, 'b')
+  call assert_equal(1, found.lnum)
+  call assert_equal('-----', found.text)
+  bwipe!
+  call prop_type_delete(tn)
+
+  " Also cover 'below' and 'right' aligned virtual text (also tp_col==MAXCOL)
+  for align in ['below', 'right']
+    new
+    call setline(1, ['aaa', 'bbb'])
+    call prop_type_add(tn, {'highlight': 'Search'})
+    call prop_add(1, 0, {'type': tn, 'text': 'VT', 'text_align': align})
+    let found = prop_find({'type': tn, 'lnum': 1, 'col': 1})
+    call assert_equal(1, found.lnum, 'forward, align=' .. align)
+    call assert_equal('VT', found.text, 'forward, align=' .. align)
+    let found = prop_find({'type': tn, 'lnum': 1, 'col': 1}, 'b')
+    call assert_equal(1, found.lnum, 'backward, align=' .. align)
+    call assert_equal('VT', found.text, 'backward, align=' .. align)
+    bwipe!
+    call prop_type_delete(tn)
+  endfor


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/20019/review/4136453440@github.com>

Furkan Sahin

unread,
Apr 19, 2026, 5:20:34 PM (yesterday) Apr 19
to vim/vim, Subscribed

@sahinf commented on this pull request.


In src/textprop.c:

>  		if (dir == BACKWARD)
 		{
-		    if (prop.tp_col > col)
+		    // Virtual text with MAXCOL always matches any column
+		    if (!(prop.tp_id < 0 && prop.tp_col == MAXCOL) && prop.tp_col > col)
 			continue;
 		}
-		else if (prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col)
+		else if (!(prop.tp_id < 0 && prop.tp_col == MAXCOL) &&
+			 prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col)
 		    continue;

Thanks


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/20019/review/4136573157@github.com>

Furkan Sahin

unread,
Apr 19, 2026, 5:21:15 PM (yesterday) Apr 19
to vim/vim, Push

@sahinf pushed 1 commit.

  • 4894893 prop_find(): fix virtual text search on first line


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/20019/before/12e5c11c55751d8b62ff714cdd44e84f51f27da0/after/4894893b1fff545c0ed1de956e34e571859d5f17@github.com>

Christian Brabandt

unread,
12:12 PM (6 hours ago) 12:12 PM
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#20019)

thanks


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/20019/c4282440275@github.com>

Christian Brabandt

unread,
12:21 PM (6 hours ago) 12:21 PM
to vim/vim, Subscribed

Closed #20019 via c9d4c1d.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/20019/issue_event/24685641770@github.com>

Reply all
Reply to author
Forward
0 new messages