diff src/popupwin.c @ 16896:52fc577a087d v8.1.1449

patch 8.1.1449: popup text truncated at end of screen commit https://github.com/vim/vim/commit/042fb4b449bb5d8494698803e766dfd288b458cf Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 2 14:49:56 2019 +0200 patch 8.1.1449: popup text truncated at end of screen Problem: Popup text truncated at end of screen. Solution: Move popup left if needed. Add the "fixed" property to disable that. (Ben Jackson , closes #4466)
author Bram Moolenaar <Bram@vim.org>
date Sun, 02 Jun 2019 15:00:06 +0200
parents 60c9ac14a2ec
children 16fd1bb2e675
line wrap: on
line diff
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -84,6 +84,8 @@ get_pos_options(win_T *wp, dict_T *dict)
     if (nr > 0)
 	wp->w_wantcol = nr;
 
+    wp->w_popup_fixed = dict_get_number(dict, (char_u *)"fixed") != 0;
+
     str = dict_get_string(dict, (char_u *)"pos", FALSE);
     if (str != NULL)
     {
@@ -379,6 +381,7 @@ popup_adjust_position(win_T *wp)
     int		maxwidth;
     int		center_vert = FALSE;
     int		center_hor = FALSE;
+    int		allow_adjust_left = !wp->w_popup_fixed;
 
     wp->w_winrow = 0;
     wp->w_wincol = 0;
@@ -412,10 +415,14 @@ popup_adjust_position(win_T *wp)
     }
 
     // When centering or right aligned, use maximum width.
-    // When left aligned use the space available.
+    // When left aligned use the space available, but shift to the left when we
+    // hit the right of the screen.
     maxwidth = Columns - wp->w_wincol;
     if (wp->w_maxwidth > 0 && maxwidth > wp->w_maxwidth)
+    {
+	allow_adjust_left = FALSE;
 	maxwidth = wp->w_maxwidth;
+    }
 
     // Compute width based on longest text line and the 'wrap' option.
     // TODO: more accurate wrapping
@@ -424,10 +431,32 @@ popup_adjust_position(win_T *wp)
     {
 	int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE));
 
-	while (wp->w_p_wrap && len > maxwidth)
+	if (wp->w_p_wrap)
 	{
-	    ++wrapped;
-	    len -= maxwidth;
+	    while (len > maxwidth)
+	    {
+		++wrapped;
+		len -= maxwidth;
+		wp->w_width = maxwidth;
+	    }
+	}
+	else if (len > maxwidth
+		&& allow_adjust_left
+		&& (wp->w_popup_pos == POPPOS_TOPLEFT
+		    || wp->w_popup_pos == POPPOS_BOTLEFT))
+	{
+	    // adjust leftwise to fit text on screen
+	    int shift_by = ( len - maxwidth );
+
+	    if ( shift_by > wp->w_wincol )
+	    {
+		int truncate_shift = shift_by - wp->w_wincol;
+		len -= truncate_shift;
+		shift_by -= truncate_shift;
+	    }
+
+	    wp->w_wincol -= shift_by;
+	    maxwidth += shift_by;
 	    wp->w_width = maxwidth;
 	}
 	if (wp->w_width < len)
@@ -895,6 +924,7 @@ f_popup_getoptions(typval_T *argvars, ty
 	dict_add_number(dict, "maxheight", wp->w_maxheight);
 	dict_add_number(dict, "maxwidth", wp->w_maxwidth);
 	dict_add_number(dict, "zindex", wp->w_zindex);
+	dict_add_number(dict, "fixed", wp->w_popup_fixed);
 
 	for (i = 0; i < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T));
 									   ++i)