Skip to content

Commit 402502d

Browse files
committed
patch 8.1.1430: popup window option "wrap" not supported
Problem: Popup window option "wrap" not supported. Solution: Implement it.
1 parent ac1f1bc commit 402502d

File tree

5 files changed

+109
-24
lines changed

5 files changed

+109
-24
lines changed

src/popupwin.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ get_pos_options(win_T *wp, dict_T *dict)
109109
static void
110110
apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict, int atcursor)
111111
{
112-
#if defined(FEAT_TIMERS)
113-
int nr;
114-
#endif
115-
char_u *str;
112+
int nr;
113+
char_u *str;
114+
dictitem_T *di;
116115

117116
wp->w_minwidth = dict_get_number(dict, (char_u *)"minwidth");
118117
wp->w_minheight = dict_get_number(dict, (char_u *)"minheight");
@@ -158,10 +157,17 @@ apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict, int atcursor)
158157
}
159158
#endif
160159

160+
// Option values resulting in setting an option.
161161
str = dict_get_string(dict, (char_u *)"highlight", TRUE);
162162
if (str != NULL)
163163
set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
164164
str, OPT_FREE|OPT_LOCAL, 0);
165+
di = dict_find(dict, (char_u *)"wrap", -1);
166+
if (di != NULL)
167+
{
168+
nr = dict_get_number(dict, (char_u *)"wrap");
169+
wp->w_p_wrap = nr != 0;
170+
}
165171
}
166172

167173
/*
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
>1+0&#ffffff0| @73
2+
|2| @73
3+
|3| @17|a+0#0000001#ffd7ff255| |l|o|n|g| |l|i|n| +0#0000000#ffffff0@45
4+
|4| @73
5+
|5| @73
6+
|6| @73
7+
|7| @73
8+
|8| @73
9+
|9| @73
10+
@57|1|,|1| @10|T|o|p|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
>1+0&#ffffff0| @73
2+
|2| @73
3+
|3| @17|a+0#0000001#ffd7ff255| |l|o|n|g| |l|i|n| +0#0000000#ffffff0@45
4+
|4| @17|e+0#0000001#ffd7ff255| |t|h|a|t| |w|o|n| +0#0000000#ffffff0@45
5+
|5| @17|t+0#0000001#ffd7ff255| |f|i|t| @4| +0#0000000#ffffff0@45
6+
|6| @73
7+
|7| @73
8+
|8| @73
9+
|9| @73
10+
@57|1|,|1| @10|T|o|p|

src/testdir/test_popupwin.vim

Lines changed: 77 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,19 @@ func Test_popup_with_syntax_setbufvar()
8484
if !CanRunVimInTerminal()
8585
return
8686
endif
87-
call writefile([
88-
\ "call setline(1, range(1, 100))",
89-
\ "hi PopupColor ctermbg=lightgrey",
90-
\ "let winid = popup_create([",
91-
\ "\\ '#include <stdio.h>',",
92-
\ "\\ 'int main(void)',",
93-
\ "\\ '{',",
94-
\ "\\ ' printf(567);',",
95-
\ "\\ '}',",
96-
\ "\\], {'line': 3, 'col': 21, 'highlight': 'PopupColor'})",
97-
\ "call setbufvar(winbufnr(winid), '&syntax', 'cpp')",
98-
\], 'XtestPopup')
87+
let lines =<< trim END
88+
call setline(1, range(1, 100))
89+
hi PopupColor ctermbg=lightgrey
90+
let winid = popup_create([
91+
\ '#include <stdio.h>',
92+
\ 'int main(void)',
93+
\ '{',
94+
\ ' printf(567);',
95+
\ '}',
96+
\], {'line': 3, 'col': 21, 'highlight': 'PopupColor'})
97+
call setbufvar(winbufnr(winid), '&syntax', 'cpp')
98+
END
99+
call writefile(lines, 'XtestPopup')
99100
let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
100101
call VerifyScreenDump(buf, 'Test_popupwin_11', {})
101102

@@ -104,6 +105,44 @@ func Test_popup_with_syntax_setbufvar()
104105
call delete('XtestPopup')
105106
endfunc
106107

108+
func Test_popup_with_wrap()
109+
if !CanRunVimInTerminal()
110+
return
111+
endif
112+
let lines =<< trim END
113+
call setline(1, range(1, 100))
114+
let winid = popup_create(
115+
\ 'a long line that wont fit',
116+
\ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1})
117+
END
118+
call writefile(lines, 'XtestPopup')
119+
let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
120+
call VerifyScreenDump(buf, 'Test_popupwin_wrap', {})
121+
122+
" clean up
123+
call StopVimInTerminal(buf)
124+
call delete('XtestPopup')
125+
endfunc
126+
127+
func Test_popup_without_wrap()
128+
if !CanRunVimInTerminal()
129+
return
130+
endif
131+
let lines =<< trim END
132+
call setline(1, range(1, 100))
133+
let winid = popup_create(
134+
\ 'a long line that wont fit',
135+
\ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0})
136+
END
137+
call writefile(lines, 'XtestPopup')
138+
let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
139+
call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {})
140+
141+
" clean up
142+
call StopVimInTerminal(buf)
143+
call delete('XtestPopup')
144+
endfunc
145+
107146
func Test_popup_time()
108147
if !has('timers')
109148
return
@@ -156,19 +195,19 @@ func Test_popup_hide()
156195
redraw
157196
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
158197
call assert_equal('world', line)
159-
call assert_equal(1, popup_getposition(winid).visible)
198+
call assert_equal(1, popup_getpos(winid).visible)
160199

161200
call popup_hide(winid)
162201
redraw
163202
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
164203
call assert_equal('hello', line)
165-
call assert_equal(0, popup_getposition(winid).visible)
204+
call assert_equal(0, popup_getpos(winid).visible)
166205

167206
call popup_show(winid)
168207
redraw
169208
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
170209
call assert_equal('world', line)
171-
call assert_equal(1, popup_getposition(winid).visible)
210+
call assert_equal(1, popup_getpos(winid).visible)
172211

173212

174213
call popup_close(winid)
@@ -216,15 +255,15 @@ func Test_popup_move()
216255
bwipe!
217256
endfunc
218257

219-
func Test_popup_getposition()
258+
func Test_popup_getpos()
220259
let winid = popup_create('hello', {
221260
\ 'line': 2,
222261
\ 'col': 3,
223262
\ 'minwidth': 10,
224263
\ 'minheight': 11,
225264
\})
226265
redraw
227-
let res = popup_getposition(winid)
266+
let res = popup_getpos(winid)
228267
call assert_equal(2, res.line)
229268
call assert_equal(3, res.col)
230269
call assert_equal(10, res.width)
@@ -246,7 +285,7 @@ func Test_popup_width_longest()
246285
for test in tests
247286
let winid = popup_create(test[0], {'line': 2, 'col': 3})
248287
redraw
249-
let position = popup_getposition(winid)
288+
let position = popup_getpos(winid)
250289
call assert_equal(test[1], position.width)
251290
call popup_close(winid)
252291
endfor
@@ -262,12 +301,12 @@ func Test_popup_wraps()
262301
let winid = popup_create(test[0],
263302
\ {'line': 2, 'col': 3, 'maxwidth': 12})
264303
redraw
265-
let position = popup_getposition(winid)
304+
let position = popup_getpos(winid)
266305
call assert_equal(test[1], position.width)
267306
call assert_equal(test[2], position.height)
268307

269308
call popup_close(winid)
270-
call assert_equal({}, popup_getposition(winid))
309+
call assert_equal({}, popup_getpos(winid))
271310
endfor
272311
endfunc
273312

@@ -382,5 +421,23 @@ func Test_popup_atcursor()
382421
call assert_equal('xvimxxxxxxxxxxxxx', line)
383422
call popup_close(winid)
384423

424+
" just enough room above
425+
call cursor(3, 3)
426+
redraw
427+
let winid = popup_atcursor(['vim', 'is great'], {})
428+
redraw
429+
let pos = popup_getpos(winid)
430+
call assert_equal(1, pos.line)
431+
call popup_close(winid)
432+
433+
" not enough room above, popup goes below the cursor
434+
call cursor(3, 3)
435+
redraw
436+
let winid = popup_atcursor(['vim', 'is', 'great'], {})
437+
redraw
438+
let pos = popup_getpos(winid)
439+
call assert_equal(4, pos.line)
440+
call popup_close(winid)
441+
385442
bwipe!
386443
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ static char *(features[]) =
767767

768768
static int included_patches[] =
769769
{ /* Add new patch number below this line */
770+
/**/
771+
1430,
770772
/**/
771773
1429,
772774
/**/

0 commit comments

Comments
 (0)