Skip to content

Commit 2a79ed2

Browse files
committed
patch 8.0.0602: when gF fails to edit the file the cursor still moves
Problem: When gF fails to edit the file the cursor still moves to the found line number. Solution: Check the return value of do_ecmd(). (Michael Hwang)
1 parent 545cb79 commit 2a79ed2

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/normal.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6250,9 +6250,9 @@ nv_gotofile(cmdarg_T *cap)
62506250
if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !P_HID(curbuf))
62516251
(void)autowrite(curbuf, FALSE);
62526252
setpcmark();
6253-
(void)do_ecmd(0, ptr, NULL, NULL, ECMD_LAST,
6254-
P_HID(curbuf) ? ECMD_HIDE : 0, curwin);
6255-
if (cap->nchar == 'F' && lnum >= 0)
6253+
if (do_ecmd(0, ptr, NULL, NULL, ECMD_LAST,
6254+
P_HID(curbuf) ? ECMD_HIDE : 0, curwin) == OK
6255+
&& cap->nchar == 'F' && lnum >= 0)
62566256
{
62576257
curwin->w_cursor.lnum = lnum;
62586258
check_cursor_lnum();

src/testdir/test_gf.vim

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
" This is a test if a URL is recognized by "gf", with the cursor before and
33
" after the "://". Also test ":\\".
4-
function! Test_gf_url()
4+
func Test_gf_url()
55
enew!
66
call append(0, [
77
\ "first test for URL://machine.name/tmp/vimtest2a and other text",
@@ -30,4 +30,25 @@ function! Test_gf_url()
3030

3131
set isf&vim
3232
enew!
33-
endfunction
33+
endfunc
34+
35+
func Test_gF()
36+
new
37+
call setline(1, ['111', '222', '333', '444'])
38+
w! Xfile
39+
close
40+
new
41+
call setline(1, ['one', 'Xfile:3', 'three'])
42+
2
43+
call assert_fails('normal gF', 'E37:')
44+
call assert_equal(2, getcurpos()[1])
45+
w! Xfile2
46+
normal gF
47+
call assert_equal('Xfile', bufname('%'))
48+
call assert_equal(3, getcurpos()[1])
49+
50+
call delete('Xfile')
51+
call delete('Xfile2')
52+
bwipe Xfile
53+
bwipe Xfile2
54+
endfunc

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
602,
767769
/**/
768770
601,
769771
/**/

0 commit comments

Comments
 (0)