diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-02-06 04:46:16 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-02-06 04:46:16 +0800 |
commit | 8ba9f19961d8573dc851d3d5f2ec217ad2fb7b28 (patch) | |
tree | dcade506fff3749f5561d947067e730ca66cf126 /src | |
parent | 92e92f02e7106fcad1597bb8f0edf1e43186a07f (diff) | |
download | rneovim-8ba9f19961d8573dc851d3d5f2ec217ad2fb7b28.tar.gz rneovim-8ba9f19961d8573dc851d3d5f2ec217ad2fb7b28.tar.bz2 rneovim-8ba9f19961d8573dc851d3d5f2ec217ad2fb7b28.zip |
vim-patch:8.2.1727: a popup created with "cursorline" will ignore "firstline"
Problem: A popup created with "cursorline" will ignore "firstline".
Solution: When both "cursorline" and "firstline" are present put the cursor
on "firstline". (closes vim/vim#7000) Add the "winid" argument to
getcurpos().
https://github.com/vim/vim/commit/99ca9c4868bb1669706b9e3de9a9218bd11cc459
Skip popup window related code.
Cherry-pick all of Test_getcurpos_setpos() from patch 8.2.0610.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.lua | 2 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 30 | ||||
-rw-r--r-- | src/nvim/testdir/test_functions.vim | 27 |
3 files changed, 47 insertions, 12 deletions
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index ef2b8a0cc0..8590614a0a 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -151,7 +151,7 @@ return { getcmdtype={}, getcmdwintype={}, getcompletion={args={2, 3}, base=1}, - getcurpos={}, + getcurpos={args={0, 1}, base=1}, getcwd={args={0, 2}, base=1}, getenv={args=1, base=1}, getfontname={args={0, 1}}, diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index b96ff50787..eb9c08c8f0 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -3845,37 +3845,45 @@ static void f_getpid(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void getpos_both(typval_T *argvars, typval_T *rettv, bool getcurpos) { - pos_T *fp; + pos_T *fp = NULL; + win_T *wp = curwin; int fnum = -1; if (getcurpos) { - fp = &curwin->w_cursor; + if (argvars[0].v_type != VAR_UNKNOWN) { + wp = find_win_by_nr_or_id(&argvars[0]); + if (wp != NULL) { + fp = &wp->w_cursor; + } + } else { + fp = &curwin->w_cursor; + } } else { fp = var2fpos(&argvars[0], true, &fnum); } list_T *const l = tv_list_alloc_ret(rettv, 4 + (!!getcurpos)); tv_list_append_number(l, (fnum != -1) ? (varnumber_T)fnum : (varnumber_T)0); + tv_list_append_number(l, ((fp != NULL) ? (varnumber_T)fp->lnum : (varnumber_T)0)); tv_list_append_number(l, ((fp != NULL) - ? (varnumber_T)fp->lnum + ? (varnumber_T)(fp->col == MAXCOL ? MAXCOL : fp->col + 1) : (varnumber_T)0)); - tv_list_append_number(l, ((fp != NULL) - ? (varnumber_T)(fp->col == MAXCOL ? MAXCOL : fp->col + 1) - : (varnumber_T)0)); tv_list_append_number(l, (fp != NULL) ? (varnumber_T)fp->coladd : (varnumber_T)0); if (getcurpos) { const int save_set_curswant = curwin->w_set_curswant; const colnr_T save_curswant = curwin->w_curswant; const colnr_T save_virtcol = curwin->w_virtcol; - update_curswant(); - tv_list_append_number(l, (curwin->w_curswant == MAXCOL - ? (varnumber_T)MAXCOL - : (varnumber_T)curwin->w_curswant + 1)); + if (wp == curwin) { + update_curswant(); + } + tv_list_append_number(l, (wp == NULL) ? 0 : (wp->w_curswant == MAXCOL) + ? (varnumber_T)MAXCOL + : (varnumber_T)wp->w_curswant + 1); // Do not change "curswant", as it is unexpected that a get // function has a side effect. - if (save_set_curswant) { + if (wp == curwin && save_set_curswant) { curwin->w_set_curswant = save_set_curswant; curwin->w_curswant = save_curswant; curwin->w_virtcol = save_virtcol; diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 42facdd491..6c2b0b97b6 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1712,6 +1712,33 @@ func Test_nr2char() call assert_equal("\x80\xfc\b\xfd\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX", eval('"\<M-' .. nr2char(0x40000000) .. '>"')) endfunc +" Test for getcurpos() and setpos() +func Test_getcurpos_setpos() + new + call setline(1, ['012345678', '012345678']) + normal gg6l + let sp = getcurpos() + normal 0 + call setpos('.', sp) + normal jyl + call assert_equal('6', @") + call assert_equal(-1, setpos('.', v:_null_list)) + call assert_equal(-1, setpos('.', {})) + + let winid = win_getid() + normal G$ + let pos = getcurpos() + wincmd w + call assert_equal(pos, getcurpos(winid)) + + wincmd w + close! + + call assert_equal(getcurpos(), getcurpos(0)) + call assert_equal([0, 0, 0, 0, 0], getcurpos(-1)) + call assert_equal([0, 0, 0, 0, 0], getcurpos(1999)) +endfunc + func HasDefault(msg = 'msg') return a:msg endfunc |