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.
https://github.com/vim/vim/pull/20019
(2 files)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@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.
- 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.![]()
@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.![]()
@sahinf pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
thanks
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()