diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-07-06 19:01:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-06 19:01:44 +0800 |
commit | 9ced05413474a7c8b8a8b2f36a27db29a37dfaf6 (patch) | |
tree | 1fa4d60d0b0d134a2443f10f92265c17215e524a | |
parent | c68f1d7263cd5296e723d8cfee914c72f58138c3 (diff) | |
download | rneovim-9ced05413474a7c8b8a8b2f36a27db29a37dfaf6.tar.gz rneovim-9ced05413474a7c8b8a8b2f36a27db29a37dfaf6.tar.bz2 rneovim-9ced05413474a7c8b8a8b2f36a27db29a37dfaf6.zip |
fix(mark): fix unexpected cursor movements (#19253)
-rw-r--r-- | src/nvim/ex_docmd.c | 7 | ||||
-rw-r--r-- | src/nvim/mark.c | 22 | ||||
-rw-r--r-- | test/functional/editor/mark_spec.lua | 21 |
3 files changed, 32 insertions, 18 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 43d57cb278..18490bd60c 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -4345,13 +4345,12 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int // used by itself: ":'M". MarkGet flag = to_other_file && cmd[1] == NUL ? kMarkAll : kMarkBufLocal; fmark_T *fm = mark_get(curbuf, curwin, NULL, flag, *cmd); - MarkMoveRes move_res = mark_move_to(fm, kMarkBeginLine); cmd++; - // Switched buffer - if (move_res & kMarkSwitchedBuf) { + if (fm != NULL && fm->fnum != curbuf->handle) { + // Jumped to another file. lnum = curwin->w_cursor.lnum; } else { - if (fm == NULL) { + if (!mark_check(fm)) { cmd = NULL; goto error; } diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 0bf5875269..66855c66b5 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -448,27 +448,21 @@ fmark_T *mark_get_local(buf_T *buf, win_T *win, int name) fmark_T *mark_get_motion(buf_T *buf, win_T *win, int name) { fmark_T *mark = NULL; - if (name == '{' || name == '}') { - // to previous/next paragraph + const pos_T pos = curwin->w_cursor; + const bool slcb = listcmd_busy; + listcmd_busy = true; // avoid that '' is changed + if (name == '{' || name == '}') { // to previous/next paragraph oparg_T oa; - bool slcb = listcmd_busy; - listcmd_busy = true; // avoid that '' is changed - - if (findpar(&oa.inclusive, - name == '}' ? FORWARD : BACKWARD, 1L, NUL, false)) { + if (findpar(&oa.inclusive, name == '}' ? FORWARD : BACKWARD, 1L, NUL, false)) { mark = pos_to_mark(buf, NULL, win->w_cursor); } - listcmd_busy = slcb; - // to previous/next sentence - } else if (name == '(' || name == ')') { - bool slcb = listcmd_busy; - listcmd_busy = true; // avoid that '' is changed - + } else if (name == '(' || name == ')') { // to previous/next sentence if (findsent(name == ')' ? FORWARD : BACKWARD, 1L)) { mark = pos_to_mark(buf, NULL, win->w_cursor); } - listcmd_busy = slcb; } + curwin->w_cursor = pos; + listcmd_busy = slcb; return mark; } diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua index 8b469286ec..1eb76aa628 100644 --- a/test/functional/editor/mark_spec.lua +++ b/test/functional/editor/mark_spec.lua @@ -279,6 +279,27 @@ describe('named marks', function() -- should still be folded eq(2, funcs.foldclosed('.')) end) + + it("getting '{ '} '( ') does not move cursor", function() + meths.buf_set_lines(0, 0, 0, true, {'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee'}) + meths.win_set_cursor(0, {2, 0}) + funcs.getpos("'{") + eq({2, 0}, meths.win_get_cursor(0)) + funcs.getpos("'}") + eq({2, 0}, meths.win_get_cursor(0)) + funcs.getpos("'(") + eq({2, 0}, meths.win_get_cursor(0)) + funcs.getpos("')") + eq({2, 0}, meths.win_get_cursor(0)) + end) + + it('in command range does not move cursor #19248', function() + meths.create_user_command('Test', ':', {range = true}) + meths.buf_set_lines(0, 0, 0, true, {'aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee'}) + meths.win_set_cursor(0, {2, 0}) + command([['{,'}Test]]) + eq({2, 0}, meths.win_get_cursor(0)) + end) end) describe('named marks view', function() |