Skip to content

Commit b7cffc8

Browse files
zeertzjqchrisbra
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 880cf88 commit b7cffc8

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/syntax.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ syn_sync(
595595
int found_flags = 0;
596596
int found_match_idx = 0;
597597
linenr_T found_current_lnum = 0;
598-
int found_current_col= 0;
598+
int found_current_col = 0;
599599
lpos_T found_m_endpos;
600600
colnr_T prev_current_col;
601601

@@ -817,6 +817,8 @@ syn_sync(
817817
*/
818818
if (found_flags & HL_SYNC_HERE)
819819
{
820+
current_lnum = found_m_endpos.lnum;
821+
current_col = found_m_endpos.col;
820822
if (current_state.ga_len)
821823
{
822824
cur_si = &CUR_STATE(current_state.ga_len - 1);
@@ -825,8 +827,6 @@ syn_sync(
825827
update_si_end(cur_si, (int)current_col, TRUE);
826828
check_keepend();
827829
}
828-
current_col = found_m_endpos.col;
829-
current_lnum = found_m_endpos.lnum;
830830
(void)syn_finish_line(FALSE);
831831
++current_lnum;
832832
}

src/testdir/test_syntax.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,5 +988,30 @@ func Test_WinEnter_synstack_synID()
988988
bw!
989989
endfunc
990990

991+
" This was going beyond the end of the "foo" line
992+
func Test_syn_sync_grouphere_shorter_next_line()
993+
let lines =<< trim END
994+
if [[ "$var1" == 1 ]]; then
995+
foo
996+
else
997+
bar
998+
fi
999+
END
1000+
let lines = ['a']->repeat(50) + lines + ['a']->repeat(28 + winheight(0))
1001+
1002+
new
1003+
call setline(1, lines)
1004+
syn region shIf transparent
1005+
\ start="\<if\_s" skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>"
1006+
syn sync minlines=20 maxlines=40
1007+
syn sync match shIfSync grouphere shIf "\<if\>"
1008+
redraw!
1009+
1010+
normal! G
1011+
" Should not go beyond end of line
1012+
redraw!
1013+
1014+
bw!
1015+
endfunc
9911016

9921017
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
285,
737739
/**/
738740
284,
739741
/**/

0 commit comments

Comments
 (0)