aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <janedmundlazo@hotmail.com>2018-06-08 11:18:50 -0400
committerJan Edmund Lazo <janedmundlazo@hotmail.com>2018-06-19 16:57:29 -0400
commit141df73930159682a48f68a89e02f0b5c38ac9e4 (patch)
treed8fcf6103231c9fcc2e88e5791fa0b9729d8508c
parentc1d7a280936470c119035a8e6d5a4350571eb68a (diff)
downloadrneovim-141df73930159682a48f68a89e02f0b5c38ac9e4.tar.gz
rneovim-141df73930159682a48f68a89e02f0b5c38ac9e4.tar.bz2
rneovim-141df73930159682a48f68a89e02f0b5c38ac9e4.zip
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
-rw-r--r--src/nvim/normal.c19
-rw-r--r--src/nvim/testdir/test_goto.vim21
2 files changed, 32 insertions, 8 deletions
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