From: zeertzjq Date: Fri, 3 Apr 2026 08:30:40 +0000 (+0000) Subject: patch 9.2.0285: :syn sync grouphere may go beyond end of line X-Git-Tag: v9.2.0285^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7cffc84340d6c141fb8f7dbe771c4c15dcc47d4;p=thirdparty%2Fvim.git patch 9.2.0285: :syn sync grouphere may go beyond end of line 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 Signed-off-by: Christian Brabandt --- diff --git a/src/syntax.c b/src/syntax.c index ed4c1225f3..c845a1051f 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -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; } diff --git a/src/testdir/test_syntax.vim b/src/testdir/test_syntax.vim index e4d46911d0..27f2efc2ca 100644 --- a/src/testdir/test_syntax.vim +++ b/src/testdir/test_syntax.vim @@ -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="\+ end="\<;\_s*then\>" end="\" + syn sync minlines=20 maxlines=40 + syn sync match shIfSync grouphere shIf "\" + redraw! + + normal! G + " Should not go beyond end of line + redraw! + + bw! +endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index ebb4732943..ce87898c7f 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 285, /**/ 284, /**/