diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-08-30 17:34:08 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-08-30 17:34:08 +0200 |
commit | 9e67b6a6a126f401417590dedf1bd38f71bfbae4 (patch) | |
tree | db35f5353e791964b6ead20edf8a9a2750d69171 | |
parent | 821d771e86dcfc64491b2619f799ac977fc32630 (diff) | |
download | vim-git-9e67b6a6a126f401417590dedf1bd38f71bfbae4.tar.gz |
patch 8.1.1945: popup window "firstline" cannot be resetv8.1.1945
Problem: Popup window "firstline" cannot be reset.
Solution: Allow for setting "firstline" to zero. Fix that the text jumps to
the top when using win_execute(). (closes #4876)
-rw-r--r-- | src/popupwin.c | 13 | ||||
-rw-r--r-- | src/testdir/dumps/Test_popupwin_scroll_5.dump | 8 | ||||
-rw-r--r-- | src/testdir/dumps/Test_popupwin_scroll_6.dump | 8 | ||||
-rw-r--r-- | src/testdir/test_popupwin.vim | 32 | ||||
-rw-r--r-- | src/version.c | 2 |
5 files changed, 52 insertions, 11 deletions
diff --git a/src/popupwin.c b/src/popupwin.c index dfc0c89de..8d4a9f21a 100644 --- a/src/popupwin.c +++ b/src/popupwin.c @@ -610,8 +610,8 @@ apply_general_options(win_T *wp, dict_T *dict) di = dict_find(dict, (char_u *)"firstline", -1); if (di != NULL) wp->w_firstline = dict_get_number(dict, (char_u *)"firstline"); - if (wp->w_firstline < 1) - wp->w_firstline = 1; + if (wp->w_firstline < 0) + wp->w_firstline = 0; di = dict_find(dict, (char_u *)"scrollbar", -1); if (di != NULL) @@ -3192,8 +3192,17 @@ update_popups(void (*win_update)(win_T *wp)) // Draw the popup text, unless it's off screen. if (wp->w_winrow < screen_Rows && wp->w_wincol < screen_Columns) + { win_update(wp); + // move the cursor into the visible lines, otherwise executing + // commands with win_execute() may cause the text to jump. + if (wp->w_cursor.lnum < wp->w_topline) + wp->w_cursor.lnum = wp->w_topline; + else if (wp->w_cursor.lnum >= wp->w_botline) + wp->w_cursor.lnum = wp->w_botline - 1; + } + wp->w_winrow -= top_off; wp->w_wincol -= left_extra; diff --git a/src/testdir/dumps/Test_popupwin_scroll_5.dump b/src/testdir/dumps/Test_popupwin_scroll_5.dump index 0437d451f..fa7ee30f8 100644 --- a/src/testdir/dumps/Test_popupwin_scroll_5.dump +++ b/src/testdir/dumps/Test_popupwin_scroll_5.dump @@ -1,10 +1,10 @@ >1+0&#ffffff0| @73 |2| @73 |3| @73 -|4| @31|o+0#0000001#ffd7ff255|n|e| @4| +0#0000000#4040ff13| +0&#ffffff0@32 -|5| @31|t+0#0000001#ffd7ff255|w|o| @4| +0#0000000#4040ff13| +0&#ffffff0@32 -|6| @31|t+0#0000001#ffd7ff255|h|r|e@1| @2| +0#0000000#ff404010| +0&#ffffff0@32 -|7| @31|f+0#0000001#ffd7ff255|o|u|r| @3| +0#0000000#ff404010| +0&#ffffff0@32 +|4| @31|f+0#0000001#ffd7ff255|o|u|r| @3| +0#0000000#ff404010| +0&#ffffff0@32 +|5| @31|f+0#0000001#ffd7ff255|i|v|e| @3| +0#0000000#4040ff13| +0&#ffffff0@32 +|6| @31|s+0#0000001#ffd7ff255|i|x| @4| +0#0000000#4040ff13| +0&#ffffff0@32 +|7| @31|s+0#0000001#ffd7ff255|e|v|e|n| @2| +0#0000000#ff404010| +0&#ffffff0@32 |8| @73 |9| @73 |:|c|a|l@1| |S|c|r|o|l@1|U|p|(|)| @40|1|,|1| @10|T|o|p| diff --git a/src/testdir/dumps/Test_popupwin_scroll_6.dump b/src/testdir/dumps/Test_popupwin_scroll_6.dump index a0b5988f9..1ee91b1ed 100644 --- a/src/testdir/dumps/Test_popupwin_scroll_6.dump +++ b/src/testdir/dumps/Test_popupwin_scroll_6.dump @@ -1,10 +1,10 @@ >1+0&#ffffff0| @73 |2| @73 |3| @73 -|4| @31|t+0#0000001#ffd7ff255|h|r|e@1| @2| +0#0000000#ff404010| +0&#ffffff0@32 -|5| @31|f+0#0000001#ffd7ff255|o|u|r| @3| +0#0000000#4040ff13| +0&#ffffff0@32 -|6| @31|f+0#0000001#ffd7ff255|i|v|e| @3| +0#0000000#4040ff13| +0&#ffffff0@32 -|7| @31|s+0#0000001#ffd7ff255|i|x| @4| +0#0000000#ff404010| +0&#ffffff0@32 +|4| @31|s+0#0000001#ffd7ff255|i|x| @4| +0#0000000#ff404010| +0&#ffffff0@32 +|5| @31|s+0#0000001#ffd7ff255|e|v|e|n| @2| +0#0000000#ff404010| +0&#ffffff0@32 +|6| @31|e+0#0000001#ffd7ff255|i|g|h|t| @2| +0#0000000#4040ff13| +0&#ffffff0@32 +|7| @31|n+0#0000001#ffd7ff255|i|n|e| @3| +0#0000000#4040ff13| +0&#ffffff0@32 |8| @73 |9| @73 |:|c|a|l@1| |S|c|r|o|l@1|D|o|w|n|(|)| @38|1|,|1| @10|T|o|p| diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim index 947185787..d7130863c 100644 --- a/src/testdir/test_popupwin.vim +++ b/src/testdir/test_popupwin.vim @@ -333,6 +333,36 @@ func Test_popup_firstline() call assert_equal(3, popup_getoptions(winid).firstline) call popup_setoptions(winid, #{firstline: 1}) call assert_equal(1, popup_getoptions(winid).firstline) + call popup_close(winid) + + let winid = popup_create(['xxx']->repeat(50), #{ + \ maxheight: 3, + \ firstline: 11, + \ }) + redraw + call assert_equal(11, popup_getoptions(winid).firstline) + call assert_equal(11, popup_getpos(winid).firstline) + + " Normal command changes what is displayed but not "firstline" + call win_execute(winid, "normal! \<c-y>") + call assert_equal(11, popup_getoptions(winid).firstline) + call assert_equal(10, popup_getpos(winid).firstline) + + " Making some property change applies "firstline" again + call popup_setoptions(winid, #{line: 4}) + call assert_equal(11, popup_getoptions(winid).firstline) + call assert_equal(11, popup_getpos(winid).firstline) + + " Remove "firstline" property and scroll + call popup_setoptions(winid, #{firstline: 0}) + call win_execute(winid, "normal! \<c-y>") + call assert_equal(0, popup_getoptions(winid).firstline) + call assert_equal(10, popup_getpos(winid).firstline) + + " Making some property change has no side effect + call popup_setoptions(winid, #{line: 3}) + call assert_equal(0, popup_getoptions(winid).firstline) + call assert_equal(10, popup_getpos(winid).firstline) call popup_close(winid) endfunc @@ -1678,7 +1708,7 @@ func Test_popup_scrollbar() call term_sendkeys(buf, ":\<CR>") call VerifyScreenDump(buf, 'Test_popupwin_scroll_4', {}) - call term_sendkeys(buf, ":call popup_setoptions(winid, #{scrollbarhighlight: 'ScrollBar', thumbhighlight: 'ScrollThumb'})\<CR>") + call term_sendkeys(buf, ":call popup_setoptions(winid, #{scrollbarhighlight: 'ScrollBar', thumbhighlight: 'ScrollThumb', firstline: 5})\<CR>") call term_sendkeys(buf, ":call ScrollUp()\<CR>") call VerifyScreenDump(buf, 'Test_popupwin_scroll_5', {}) diff --git a/src/version.c b/src/version.c index 71901c9c2..5bde641b4 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1945, +/**/ 1944, /**/ 1943, |