To: vim_dev@googlegroups.com Subject: Patch 8.2.1727 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1727 Problem: A popup created with "cursorline" will ignore "firstline". Solution: When both "cursorline" and "firstline" are present put the cursor on "firstline". (closes #7000) Add the "winid" argument to getcurpos(). Files: runtime/doc/eval.txt, src/evalfunc.c, src/popupwin.c, src/evalwindow.c, src/testdir/test_popupwin.vim, src/testdir/test_functions.vim *** ../vim-8.2.1726/runtime/doc/eval.txt 2020-09-22 20:33:30.433223197 +0200 --- runtime/doc/eval.txt 2020-09-22 21:50:37.116094829 +0200 *************** *** 2502,2508 **** getcmdwintype() String return current command-line window type getcompletion({pat}, {type} [, {filtered}]) List list of cmdline completion matches ! getcurpos() List position of the cursor getcwd([{winnr} [, {tabnr}]]) String get the current working directory getenv({name}) String return environment variable getfontname([{name}]) String name of font being used --- 2516,2522 ---- getcmdwintype() String return current command-line window type getcompletion({pat}, {type} [, {filtered}]) List list of cmdline completion matches ! getcurpos([{winnr}]) List position of the cursor getcwd([{winnr} [, {tabnr}]]) String get the current working directory getenv({name}) String return environment variable getfontname([{name}]) String name of font being used *************** *** 5229,5239 **** GetPattern()->getcompletion('color') < *getcurpos()* ! getcurpos() Get the position of the cursor. This is like getpos('.'), but ! includes an extra item in the list: ! [bufnum, lnum, col, off, curswant] ~ The "curswant" number is the preferred column when moving the cursor vertically. Also see |getpos()|. This can be used to save and restore the cursor position: > let save_cursor = getcurpos() --- 5261,5279 ---- GetPattern()->getcompletion('color') < *getcurpos()* ! getcurpos([{winid}]) ! Get the position of the cursor. This is like getpos('.'), but ! includes an extra "curswant" item in the list: ! [0, lnum, col, off, curswant] ~ The "curswant" number is the preferred column when moving the cursor vertically. Also see |getpos()|. + The first "bufnum" item is always zero. + + The optional {winid} argument can specify the window. It can + be the window number or the |window-ID|. The last known + cursor position is returned, this may be invalid for the + current value of the buffer if it is not the current window. + If {winid} is invalid a list with zeroes is returned. This can be used to save and restore the cursor position: > let save_cursor = getcurpos() *** ../vim-8.2.1726/src/evalfunc.c 2020-09-22 20:33:30.437223175 +0200 --- src/evalfunc.c 2020-09-22 21:46:59.040890477 +0200 *************** *** 646,652 **** {"getcmdtype", 0, 0, 0, ret_string, f_getcmdtype}, {"getcmdwintype", 0, 0, 0, ret_string, f_getcmdwintype}, {"getcompletion", 2, 3, FEARG_1, ret_list_string, f_getcompletion}, ! {"getcurpos", 0, 0, 0, ret_list_number, f_getcurpos}, {"getcwd", 0, 2, FEARG_1, ret_string, f_getcwd}, {"getenv", 1, 1, FEARG_1, ret_string, f_getenv}, {"getfontname", 0, 1, 0, ret_string, f_getfontname}, --- 646,652 ---- {"getcmdtype", 0, 0, 0, ret_string, f_getcmdtype}, {"getcmdwintype", 0, 0, 0, ret_string, f_getcmdwintype}, {"getcompletion", 2, 3, FEARG_1, ret_list_string, f_getcompletion}, ! {"getcurpos", 0, 1, FEARG_1, ret_list_number, f_getcurpos}, {"getcwd", 0, 2, FEARG_1, ret_string, f_getcwd}, {"getenv", 1, 1, FEARG_1, ret_string, f_getenv}, {"getfontname", 0, 1, 0, ret_string, f_getfontname}, *************** *** 3259,3265 **** typval_T *rettv, int getcurpos) { ! pos_T *fp; list_T *l; int fnum = -1; --- 3259,3266 ---- typval_T *rettv, int getcurpos) { ! pos_T *fp = NULL; ! win_T *wp = curwin; list_T *l; int fnum = -1; *************** *** 3267,3273 **** { l = rettv->vval.v_list; if (getcurpos) ! fp = &curwin->w_cursor; else fp = var2fpos(&argvars[0], TRUE, &fnum); if (fnum != -1) --- 3268,3283 ---- { l = rettv->vval.v_list; if (getcurpos) ! { ! 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); if (fnum != -1) *************** *** 3287,3299 **** colnr_T save_curswant = curwin->w_curswant; colnr_T save_virtcol = curwin->w_virtcol; ! update_curswant(); ! list_append_number(l, curwin->w_curswant == MAXCOL ? ! (varnumber_T)MAXCOL : (varnumber_T)curwin->w_curswant + 1); // Do not change "curswant", as it is unexpected that a get // function has a side effect. ! if (save_set_curswant) { curwin->w_set_curswant = save_set_curswant; curwin->w_curswant = save_curswant; --- 3297,3310 ---- colnr_T save_curswant = curwin->w_curswant; colnr_T save_virtcol = curwin->w_virtcol; ! if (wp == curwin) ! update_curswant(); ! 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 (wp == curwin && save_set_curswant) { curwin->w_set_curswant = save_set_curswant; curwin->w_curswant = save_curswant; *** ../vim-8.2.1726/src/popupwin.c 2020-09-08 22:55:22.075652514 +0200 --- src/popupwin.c 2020-09-22 21:53:54.263314983 +0200 *************** *** 593,600 **** ++wp->w_topline; } ! // Don't use "firstline" now. ! wp->w_firstline = 0; } /* --- 593,601 ---- ++wp->w_topline; } ! // Don't let "firstline" cause a scroll. ! if (wp->w_firstline > 0) ! wp->w_firstline = wp->w_topline; } /* *************** *** 948,953 **** --- 949,966 ---- if (nr > 0) wp->w_popup_flags |= POPF_HIDDEN; + // when "firstline" and "cursorline" are both set move the cursor to the + // "firstline". + if (wp->w_firstline > 0 && (wp->w_popup_flags & POPF_CURSORLINE)) + { + if (wp->w_firstline > wp->w_buffer->b_ml.ml_line_count) + wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count; + else + wp->w_cursor.lnum = wp->w_firstline; + wp->w_topline = wp->w_cursor.lnum; + curwin->w_valid &= ~VALID_BOTLINE; + } + popup_mask_refresh = TRUE; popup_highlight_curline(wp); } *** ../vim-8.2.1726/src/evalwindow.c 2020-09-05 21:57:49.492963210 +0200 --- src/evalwindow.c 2020-09-22 21:33:31.300388816 +0200 *************** *** 530,535 **** --- 530,551 ---- return; } } + #ifdef FEAT_PROP_POPUP + if (wparg != NULL) + { + tabnr = 0; + FOR_ALL_TABPAGES(tp) + { + tabnr++; + FOR_ALL_POPUPWINS_IN_TAB(tp, wp) + if (wp == wparg) + break; + } + d = get_win_info(wparg, tp == NULL ? 0 : tabnr, 0); + if (d != NULL) + list_append_dict(rettv->vval.v_list, d); + } + #endif } /* *** ../vim-8.2.1726/src/testdir/test_popupwin.vim 2020-09-08 22:06:12.825040939 +0200 --- src/testdir/test_popupwin.vim 2020-09-22 21:19:21.236593857 +0200 *************** *** 516,521 **** --- 516,534 ---- call popup_close(winid) endfunc + func Test_popup_firstline_cursorline() + let winid = popup_create(['1111', '222222', '33333', '44444'], #{ + \ maxheight: 2, + \ firstline: 3, + \ cursorline: 1, + \ }) + call assert_equal(3, popup_getoptions(winid).firstline) + call assert_equal(3, getwininfo(winid)[0].topline) + call assert_equal(3, getcurpos(winid)[1]) + + call popup_close(winid) + endfunc + func Test_popup_noscrolloff() set scrolloff=5 let winid = popup_create(['xxx']->repeat(50), #{ *** ../vim-8.2.1726/src/testdir/test_functions.vim 2020-09-22 20:33:30.437223175 +0200 --- src/testdir/test_functions.vim 2020-09-22 21:48:32.256560891 +0200 *************** *** 2520,2526 **** --- 2520,2538 ---- call assert_equal('6', @") call assert_equal(-1, setpos('.', test_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 " Test for glob() *** ../vim-8.2.1726/src/version.c 2020-09-22 20:33:30.437223175 +0200 --- src/version.c 2020-09-22 20:52:49.368383997 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1727, /**/ -- This computer is so slow, it takes forever to execute and endless loop! /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///