fix(mark): fix unexpected cursor movements (#19253)

This commit is contained in:
zeertzjq
2022-07-06 19:01:44 +08:00
committed by GitHub
parent c68f1d7263
commit 9ced054134
3 changed files with 32 additions and 18 deletions

View File

@@ -4345,13 +4345,12 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, int
// used by itself: ":'M". // used by itself: ":'M".
MarkGet flag = to_other_file && cmd[1] == NUL ? kMarkAll : kMarkBufLocal; MarkGet flag = to_other_file && cmd[1] == NUL ? kMarkAll : kMarkBufLocal;
fmark_T *fm = mark_get(curbuf, curwin, NULL, flag, *cmd); fmark_T *fm = mark_get(curbuf, curwin, NULL, flag, *cmd);
MarkMoveRes move_res = mark_move_to(fm, kMarkBeginLine);
cmd++; cmd++;
// Switched buffer if (fm != NULL && fm->fnum != curbuf->handle) {
if (move_res & kMarkSwitchedBuf) { // Jumped to another file.
lnum = curwin->w_cursor.lnum; lnum = curwin->w_cursor.lnum;
} else { } else {
if (fm == NULL) { if (!mark_check(fm)) {
cmd = NULL; cmd = NULL;
goto error; goto error;
} }

View File

@@ -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_get_motion(buf_T *buf, win_T *win, int name)
{ {
fmark_T *mark = NULL; fmark_T *mark = NULL;
if (name == '{' || name == '}') { const pos_T pos = curwin->w_cursor;
// to previous/next paragraph const bool slcb = listcmd_busy;
listcmd_busy = true; // avoid that '' is changed
if (name == '{' || name == '}') { // to previous/next paragraph
oparg_T oa; oparg_T oa;
bool slcb = listcmd_busy; if (findpar(&oa.inclusive, name == '}' ? FORWARD : BACKWARD, 1L, NUL, false)) {
listcmd_busy = true; // avoid that '' is changed
if (findpar(&oa.inclusive,
name == '}' ? FORWARD : BACKWARD, 1L, NUL, false)) {
mark = pos_to_mark(buf, NULL, win->w_cursor); mark = pos_to_mark(buf, NULL, win->w_cursor);
} }
listcmd_busy = slcb; } else if (name == '(' || name == ')') { // to previous/next sentence
// to previous/next sentence
} else if (name == '(' || name == ')') {
bool slcb = listcmd_busy;
listcmd_busy = true; // avoid that '' is changed
if (findsent(name == ')' ? FORWARD : BACKWARD, 1L)) { if (findsent(name == ')' ? FORWARD : BACKWARD, 1L)) {
mark = pos_to_mark(buf, NULL, win->w_cursor); mark = pos_to_mark(buf, NULL, win->w_cursor);
} }
listcmd_busy = slcb;
} }
curwin->w_cursor = pos;
listcmd_busy = slcb;
return mark; return mark;
} }

View File

@@ -279,6 +279,27 @@ describe('named marks', function()
-- should still be folded -- should still be folded
eq(2, funcs.foldclosed('.')) eq(2, funcs.foldclosed('.'))
end) 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) end)
describe('named marks view', function() describe('named marks view', function()