changeset 17634:6e6a84993444 v8.1.1814

patch 8.1.1814: a long title in a popup window overflows commit https://github.com/vim/vim/commit/5d458a7b3d1819d51bff6f3682b81bf943c7e9d0 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 4 21:12:15 2019 +0200 patch 8.1.1814: a long title in a popup window overflows Problem: A long title in a popup window overflows. Solution: Truncate the title. (closes https://github.com/vim/vim/issues/4770)
author Bram Moolenaar <Bram@vim.org>
date Sun, 04 Aug 2019 21:15:04 +0200
parents a965a73ab797
children bb15578c9eca
files src/popupwin.c src/testdir/dumps/Test_popupwin_longtitle_1.dump src/testdir/dumps/Test_popupwin_longtitle_2.dump src/testdir/test_popupwin.vim src/version.c
diffstat 5 files changed, 38 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -2969,8 +2969,14 @@ update_popups(void (*win_update)(win_T *
 
 	// Title goes on top of border or padding.
 	if (wp->w_popup_title != NULL)
-	    screen_puts(wp->w_popup_title, wp->w_winrow, wp->w_wincol + 1,
+	{
+	    int	    len = (int)STRLEN(wp->w_popup_title) + 1;
+	    char_u  *title = alloc(len);
+
+	    trunc_string(wp->w_popup_title, title, total_width - 2, len);
+	    screen_puts(title, wp->w_winrow, wp->w_wincol + 1,
 		    wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr);
+	}
 
 	// Compute scrollbar thumb position and size.
 	if (wp->w_has_scrollbar)
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_longtitle_1.dump
@@ -0,0 +1,10 @@
+>1+0&#ffffff0| @73
+|2| @73
+|3| @73
+|4| @25| +0#0000001#ffd7ff255|a| |v|e|r|y| |.@2|g| |t|o| |f|i|t| | +0#0000000#ffffff0@27
+|5| @25|o+0#0000001#ffd7ff255|n|e| @16| +0#0000000#ffffff0@27
+|6| @25|t+0#0000001#ffd7ff255|w|o| @16| +0#0000000#ffffff0@27
+|7| @25|a+0#0000001#ffd7ff255|n|o|t|h|e|r| @12| +0#0000000#ffffff0@27
+|8| @73
+|9| @73
+|:| @55|1|,|1| @10|T|o|p| 
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_longtitle_2.dump
@@ -0,0 +1,10 @@
+>1+0&#ffffff0| @73
+|2| @73
+|3| @24|╔+0#0000001#ffd7ff255|a| |v|e|r|y| |l|.@2|n|g| |t|o| |f|i|t|╗| +0#0000000#ffffff0@26
+|4| @24|║+0#0000001#ffd7ff255|o|n|e| @16|║| +0#0000000#ffffff0@26
+|5| @24|║+0#0000001#ffd7ff255|t|w|o| @16|║| +0#0000000#ffffff0@26
+|6| @24|║+0#0000001#ffd7ff255|a|n|o|t|h|e|r| @12|║| +0#0000000#ffffff0@26
+|7| @24|╚+0#0000001#ffd7ff255|═@19|╝| +0#0000000#ffffff0@26
+|8| @73
+|9| @73
+|:| @55|1|,|1| @10|T|o|p| 
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -1282,12 +1282,20 @@ func Test_popup_title()
   " put the title on.
   let lines =<< trim END
 	call setline(1, range(1, 20))
-	call popup_create(['one', 'two', 'another'], #{title: 'Title String'})
+	let winid = popup_create(['one', 'two', 'another'], #{title: 'Title String'})
   END
   call writefile(lines, 'XtestPopupTitle')
   let buf = RunVimInTerminal('-S XtestPopupTitle', #{rows: 10})
   call VerifyScreenDump(buf, 'Test_popupwin_title', {})
 
+  call term_sendkeys(buf, ":call popup_setoptions(winid, #{maxwidth: 20, title: 'a very long title that is not going to fit'})\<CR>")
+  call term_sendkeys(buf, ":\<CR>")
+  call VerifyScreenDump(buf, 'Test_popupwin_longtitle_1', {})
+
+  call term_sendkeys(buf, ":call popup_setoptions(winid, #{border: []})\<CR>")
+  call term_sendkeys(buf, ":\<CR>")
+  call VerifyScreenDump(buf, 'Test_popupwin_longtitle_2', {})
+
   " clean up
   call StopVimInTerminal(buf)
   call delete('XtestPopupTitle')
--- a/src/version.c
+++ b/src/version.c
@@ -774,6 +774,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1814,
+/**/
     1813,
 /**/
     1812,