To: vim_dev@googlegroups.com Subject: Patch 8.2.1750 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1750 Problem: Setting firstline with popup_setoptions() fails if cursorline is set. Solution: Use apply_options(). Update the popup before applying "zz". (closes #7010) Files: src/popupwin.c, src/proto/popupwin.pro, src/move.c, src/testdir/test_popupwin.vim, src/testdir/dumps/Test_popupwin_win_execute_cursorline.dump, src/testdir/dumps/Test_popupwin_set_firstline_1.dump, src/testdir/dumps/Test_popupwin_set_firstline_2.dump *** ../vim-8.2.1749/src/popupwin.c 2020-09-24 22:57:10.713447710 +0200 --- src/popupwin.c 2020-09-26 21:51:09.161401221 +0200 *************** *** 579,585 **** if (wp->w_cursor.lnum < wp->w_topline) wp->w_topline = wp->w_cursor.lnum; else if (wp->w_cursor.lnum >= wp->w_botline ! && (curwin->w_valid & VALID_BOTLINE)) { wp->w_topline = wp->w_cursor.lnum - wp->w_height + 1; if (wp->w_topline < 1) --- 579,585 ---- if (wp->w_cursor.lnum < wp->w_topline) wp->w_topline = wp->w_cursor.lnum; else if (wp->w_cursor.lnum >= wp->w_botline ! && (wp->w_valid & VALID_BOTLINE)) { wp->w_topline = wp->w_cursor.lnum - wp->w_height + 1; if (wp->w_topline < 1) *************** *** 931,946 **** /* * Go through the options in "dict" and apply them to popup window "wp". ! * Only used when creating a new popup window. */ static void ! apply_options(win_T *wp, dict_T *dict) { int nr; apply_move_options(wp, dict); ! set_string_option_direct_in_win(wp, (char_u *)"signcolumn", -1, (char_u *)"no", OPT_FREE|OPT_LOCAL, 0); apply_general_options(wp, dict); --- 931,947 ---- /* * Go through the options in "dict" and apply them to popup window "wp". ! * "create" is TRUE when creating a new popup window. */ static void ! apply_options(win_T *wp, dict_T *dict, int create) { int nr; apply_move_options(wp, dict); ! if (create) ! set_string_option_direct_in_win(wp, (char_u *)"signcolumn", -1, (char_u *)"no", OPT_FREE|OPT_LOCAL, 0); apply_general_options(wp, dict); *************** *** 949,964 **** 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; --- 950,966 ---- if (nr > 0) wp->w_popup_flags |= POPF_HIDDEN; ! // when "firstline" and "cursorline" are both set and the cursor would be ! // above or below the displayed lines, move the cursor to "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 if (wp->w_cursor.lnum < wp->w_firstline ! || wp->w_cursor.lnum >= wp->w_firstline + wp->w_height) wp->w_cursor.lnum = wp->w_firstline; ! wp->w_topline = wp->w_firstline; ! wp->w_valid &= ~VALID_BOTLINE; } popup_mask_refresh = TRUE; *************** *** 2106,2112 **** if (d != NULL) // Deal with options. ! apply_options(wp, d); #ifdef FEAT_TIMERS if (type == TYPE_NOTIFICATION && wp->w_popup_timer == NULL) --- 2108,2114 ---- if (d != NULL) // Deal with options. ! apply_options(wp, d, TRUE); #ifdef FEAT_TIMERS if (type == TYPE_NOTIFICATION && wp->w_popup_timer == NULL) *************** *** 2762,2774 **** dict = argvars[1].vval.v_dict; old_firstline = wp->w_firstline; ! apply_move_options(wp, dict); ! apply_general_options(wp, dict); if (old_firstline != wp->w_firstline) redraw_win_later(wp, NOT_VALID); - popup_mask_refresh = TRUE; - popup_highlight_curline(wp); popup_adjust_position(wp); } --- 2764,2773 ---- dict = argvars[1].vval.v_dict; old_firstline = wp->w_firstline; ! apply_options(wp, dict, FALSE); if (old_firstline != wp->w_firstline) redraw_win_later(wp, NOT_VALID); popup_adjust_position(wp); } *************** *** 3467,3479 **** { if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) return TRUE; ! if (win_valid(wp->w_popup_prop_win)) ! return wp->w_popup_prop_changedtick ! != CHANGEDTICK(wp->w_popup_prop_win->w_buffer) ! || wp->w_popup_prop_topline != wp->w_popup_prop_win->w_topline ! || ((wp->w_popup_flags & POPF_CURSORLINE) ! && wp->w_cursor.lnum != wp->w_popup_last_curline); ! return FALSE; } /* --- 3466,3479 ---- { if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) return TRUE; ! if (win_valid(wp->w_popup_prop_win) ! && (wp->w_popup_prop_changedtick ! != CHANGEDTICK(wp->w_popup_prop_win->w_buffer) ! || wp->w_popup_prop_topline != wp->w_popup_prop_win->w_topline)) ! return TRUE; ! ! // May need to adjust the width if the cursor moved. ! return wp->w_cursor.lnum != wp->w_popup_last_curline; } /* *************** *** 3647,3652 **** --- 3647,3663 ---- } /* + * If the current window is a popup and something relevant changed, recompute + * the position and size. + */ + void + may_update_popup_position(void) + { + if (popup_is_popup(curwin) && popup_need_position_adjust(curwin)) + popup_adjust_position(curwin); + } + + /* * Return a string of "len" spaces in IObuff. */ static char_u * *** ../vim-8.2.1749/src/proto/popupwin.pro 2020-07-18 16:07:02.005864389 +0200 --- src/proto/popupwin.pro 2020-09-26 21:45:18.126355694 +0200 *************** *** 50,55 **** --- 50,56 ---- int popup_no_mapping(void); void popup_check_cursor_pos(void); void may_update_popup_mask(int type); + void may_update_popup_position(void); void update_popups(void (*win_update)(win_T *wp)); int set_ref_in_popups(int copyID); int popup_is_popup(win_T *wp); *** ../vim-8.2.1749/src/move.c 2020-07-14 21:22:26.763794360 +0200 --- src/move.c 2020-09-26 21:45:14.826365004 +0200 *************** *** 2144,2149 **** --- 2144,2153 ---- linenr_T old_topline = curwin->w_topline; #endif + #ifdef FEAT_PROP_POPUP + // if the width changed this needs to be updated first + may_update_popup_position(); + #endif loff.lnum = boff.lnum = curwin->w_cursor.lnum; #ifdef FEAT_FOLDING (void)hasFolding(loff.lnum, &loff.lnum, &boff.lnum); *** ../vim-8.2.1749/src/testdir/test_popupwin.vim 2020-09-24 22:57:10.717447706 +0200 --- src/testdir/test_popupwin.vim 2020-09-26 21:57:58.340345279 +0200 *************** *** 1581,1586 **** --- 1581,1614 ---- call delete('XtestPopupWinExecute') endfunc + func Test_popup_set_firstline() + CheckScreendump + + let lines =<< trim END + let lines = range(1, 50)->map({_, v -> string(v)}) + let g:id = popup_create(lines, #{ + \ minwidth: 20, + \ maxwidth: 20, + \ minheight: &lines - 5, + \ maxheight: &lines - 5, + \ cursorline: 1, + \ }) + call popup_setoptions(g:id, #{firstline: 10}) + redraw + END + call writefile(lines, 'XtestPopupWinSetFirstline') + let buf = RunVimInTerminal('-S XtestPopupWinSetFirstline', #{rows: 16}) + + call VerifyScreenDump(buf, 'Test_popupwin_set_firstline_1', {}) + + call term_sendkeys(buf, ":call popup_setoptions(g:id, #{firstline: 5})\") + call term_sendkeys(buf, ":\") + call VerifyScreenDump(buf, 'Test_popupwin_set_firstline_2', {}) + + call StopVimInTerminal(buf) + call delete('XtestPopupWinSetFirstline') + endfunc + " this tests that we don't get stuck with an error in "win_execute()" func Test_popup_filter_win_execute_error() CheckScreendump *** ../vim-8.2.1749/src/testdir/dumps/Test_popupwin_win_execute_cursorline.dump 2020-09-24 22:57:10.717447706 +0200 --- src/testdir/dumps/Test_popupwin_win_execute_cursorline.dump 2020-09-26 21:46:51.678094844 +0200 *************** *** 1,14 **** > +0&#ffffff0@74 |~+0#4040ff13&| @73 |~| @34|1+0#0000001#ffd7ff255|4| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@35 |~| @34|1+0#0000001#ffd7ff255|5| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@35 |~| @34|1+0#0000001#ffd7ff255|6| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@35 ! |~| @34|1+0#0000001#e0e0e08|7| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@35 |~| @34|1+0#0000001#ffd7ff255|8| +0#0000000#0000001| +0#4040ff13#ffffff0@35 |~| @34|1+0#0000001#ffd7ff255|9| +0#0000000#0000001| +0#4040ff13#ffffff0@35 ! |~| @34|2+0#0000001#ffd7ff255|0| +0#0000000#0000001| +0#4040ff13#ffffff0@35 |~| @34|2+0#0000001#ffd7ff255|1| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@35 - |~| @34|2+0#0000001#ffd7ff255@1| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@35 |~| @73 |~| @73 |:+0#0000000&| @55|0|,|0|-|1| @8|A|l@1| --- 1,14 ---- > +0&#ffffff0@74 |~+0#4040ff13&| @73 + |~| @34|1+0#0000001#ffd7ff255|3| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@35 |~| @34|1+0#0000001#ffd7ff255|4| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@35 |~| @34|1+0#0000001#ffd7ff255|5| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@35 |~| @34|1+0#0000001#ffd7ff255|6| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@35 ! |~| @34|1+0#0000001#e0e0e08|7| +0#0000000#0000001| +0#4040ff13#ffffff0@35 |~| @34|1+0#0000001#ffd7ff255|8| +0#0000000#0000001| +0#4040ff13#ffffff0@35 |~| @34|1+0#0000001#ffd7ff255|9| +0#0000000#0000001| +0#4040ff13#ffffff0@35 ! |~| @34|2+0#0000001#ffd7ff255|0| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@35 |~| @34|2+0#0000001#ffd7ff255|1| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@35 |~| @73 |~| @73 |:+0#0000000&| @55|0|,|0|-|1| @8|A|l@1| *** ../vim-8.2.1749/src/testdir/dumps/Test_popupwin_set_firstline_1.dump 2020-09-26 22:01:05.359873529 +0200 --- src/testdir/dumps/Test_popupwin_set_firstline_1.dump 2020-09-26 21:58:35.652250788 +0200 *************** *** 0 **** --- 1,16 ---- + > +0&#ffffff0@74 + |~+0#4040ff13&| @73 + |~| @25|1+0#0000001#e0e0e08|0| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255@1| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255|2| @17| +0#0000000#0000001| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255|3| @17| +0#0000000#0000001| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255|4| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255|5| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255|6| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255|7| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255|8| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255|9| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|2+0#0000001#ffd7ff255|0| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @73 + |~| @73 + | +0#0000000&@56|0|,|0|-|1| @8|A|l@1| *** ../vim-8.2.1749/src/testdir/dumps/Test_popupwin_set_firstline_2.dump 2020-09-26 22:01:05.363873519 +0200 --- src/testdir/dumps/Test_popupwin_set_firstline_2.dump 2020-09-26 21:58:36.712248107 +0200 *************** *** 0 **** --- 1,16 ---- + > +0&#ffffff0@74 + |~+0#4040ff13&| @73 + |~| @25|5+0#0000001#ffd7ff255| @18| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|6+0#0000001#ffd7ff255| @18| +0#0000000#0000001| +0#4040ff13#ffffff0@26 + |~| @25|7+0#0000001#ffd7ff255| @18| +0#0000000#0000001| +0#4040ff13#ffffff0@26 + |~| @25|8+0#0000001#ffd7ff255| @18| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|9+0#0000001#ffd7ff255| @18| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#e0e0e08|0| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255@1| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255|2| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255|3| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255|4| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @25|1+0#0000001#ffd7ff255|5| @17| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@26 + |~| @73 + |~| @73 + |:+0#0000000&| @55|0|,|0|-|1| @8|A|l@1| *** ../vim-8.2.1749/src/version.c 2020-09-26 19:59:34.097707443 +0200 --- src/version.c 2020-09-26 20:54:30.345947110 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1750, /**/ -- It's totally unfair to suggest - as many have - that engineers are socially inept. Engineers simply have different objectives when it comes to social interaction. (Scott Adams - The Dilbert principle) /// 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 ///