]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0375: prop_find() does not find a virt text in starting line v9.2.0375
authorFurkan Sahin <furkan-dev@proton.me>
Mon, 20 Apr 2026 16:12:54 +0000 (16:12 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 20 Apr 2026 16:20:12 +0000 (16:20 +0000)
Problem:  prop_find() does not find a virt text in the starting line
          (@rickhowe, after v9.2.0320)
Solution: Do not skip virtual text properties with tp_col == MAXCOL on
          the starting line (Furkan Sahin)

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
closes: #20019

Signed-off-by: Furkan Sahin <furkan-dev@proton.me>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_textprop.vim
src/textprop.c
src/version.c

index f94acfc97cb82a9af6592c026006b45b23cfa0a6..a57493bc812d1b67b8fa30d7512f19a64d84c35d 100644 (file)
@@ -4907,4 +4907,38 @@ func Test_textprop_materialize_list()
        call assert_equal([], prop_list(1, #{ids: 3->range()}))
 endfunc
 
+func Test_prop_find_floating_vtext()
+  new
+  call setline(1, ['111', '222', '333'])
+  let tn = 'test'
+  call prop_type_add(tn, {'highlight': 'Search'})
+  for ln in range(1, 3)
+    call prop_add(ln, 0, {'type': tn, 'text': '-----', 'text_align': 'above'})
+  endfor
+  " 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
+endfunc
 " vim: shiftwidth=2 sts=2 expandtab
index b4aedf98d7c498ac6ff9254a2d67e990e752a6ff..48cbad4b6a6f9d92a076418afee767bd7971ed88 100644 (file)
@@ -1967,12 +1967,16 @@ f_prop_find(typval_T *argvars, typval_T *rettv)
            // after `col`, depending on the search direction.
            if (lnum == lnum_start)
            {
+               bool is_floating_vtext = prop.tp_id < 0
+                   && prop.tp_col == MAXCOL;
                if (dir == BACKWARD)
                {
-                   if (prop.tp_col > col)
+                   // Virtual text with MAXCOL always matches any column
+                   if (!is_floating_vtext && prop.tp_col > col)
                        continue;
                }
-               else if (prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col)
+               else if (!is_floating_vtext
+                   && prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col)
                    continue;
            }
            if (both ? prop.tp_id == id && prop.tp_type == type_id
index f36742a33adc90e148174bdeab5951c7a7cb2cfd..47ea1bac76df95cf1e181194ad1a81ce73be613f 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    375,
 /**/
     374,
 /**/