mirror of
https://github.com/vim/vim.git
synced 2025-10-06 05:44:14 -04:00
patch 8.1.1420: popup window size only uses first line length
Problem: Popup window size only uses first line length. Solution: Use the longest line. (Ben Jackson, closes #4451) Also deal with wrapping lines.
This commit is contained in:
@@ -154,6 +154,10 @@ add_popup_dicts(buf_T *buf, list_T *l)
|
|||||||
static void
|
static void
|
||||||
popup_adjust_position(win_T *wp)
|
popup_adjust_position(win_T *wp)
|
||||||
{
|
{
|
||||||
|
linenr_T lnum;
|
||||||
|
int wrapped = 0;
|
||||||
|
int maxwidth;
|
||||||
|
|
||||||
// TODO: Compute the size and position properly.
|
// TODO: Compute the size and position properly.
|
||||||
if (wp->w_wantline > 0)
|
if (wp->w_wantline > 0)
|
||||||
wp->w_winrow = wp->w_wantline - 1;
|
wp->w_winrow = wp->w_wantline - 1;
|
||||||
@@ -171,18 +175,34 @@ popup_adjust_position(win_T *wp)
|
|||||||
if (wp->w_wincol >= Columns - 3)
|
if (wp->w_wincol >= Columns - 3)
|
||||||
wp->w_wincol = Columns - 3;
|
wp->w_wincol = Columns - 3;
|
||||||
|
|
||||||
// TODO: set width based on longest text line and the 'wrap' option
|
maxwidth = Columns - wp->w_wincol;
|
||||||
wp->w_width = vim_strsize(ml_get_buf(wp->w_buffer, 1, FALSE));
|
if (wp->w_maxwidth > 0 && maxwidth > wp->w_maxwidth)
|
||||||
|
maxwidth = wp->w_maxwidth;
|
||||||
|
|
||||||
|
// Compute width based on longest text line and the 'wrap' option.
|
||||||
|
// TODO: more accurate wrapping
|
||||||
|
wp->w_width = 0;
|
||||||
|
for (lnum = 1; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum)
|
||||||
|
{
|
||||||
|
int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE));
|
||||||
|
|
||||||
|
while (wp->w_p_wrap && len > maxwidth)
|
||||||
|
{
|
||||||
|
++wrapped;
|
||||||
|
len -= maxwidth;
|
||||||
|
wp->w_width = maxwidth;
|
||||||
|
}
|
||||||
|
if (wp->w_width < len)
|
||||||
|
wp->w_width = len;
|
||||||
|
}
|
||||||
|
|
||||||
if (wp->w_minwidth > 0 && wp->w_width < wp->w_minwidth)
|
if (wp->w_minwidth > 0 && wp->w_width < wp->w_minwidth)
|
||||||
wp->w_width = wp->w_minwidth;
|
wp->w_width = wp->w_minwidth;
|
||||||
if (wp->w_maxwidth > 0 && wp->w_width > wp->w_maxwidth)
|
if (wp->w_width > maxwidth)
|
||||||
wp->w_width = wp->w_maxwidth;
|
wp->w_width = maxwidth;
|
||||||
if (wp->w_width > Columns - wp->w_wincol)
|
|
||||||
wp->w_width = Columns - wp->w_wincol;
|
|
||||||
|
|
||||||
if (wp->w_height <= 1)
|
if (wp->w_height <= 1)
|
||||||
// TODO: adjust height for wrapped lines
|
wp->w_height = wp->w_buffer->b_ml.ml_line_count + wrapped;
|
||||||
wp->w_height = wp->w_buffer->b_ml.ml_line_count;
|
|
||||||
if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight)
|
if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight)
|
||||||
wp->w_height = wp->w_minheight;
|
wp->w_height = wp->w_minheight;
|
||||||
if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight)
|
if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight)
|
||||||
|
@@ -176,3 +176,39 @@ func Test_popup_getposition()
|
|||||||
|
|
||||||
call popup_close(winid)
|
call popup_close(winid)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_popup_width_longest()
|
||||||
|
let tests = [
|
||||||
|
\ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
|
||||||
|
\ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
|
||||||
|
\ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
|
||||||
|
\ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
|
||||||
|
\ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
for test in tests
|
||||||
|
let winid = popup_create(test[0], {'line': 2, 'col': 3})
|
||||||
|
redraw
|
||||||
|
let position = popup_getposition(winid)
|
||||||
|
call assert_equal(test[1], position.width)
|
||||||
|
call popup_close(winid)
|
||||||
|
endfor
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_popup_wraps()
|
||||||
|
let tests = [
|
||||||
|
\ ['nowrap', 6, 1],
|
||||||
|
\ ['a line that wraps once', 12, 2],
|
||||||
|
\ ['a line that wraps two times', 12, 3],
|
||||||
|
\ ]
|
||||||
|
for test in tests
|
||||||
|
let winid = popup_create(test[0],
|
||||||
|
\ {'line': 2, 'col': 3, 'maxwidth': 12})
|
||||||
|
redraw
|
||||||
|
let position = popup_getposition(winid)
|
||||||
|
call assert_equal(test[1], position.width)
|
||||||
|
call assert_equal(test[2], position.height)
|
||||||
|
|
||||||
|
call popup_close(winid)
|
||||||
|
endfor
|
||||||
|
endfunc
|
||||||
|
@@ -767,6 +767,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 */
|
||||||
|
/**/
|
||||||
|
1420,
|
||||||
/**/
|
/**/
|
||||||
1419,
|
1419,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user