From 141df73930159682a48f68a89e02f0b5c38ac9e4 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 8 Jun 2018 11:18:50 -0400 Subject: vim-patch:8.0.0568: 1gd may hang Problem: "1gd" may hang. Solution: Don't get stuck in one position. (Christian Brabandt, closes vim/vim#1643) https://github.com/vim/vim/commit/60402d68da09997cacdeec71fd22c9344f8f40d5 --- src/nvim/normal.c | 19 +++++++++++-------- src/nvim/testdir/test_goto.vim | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index b959ea08f3..a649777ddd 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3769,14 +3769,17 @@ find_decl ( t = false; /* match after start is failure too */ if (thisblock && t != false) { - pos_T *pos; - - /* Check that the block the match is in doesn't end before the - * position where we started the search from. */ - if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, - (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL - && pos->lnum < old_pos.lnum) + const int64_t maxtravel = old_pos.lnum - curwin->w_cursor.lnum + 1; + const pos_T *pos = findmatchlimit(NULL, '}', FM_FORWARD, maxtravel); + + // Check that the block the match is in doesn't end before the + // position where we started the search from. + if (pos != NULL && pos->lnum < old_pos.lnum) { + // There can't be a useful match before the end of this block. + // Skip to the end + curwin->w_cursor = *pos; continue; + } } if (t == false) { @@ -6895,7 +6898,7 @@ static void nv_g_cmd(cmdarg_T *cap) else show_utf8(); break; - + // "g<": show scrollback text case '<': show_sb_text(); break; diff --git a/src/nvim/testdir/test_goto.vim b/src/nvim/testdir/test_goto.vim index 2573401707..ea67fe7386 100644 --- a/src/nvim/testdir/test_goto.vim +++ b/src/nvim/testdir/test_goto.vim @@ -288,3 +288,24 @@ func Test_cursorline_keep_col() set nocursorline endfunc +func Test_gd_local_block() + let lines = [ + \ ' int main()', + \ '{', + \ ' char *a = "NOT NULL";', + \ ' if(a)', + \ ' {', + \ ' char *b = a;', + \ ' printf("%s\n", b);', + \ ' }', + \ ' else', + \ ' {', + \ ' char *b = "NULL";', + \ ' return b;', + \ ' }', + \ '', + \ ' return 0;', + \ '}', + \ ] + call XTest_goto_decl('1gd', lines, 11, 11) +endfunc -- cgit