aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/ex_docmd.c1
-rw-r--r--src/nvim/mark.c2
-rw-r--r--test/functional/editor/jump_spec.lua42
-rw-r--r--test/functional/editor/mark_spec.lua15
4 files changed, 58 insertions, 2 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 772e0d0faf..7e750dfcc3 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -3379,6 +3379,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int
fmark_T *fm = mark_get(curbuf, curwin, NULL, flag, *cmd);
cmd++;
if (fm != NULL && fm->fnum != curbuf->handle) {
+ (void)mark_move_to(fm, 0);
// Jumped to another file.
lnum = curwin->w_cursor.lnum;
} else {
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index bf81cdb5ee..19fad179c6 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -520,7 +520,7 @@ static MarkMoveRes switch_to_mark_buf(fmark_T *fm, bool pcmark_on_switch)
if (fm->fnum != curbuf->b_fnum) {
// Switch to another file.
int getfile_flag = pcmark_on_switch ? GETF_SETMARK : 0;
- bool res = buflist_getfile(fm->fnum, (linenr_T)1, getfile_flag, false) == OK;
+ bool res = buflist_getfile(fm->fnum, fm->mark.lnum, getfile_flag, false) == OK;
return res == true ? kMarkSwitchedBuf : kMarkMoveFailed;
}
return 0;
diff --git a/test/functional/editor/jump_spec.lua b/test/functional/editor/jump_spec.lua
index 63f522fe6e..dc056cb252 100644
--- a/test/functional/editor/jump_spec.lua
+++ b/test/functional/editor/jump_spec.lua
@@ -48,6 +48,48 @@ describe('jumplist', function()
feed('<C-O>')
eq(buf1, funcs.bufnr('%'))
end)
+
+ it('<C-O> scrolls cursor halfway when switching buffer #25763', function()
+ write_file(fname1, ('foobar\n'):rep(100))
+ write_file(fname2, 'baz')
+
+ local screen = Screen.new(5, 25)
+ screen:attach()
+ command('set number')
+ command('edit '..fname1)
+ feed('35gg')
+ command('edit '..fname2)
+ feed('<C-O>')
+ screen:expect{grid=[[
+ {1: 24 }foobar |
+ {1: 25 }foobar |
+ {1: 26 }foobar |
+ {1: 27 }foobar |
+ {1: 28 }foobar |
+ {1: 29 }foobar |
+ {1: 30 }foobar |
+ {1: 31 }foobar |
+ {1: 32 }foobar |
+ {1: 33 }foobar |
+ {1: 34 }foobar |
+ {1: 35 }^foobar |
+ {1: 36 }foobar |
+ {1: 37 }foobar |
+ {1: 38 }foobar |
+ {1: 39 }foobar |
+ {1: 40 }foobar |
+ {1: 41 }foobar |
+ {1: 42 }foobar |
+ {1: 43 }foobar |
+ {1: 44 }foobar |
+ {1: 45 }foobar |
+ {1: 46 }foobar |
+ {1: 47 }foobar |
+ |
+ ]], attr_ids={
+ [1] = {foreground = Screen.colors.Brown};
+ }}
+ end)
end)
describe("jumpoptions=stack behaves like 'tagstack'", function()
diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua
index 36485ded7a..e669d7f2bb 100644
--- a/test/functional/editor/mark_spec.lua
+++ b/test/functional/editor/mark_spec.lua
@@ -24,7 +24,6 @@ describe('named marks', function()
os.remove(file2)
end)
-
it("can be set", function()
command("edit " .. file1)
command("mark a")
@@ -147,6 +146,20 @@ describe('named marks', function()
eq({2, 2}, cursor())
end)
+ it("can move to them using :'", function()
+ command("args " .. file1 .. " " .. file2)
+ feed("j")
+ feed("ma")
+ feed("G")
+ command("'a")
+ eq({2, 0}, cursor())
+ feed("mA")
+ command("next")
+ command("'A")
+ eq(1, meths.get_current_buf().id)
+ eq({2, 0}, cursor())
+ end)
+
it("errors when it can't find the buffer", function()
command("args " .. file1 .. " " .. file2)
feed("mA")