]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0285: :syn sync grouphere may go beyond end of line v9.2.0285
authorzeertzjq <zeertzjq@outlook.com>
Fri, 3 Apr 2026 08:30:40 +0000 (08:30 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 3 Apr 2026 08:30:40 +0000 (08:30 +0000)
Problem:  :syn sync grouphere may go beyond end of line.
Solution: Start searching for the end of region at the end of match
          instead of a possibly invalid position (zeertzjq).

closes: #19896

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/syntax.c
src/testdir/test_syntax.vim
src/version.c

index ed4c1225f3baad6c97ad49690867f39c9515de08..c845a1051f1d942d0b62226625c94a8a8f99031a 100644 (file)
@@ -595,7 +595,7 @@ syn_sync(
     int                found_flags = 0;
     int                found_match_idx = 0;
     linenr_T   found_current_lnum = 0;
-    int                found_current_col= 0;
+    int                found_current_col = 0;
     lpos_T     found_m_endpos;
     colnr_T    prev_current_col;
 
@@ -817,6 +817,8 @@ syn_sync(
                 */
                if (found_flags & HL_SYNC_HERE)
                {
+                   current_lnum = found_m_endpos.lnum;
+                   current_col = found_m_endpos.col;
                    if (current_state.ga_len)
                    {
                        cur_si = &CUR_STATE(current_state.ga_len - 1);
@@ -825,8 +827,6 @@ syn_sync(
                        update_si_end(cur_si, (int)current_col, TRUE);
                        check_keepend();
                    }
-                   current_col = found_m_endpos.col;
-                   current_lnum = found_m_endpos.lnum;
                    (void)syn_finish_line(FALSE);
                    ++current_lnum;
                }
index e4d46911d09b3aeb02f2c402b79e8631e3dd4e4c..27f2efc2ca025bac2c28092f2ca9ed38220666f0 100644 (file)
@@ -988,5 +988,30 @@ func Test_WinEnter_synstack_synID()
   bw!
 endfunc
 
+" This was going beyond the end of the "foo" line
+func Test_syn_sync_grouphere_shorter_next_line()
+  let lines =<< trim END
+    if [[ "$var1" == 1 ]]; then
+      foo
+    else
+      bar
+    fi
+  END
+  let lines = ['a']->repeat(50) + lines + ['a']->repeat(28 + winheight(0))
+
+  new
+  call setline(1, lines)
+  syn region shIf transparent
+        \ start="\<if\_s" skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>"
+  syn sync minlines=20 maxlines=40
+  syn sync match shIfSync grouphere shIf "\<if\>"
+  redraw!
+
+  normal! G
+  " Should not go beyond end of line
+  redraw!
+
+  bw!
+endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index ebb4732943e9d658da1a4ba1e68314d8b9ae4800..ce87898c7f4b79b9607d10f50fdbcf682f368eed 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    285,
 /**/
     284,
 /**/