From d7ef77d175e96730c2cb22f2fb86d26cd8d13e35 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 3 Apr 2026 17:22:26 +0800 Subject: [PATCH] vim-patch:9.2.0285: :syn sync grouphere may go beyond end of line (#38727) 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: vim/vim#19896 https://github.com/vim/vim/commit/b7cffc84340d6c141fb8f7dbe771c4c15dcc47d4 --- src/nvim/syntax.c | 4 ++-- test/old/testdir/test_syntax.vim | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 02f18cf7ad..2b4dd931b7 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -679,6 +679,8 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) // the next line. // For "groupthere" the parsing starts at start_lnum. if (found_flags & HL_SYNC_HERE) { + current_lnum = found_m_endpos.lnum; + current_col = found_m_endpos.col; if (!GA_EMPTY(¤t_state)) { cur_si = &CUR_STATE(current_state.ga_len - 1); cur_si->si_h_startpos.lnum = found_current_lnum; @@ -686,8 +688,6 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) update_si_end(cur_si, (int)current_col, true); check_keepend(); } - current_col = found_m_endpos.col; - current_lnum = found_m_endpos.lnum; syn_finish_line(false); current_lnum++; } else { diff --git a/test/old/testdir/test_syntax.vim b/test/old/testdir/test_syntax.vim index 45be057c89..36d7dc61c3 100644 --- a/test/old/testdir/test_syntax.vim +++ b/test/old/testdir/test_syntax.vim @@ -985,5 +985,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