0
0
mirror of https://github.com/vim/vim.git synced 2025-09-30 04:44:14 -04:00

patch 8.1.1773: the preview popup window may be too far to the right

Problem:    The preview popup window may be too far to the right.
Solution:   Keep it inside the screen.  Also keep the close button and
            scrollbar visible if possible.
This commit is contained in:
Bram Moolenaar
2019-07-28 21:42:38 +02:00
parent b78564d022
commit 13d5c3f616
11 changed files with 186 additions and 119 deletions

View File

@@ -5138,7 +5138,7 @@ prepare_tagpreview(
{ {
wp = popup_find_preview_window(); wp = popup_find_preview_window();
if (wp != NULL) if (wp != NULL)
popup_set_wantpos(wp); popup_set_wantpos(wp, wp->w_minwidth);
} }
else else
# endif # endif

View File

@@ -1026,6 +1026,8 @@ popup_adjust_position(win_T *wp)
wp->w_has_scrollbar = wp->w_want_scrollbar wp->w_has_scrollbar = wp->w_want_scrollbar
&& (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count); && (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count);
if (wp->w_has_scrollbar)
++right_extra;
minwidth = wp->w_minwidth; minwidth = wp->w_minwidth;
if (wp->w_popup_title != NULL && *wp->w_popup_title != NUL) if (wp->w_popup_title != NULL && *wp->w_popup_title != NUL)
@@ -1040,7 +1042,7 @@ popup_adjust_position(win_T *wp)
wp->w_width = minwidth; wp->w_width = minwidth;
if (wp->w_width > maxwidth) if (wp->w_width > maxwidth)
{ {
if (wp->w_width > maxspace) if (wp->w_width > maxspace && !wp->w_p_wrap)
// some columns cut off on the right // some columns cut off on the right
wp->w_popup_rightoff = wp->w_width - maxspace; wp->w_popup_rightoff = wp->w_width - maxspace;
wp->w_width = maxwidth; wp->w_width = maxwidth;
@@ -1074,6 +1076,26 @@ popup_adjust_position(win_T *wp)
} }
} }
if (wp->w_p_wrap)
{
int want_col = 0;
if (wp->w_popup_close == POPCLOSE_BUTTON)
// try to show the close button
want_col = left_extra + wp->w_width + right_extra;
else if (wp->w_has_scrollbar)
// try to show the scrollbar
want_col = left_extra + wp->w_width
+ right_extra - wp->w_popup_border[1];
if (want_col > 0 && wp->w_wincol > 0
&& wp->w_wincol + want_col >= Columns)
{
wp->w_wincol = Columns - want_col;
if (wp->w_wincol < 0)
wp->w_wincol = 0;
}
}
wp->w_height = wp->w_buffer->b_ml.ml_line_count - wp->w_topline wp->w_height = wp->w_buffer->b_ml.ml_line_count - wp->w_topline
+ 1 + wrapped; + 1 + wrapped;
if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight) if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight)
@@ -1112,6 +1134,9 @@ popup_adjust_position(win_T *wp)
|| org_height != wp->w_height) || org_height != wp->w_height)
{ {
redraw_all_later(VALID); redraw_all_later(VALID);
redraw_win_later(wp, NOT_VALID);
if (wp->w_popup_flags & POPF_ON_CMDLINE)
clear_cmdline = TRUE;
popup_mask_refresh = TRUE; popup_mask_refresh = TRUE;
} }
} }
@@ -1221,9 +1246,10 @@ parse_previewpopup(win_T *wp)
/* /*
* Set w_wantline and w_wantcol for the cursor position in the current window. * Set w_wantline and w_wantcol for the cursor position in the current window.
* Keep at least "width" columns from the right of the screen.
*/ */
void void
popup_set_wantpos(win_T *wp) popup_set_wantpos(win_T *wp, int width)
{ {
setcursor_mayforce(TRUE); setcursor_mayforce(TRUE);
wp->w_wantline = curwin->w_winrow + curwin->w_wrow; wp->w_wantline = curwin->w_winrow + curwin->w_wrow;
@@ -1232,7 +1258,14 @@ popup_set_wantpos(win_T *wp)
wp->w_wantline = 2; wp->w_wantline = 2;
wp->w_popup_pos = POPPOS_TOPLEFT; wp->w_popup_pos = POPPOS_TOPLEFT;
} }
wp->w_wantcol = curwin->w_wincol + curwin->w_wcol + 1; wp->w_wantcol = curwin->w_wincol + curwin->w_wcol + 1;
if (wp->w_wantcol > Columns - width)
{
wp->w_wantcol = Columns - width;
if (wp->w_wantcol < 1)
wp->w_wantcol = 1;
}
popup_adjust_position(wp); popup_adjust_position(wp);
} }
@@ -1378,10 +1411,10 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
if (type == TYPE_ATCURSOR || type == TYPE_PREVIEW) if (type == TYPE_ATCURSOR || type == TYPE_PREVIEW)
{ {
wp->w_popup_pos = POPPOS_BOTLEFT; wp->w_popup_pos = POPPOS_BOTLEFT;
popup_set_wantpos(wp);
} }
if (type == TYPE_ATCURSOR) if (type == TYPE_ATCURSOR)
{ {
popup_set_wantpos(wp, 0);
set_moved_values(wp); set_moved_values(wp);
set_moved_columns(wp, FIND_STRING); set_moved_columns(wp, FIND_STRING);
} }
@@ -1485,6 +1518,7 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
for (i = 0; i < 4; ++i) for (i = 0; i < 4; ++i)
wp->w_popup_border[i] = 1; wp->w_popup_border[i] = 1;
parse_previewpopup(wp); parse_previewpopup(wp);
popup_set_wantpos(wp, wp->w_minwidth);
} }
for (i = 0; i < 4; ++i) for (i = 0; i < 4; ++i)
@@ -1878,6 +1912,7 @@ f_popup_settext(typval_T *argvars, typval_T *rettv UNUSED)
else else
{ {
popup_set_buffer_text(wp->w_buffer, argvars[1]); popup_set_buffer_text(wp->w_buffer, argvars[1]);
redraw_win_later(wp, NOT_VALID);
popup_adjust_position(wp); popup_adjust_position(wp);
} }
} }
@@ -1888,7 +1923,7 @@ popup_free(win_T *wp)
{ {
sign_undefine_by_name(popup_get_sign_name(wp), FALSE); sign_undefine_by_name(popup_get_sign_name(wp), FALSE);
wp->w_buffer->b_locked = FALSE; wp->w_buffer->b_locked = FALSE;
if (wp->w_winrow + wp->w_height >= cmdline_row) if (wp->w_winrow + popup_height(wp) >= cmdline_row)
clear_cmdline = TRUE; clear_cmdline = TRUE;
win_free_popup(wp); win_free_popup(wp);
@@ -2756,6 +2791,12 @@ update_popups(void (*win_update)(win_T *wp))
total_height = popup_height(wp); total_height = popup_height(wp);
popup_attr = get_wcr_attr(wp); popup_attr = get_wcr_attr(wp);
if (wp->w_winrow + total_height > cmdline_row)
wp->w_popup_flags |= POPF_ON_CMDLINE;
else
wp->w_popup_flags &= ~POPF_ON_CMDLINE;
// We can only use these line drawing characters when 'encoding' is // We can only use these line drawing characters when 'encoding' is
// "utf-8" and 'ambiwidth' is "single". // "utf-8" and 'ambiwidth' is "single".
if (enc_utf8 && *p_ambw == 's') if (enc_utf8 && *p_ambw == 's')

View File

@@ -9,7 +9,7 @@ int popup_height(win_T *wp);
int popup_width(win_T *wp); int popup_width(win_T *wp);
void popup_adjust_position(win_T *wp); void popup_adjust_position(win_T *wp);
int parse_previewpopup(win_T *wp); int parse_previewpopup(win_T *wp);
void popup_set_wantpos(win_T *wp); void popup_set_wantpos(win_T *wp, int width);
void f_popup_clear(typval_T *argvars, typval_T *rettv); void f_popup_clear(typval_T *argvars, typval_T *rettv);
void f_popup_create(typval_T *argvars, typval_T *rettv); void f_popup_create(typval_T *argvars, typval_T *rettv);
void f_popup_atcursor(typval_T *argvars, typval_T *rettv); void f_popup_atcursor(typval_T *argvars, typval_T *rettv);

View File

@@ -795,6 +795,11 @@ update_screen(int type_arg)
FOR_ALL_WINDOWS(wp) FOR_ALL_WINDOWS(wp)
wp->w_buffer->b_mod_set = FALSE; wp->w_buffer->b_mod_set = FALSE;
#ifdef FEAT_TEXT_PROP
// Display popup windows on top of the windows and command line.
update_popups(win_update);
#endif
after_updating_screen(TRUE); after_updating_screen(TRUE);
/* Clear or redraw the command line. Done last, because scrolling may /* Clear or redraw the command line. Done last, because scrolling may
@@ -810,11 +815,6 @@ update_screen(int type_arg)
maybe_intro_message(); maybe_intro_message();
did_intro = TRUE; did_intro = TRUE;
#ifdef FEAT_TEXT_PROP
// Display popup windows on top of the windows.
update_popups(win_update);
#endif
#ifdef FEAT_GUI #ifdef FEAT_GUI
/* Redraw the cursor and update the scrollbars when all screen updating is /* Redraw the cursor and update the scrollbars when all screen updating is
* done. */ * done. */

View File

@@ -8,7 +8,7 @@
|f|i|n|d| >t|h|e|w|o|r|d| |s|o|m|e|w|h|e|r|e| @52 |f|i|n|d| >t|h|e|w|o|r|d| |s|o|m|e|w|h|e|r|e| @52
|n|i|n|e| @70 |n|i|n|e| @70
|t|h|i|s| |i|s| |a|n|o|t|h|e|r| |w|o|r|d| @54 |t|h|i|s| |i|s| |a|n|o|t|h|e|r| |w|o|r|d| @54
|v|e|r|y| |l|o|n|g| |l|i|n|e| |w|h|e|r|e| |t|h|e| |w|o|r|d| |i|s| |a|l|s|o| |a|n|o|t|h|e|r| @29
|~+0#4040ff13&| @73 |~+0#4040ff13&| @73
|~| @73 |~| @73
|~| @73
|:+0#0000000&| @55|8|,|6| @10|A|l@1| |:+0#0000000&| @55|8|,|6| @10|A|l@1|

View File

@@ -8,7 +8,7 @@
|f|i|n|d| |t|h|e|║+0#0000001#ffd7ff255|3|0| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@23 |f|i|n|d| |t|h|e|║+0#0000001#ffd7ff255|3|0| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@23
|n|i|n|e| @3|╚+0#0000001#ffd7ff255|═@40|╝| +0#0000000#ffffff0@23 |n|i|n|e| @3|╚+0#0000001#ffd7ff255|═@40|╝| +0#0000000#ffffff0@23
|t|h|i|s| |i|s| >a|n|o|t|h|e|r| |w|o|r|d| @54 |t|h|i|s| |i|s| >a|n|o|t|h|e|r| |w|o|r|d| @54
|v|e|r|y| |l|o|n|g| |l|i|n|e| |w|h|e|r|e| |t|h|e| |w|o|r|d| |i|s| |a|l|s|o| |a|n|o|t|h|e|r| @29
|~+0#4040ff13&| @73 |~+0#4040ff13&| @73
|~| @73 |~| @73
|~| @73
|/+0#0000000&|a|n|o|t|h|e|r| @48|1|0|,|9| @9|A|l@1| |/+0#0000000&|a|n|o|t|h|e|r| @48|1|0|,|9| @9|A|l@1|

View File

@@ -8,7 +8,7 @@
|f|i|n|d| |t|h|e|w|o|r|d| |s|║+0#0000001#ffd7ff255|3|0| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@17 |f|i|n|d| |t|h|e|w|o|r|d| |s|║+0#0000001#ffd7ff255|3|0| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@17
|n|i|n|e| @9|╚+0#0000001#ffd7ff255|═@40|╝| +0#0000000#ffffff0@17 |n|i|n|e| @9|╚+0#0000001#ffd7ff255|═@40|╝| +0#0000000#ffffff0@17
|t|h|i|s| |i|s| >a|n|o|t|h|e|r| |w|o|r|d| @54 |t|h|i|s| |i|s| >a|n|o|t|h|e|r| |w|o|r|d| @54
|v|e|r|y| |l|o|n|g| |l|i|n|e| |w|h|e|r|e| |t|h|e| |w|o|r|d| |i|s| |a|l|s|o| |a|n|o|t|h|e|r| @29
|~+0#4040ff13&| @73 |~+0#4040ff13&| @73
|~| @73 |~| @73
|~| @73
|:+0#0000000&| @55|1|0|,|9| @9|A|l@1| |:+0#0000000&| @55|1|0|,|9| @9|A|l@1|

View File

@@ -0,0 +1,14 @@
|o+0&#ffffff0|n|e| @71
|t|w|o| @71
|t|h|r|e@1| @69
|f|o|u|r| @70
|f|i|v|e| @27|╔+0#0000001#ffd7ff255|═@40|X
|s+0#0000000#ffffff0|i|x| @28|║+0#0000001#ffd7ff255|2|7| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|s+0#0000000#ffffff0|e|v|e|n| @26|║+0#0000001#ffd7ff255|t|h|i|s| |i|s| |a|n|o|t|h|e|r| |p|l|a|c|e| @18| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|f+0#0000000#ffffff0|i|n|d| |t|h|e|w|o|r|d| |s|o|m|e|w|h|e|r|e| @9|║+0#0000001#ffd7ff255|2|9| @37| +0#0000000#0000001|║+0#0000001#ffd7ff255
|n+0#0000000#ffffff0|i|n|e| @27|║+0#0000001#ffd7ff255|3|0| @37| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255
|t+0#0000000#ffffff0|h|i|s| |i|s| |a|n|o|t|h|e|r| |w|o|r|d| @11|╚+0#0000001#ffd7ff255|═@40|╝
|v+0#0000000#ffffff0|e|r|y| |l|o|n|g| |l|i|n|e| |w|h|e|r|e| |t|h|e| |w|o|r|d| |i|s| |a|l|s|o| >a|n|o|t|h|e|r| @29
|~+0#4040ff13&| @73
|~| @73
|/+0#0000000&|a|n|o|t|h|e|r| @48|1@1|,|3|9| @8|A|l@1|

View File

@@ -2164,7 +2164,8 @@ func Test_previewpopup()
\ 'seven', \ 'seven',
\ 'find theword somewhere', \ 'find theword somewhere',
\ 'nine', \ 'nine',
\ 'this is another word']) \ 'this is another word',
\ 'very long line where the word is also another'])
set previewpopup=height:4,width:40 set previewpopup=height:4,width:40
END END
call writefile(lines, 'XtestPreviewPopup') call writefile(lines, 'XtestPreviewPopup')
@@ -2177,6 +2178,13 @@ func Test_previewpopup()
call term_sendkeys(buf, "/another\<CR>\<C-W>}") call term_sendkeys(buf, "/another\<CR>\<C-W>}")
call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_2', {}) call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_2', {})
call term_sendkeys(buf, ":call popup_move(popup_getpreview(), #{col: 15})\<CR>")
call term_sendkeys(buf, ":\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_3', {})
call term_sendkeys(buf, "/another\<CR>\<C-W>}")
call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_4', {})
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call delete('Xtags') call delete('Xtags')
call delete('Xtagfile') call delete('Xtagfile')

View File

@@ -777,6 +777,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1773,
/**/ /**/
1772, 1772,
/**/ /**/

View File

@@ -618,6 +618,8 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
#define POPF_HIDDEN 2 // popup is not displayed #define POPF_HIDDEN 2 // popup is not displayed
#define POPF_HANDLED 4 // popup was just redrawn or filtered #define POPF_HANDLED 4 // popup was just redrawn or filtered
#define POPF_CURSORLINE 8 // popup is highlighting at the cursorline #define POPF_CURSORLINE 8 // popup is highlighting at the cursorline
#define POPF_ON_CMDLINE 16 // popup overlaps command line
#ifdef FEAT_TEXT_PROP #ifdef FEAT_TEXT_PROP
# define WIN_IS_POPUP(wp) ((wp)->w_popup_flags != 0) # define WIN_IS_POPUP(wp) ((wp)->w_popup_flags != 0)
#else #else