]> granicus.if.org Git - vim/commitdiff
patch 8.1.1814: a long title in a popup window overflows v8.1.1814
authorBram Moolenaar <Bram@vim.org>
Sun, 4 Aug 2019 19:12:15 +0000 (21:12 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 4 Aug 2019 19:12:15 +0000 (21:12 +0200)
Problem:    A long title in a popup window overflows.
Solution:   Truncate the title. (closes #4770)

src/popupwin.c
src/testdir/dumps/Test_popupwin_longtitle_1.dump [new file with mode: 0644]
src/testdir/dumps/Test_popupwin_longtitle_2.dump [new file with mode: 0644]
src/testdir/test_popupwin.vim
src/version.c

index ca75181426c3099d68dac38c854438f0ae9f28aa..9d801ea4bc92d8551769a968940b15abdf1df121 100644 (file)
@@ -2969,8 +2969,14 @@ update_popups(void (*win_update)(win_T *wp))
 
        // 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)
diff --git a/src/testdir/dumps/Test_popupwin_longtitle_1.dump b/src/testdir/dumps/Test_popupwin_longtitle_1.dump
new file mode 100644 (file)
index 0000000..92af8b2
--- /dev/null
@@ -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| 
diff --git a/src/testdir/dumps/Test_popupwin_longtitle_2.dump b/src/testdir/dumps/Test_popupwin_longtitle_2.dump
new file mode 100644 (file)
index 0000000..079fbc3
--- /dev/null
@@ -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| 
index 8a5892670e62210c5eef1ef13adc18519fad5c32..c1bae367b819bcdb181d96b32174f63c7238ea51 100644 (file)
@@ -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')
index 7c9ba68ad5b66ddea1b4758557ba1c961b084763..b8479b15c6a693091430adcd26a3c52ba8b3da6f 100644 (file)
@@ -773,6 +773,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1814,
 /**/
     1813,
 /**/