Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1 | " Tests for popup windows |
| 2 | |
| 3 | if !has('textprop') |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 4 | throw 'Skipped: textprop feature missing' |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 5 | endif |
| 6 | |
| 7 | source screendump.vim |
| 8 | |
| 9 | func Test_simple_popup() |
| 10 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 11 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 12 | endif |
| 13 | call writefile([ |
| 14 | \ "call setline(1, range(1, 100))", |
Bram Moolenaar | 20c023a | 2019-05-26 21:03:24 +0200 | [diff] [blame] | 15 | \ "hi PopupColor1 ctermbg=lightblue", |
| 16 | \ "hi PopupColor2 ctermbg=lightcyan", |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 17 | \ "hi Comment ctermfg=red", |
| 18 | \ "call prop_type_add('comment', {'highlight': 'Comment'})", |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 19 | \ "let winid = popup_create('hello there', {'line': 3, 'col': 11, 'minwidth': 20, 'highlight': 'PopupColor1'})", |
| 20 | \ "let winid2 = popup_create(['another one', 'another two', 'another three'], {'line': 3, 'col': 25, 'minwidth': 20})", |
Bram Moolenaar | 20c023a | 2019-05-26 21:03:24 +0200 | [diff] [blame] | 21 | \ "call setwinvar(winid2, '&wincolor', 'PopupColor2')", |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 22 | \], 'XtestPopup') |
| 23 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 24 | call VerifyScreenDump(buf, 'Test_popupwin_01', {}) |
| 25 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 26 | " Add a tabpage |
| 27 | call term_sendkeys(buf, ":tabnew\<CR>") |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 28 | call term_sendkeys(buf, ":let popupwin = popup_create([" |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 29 | \ .. "{'text': 'other tab'}," |
| 30 | \ .. "{'text': 'a comment line', 'props': [{" |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 31 | \ .. "'col': 3, 'length': 7, 'minwidth': 20, 'type': 'comment'" |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 32 | \ .. "}]}," |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 33 | \ .. "], {'line': 4, 'col': 9, 'minwidth': 20})\<CR>") |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 34 | call VerifyScreenDump(buf, 'Test_popupwin_02', {}) |
| 35 | |
| 36 | " switch back to first tabpage |
| 37 | call term_sendkeys(buf, "gt") |
| 38 | call VerifyScreenDump(buf, 'Test_popupwin_03', {}) |
| 39 | |
| 40 | " close that tabpage |
| 41 | call term_sendkeys(buf, ":quit!\<CR>") |
| 42 | call VerifyScreenDump(buf, 'Test_popupwin_04', {}) |
| 43 | |
Bram Moolenaar | 202d982 | 2019-06-11 21:56:30 +0200 | [diff] [blame] | 44 | " set 'columns' to a small value, size must be recomputed |
| 45 | call term_sendkeys(buf, ":let cols = &columns\<CR>") |
| 46 | call term_sendkeys(buf, ":set columns=12\<CR>") |
| 47 | call VerifyScreenDump(buf, 'Test_popupwin_04a', {}) |
| 48 | call term_sendkeys(buf, ":let &columns = cols\<CR>") |
| 49 | |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 50 | " resize popup, show empty line at bottom |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 51 | call term_sendkeys(buf, ":call popup_move(popupwin, {'minwidth': 15, 'maxwidth': 25, 'minheight': 3, 'maxheight': 5})\<CR>") |
| 52 | call term_sendkeys(buf, ":redraw\<CR>") |
| 53 | call VerifyScreenDump(buf, 'Test_popupwin_05', {}) |
| 54 | |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 55 | " show not fitting line at bottom |
| 56 | call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>") |
| 57 | call term_sendkeys(buf, ":redraw\<CR>") |
| 58 | call VerifyScreenDump(buf, 'Test_popupwin_06', {}) |
| 59 | |
Bram Moolenaar | 24a5ac5 | 2019-06-08 19:01:18 +0200 | [diff] [blame] | 60 | " move popup over ruler |
| 61 | call term_sendkeys(buf, ":set cmdheight=2\<CR>") |
| 62 | call term_sendkeys(buf, ":call popup_move(popupwin, {'line': 7, 'col': 55})\<CR>") |
| 63 | call VerifyScreenDump(buf, 'Test_popupwin_07', {}) |
| 64 | |
| 65 | " clear all popups after moving the cursor a bit, so that ruler is updated |
| 66 | call term_sendkeys(buf, "axxx\<Esc>") |
| 67 | call term_wait(buf) |
| 68 | call term_sendkeys(buf, "0") |
| 69 | call term_wait(buf) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 70 | call term_sendkeys(buf, ":call popup_clear()\<CR>") |
Bram Moolenaar | 24a5ac5 | 2019-06-08 19:01:18 +0200 | [diff] [blame] | 71 | call VerifyScreenDump(buf, 'Test_popupwin_08', {}) |
| 72 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 73 | " clean up |
| 74 | call StopVimInTerminal(buf) |
| 75 | call delete('XtestPopup') |
| 76 | endfunc |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 77 | |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 78 | func Test_popup_with_border_and_padding() |
| 79 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 80 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 81 | endif |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 82 | |
Bram Moolenaar | 3bfd04e | 2019-06-01 20:45:21 +0200 | [diff] [blame] | 83 | for iter in range(0, 1) |
| 84 | call writefile([iter == 1 ? '' : 'set enc=latin1', |
| 85 | \ "call setline(1, range(1, 100))", |
| 86 | \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': []})", |
| 87 | \ "call popup_create('hello padding', {'line': 2, 'col': 23, 'padding': []})", |
| 88 | \ "call popup_create('hello both', {'line': 2, 'col': 43, 'border': [], 'padding': []})", |
| 89 | \ "call popup_create('border TL', {'line': 6, 'col': 3, 'border': [1, 0, 0, 4]})", |
| 90 | \ "call popup_create('paddings', {'line': 6, 'col': 23, 'padding': [1, 3, 2, 4]})", |
| 91 | \], 'XtestPopupBorder') |
| 92 | let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 15}) |
| 93 | call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {}) |
| 94 | |
| 95 | call StopVimInTerminal(buf) |
| 96 | call delete('XtestPopupBorder') |
| 97 | endfor |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 98 | |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 99 | call writefile([ |
| 100 | \ "call setline(1, range(1, 100))", |
| 101 | \ "hi BlueColor ctermbg=lightblue", |
| 102 | \ "hi TopColor ctermbg=253", |
| 103 | \ "hi RightColor ctermbg=245", |
| 104 | \ "hi BottomColor ctermbg=240", |
| 105 | \ "hi LeftColor ctermbg=248", |
| 106 | \ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor']})", |
| 107 | \ "call popup_create(['hello border', 'and more'], {'line': 2, 'col': 23, 'border': [], 'borderhighlight': ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})", |
| 108 | \ "call popup_create(['hello border', 'lines only'], {'line': 2, 'col': 43, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x']})", |
| 109 | \ "call popup_create(['hello border', 'with corners'], {'line': 2, 'col': 60, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x', '#']})", |
| 110 | \ "call popup_create(['hello border', 'with numbers'], {'line': 6, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['0', '1', '2', '3', '4', '5', '6', '7']})", |
| 111 | \ "call popup_create(['hello border', 'just blanks'], {'line': 7, 'col': 23, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': [' ']})", |
| 112 | \], 'XtestPopupBorder') |
| 113 | let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 12}) |
| 114 | call VerifyScreenDump(buf, 'Test_popupwin_22', {}) |
| 115 | |
| 116 | call StopVimInTerminal(buf) |
| 117 | call delete('XtestPopupBorder') |
| 118 | |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 119 | let with_border_or_padding = { |
| 120 | \ 'line': 2, |
| 121 | \ 'core_line': 3, |
| 122 | \ 'col': 3, |
| 123 | \ 'core_col': 4, |
| 124 | \ 'width': 14, |
| 125 | \ 'core_width': 12, |
| 126 | \ 'height': 3, |
| 127 | \ 'core_height': 1, |
| 128 | \ 'visible': 1} |
| 129 | let winid = popup_create('hello border', {'line': 2, 'col': 3, 'border': []})", |
| 130 | call assert_equal(with_border_or_padding, popup_getpos(winid)) |
| 131 | |
| 132 | let winid = popup_create('hello paddng', {'line': 2, 'col': 3, 'padding': []}) |
| 133 | call assert_equal(with_border_or_padding, popup_getpos(winid)) |
| 134 | |
| 135 | let winid = popup_create('hello both', {'line': 3, 'col': 8, 'border': [], 'padding': []}) |
| 136 | call assert_equal({ |
| 137 | \ 'line': 3, |
| 138 | \ 'core_line': 5, |
| 139 | \ 'col': 8, |
| 140 | \ 'core_col': 10, |
| 141 | \ 'width': 14, |
| 142 | \ 'core_width': 10, |
| 143 | \ 'height': 5, |
| 144 | \ 'core_height': 1, |
| 145 | \ 'visible': 1}, popup_getpos(winid)) |
| 146 | endfunc |
| 147 | |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 148 | func Test_popup_with_syntax_win_execute() |
| 149 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 150 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 151 | endif |
| 152 | call writefile([ |
| 153 | \ "call setline(1, range(1, 100))", |
| 154 | \ "hi PopupColor ctermbg=lightblue", |
| 155 | \ "let winid = popup_create([", |
| 156 | \ "\\ '#include <stdio.h>',", |
| 157 | \ "\\ 'int main(void)',", |
| 158 | \ "\\ '{',", |
| 159 | \ "\\ ' printf(123);',", |
| 160 | \ "\\ '}',", |
| 161 | \ "\\], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})", |
| 162 | \ "call win_execute(winid, 'set syntax=cpp')", |
| 163 | \], 'XtestPopup') |
| 164 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 165 | call VerifyScreenDump(buf, 'Test_popupwin_10', {}) |
| 166 | |
| 167 | " clean up |
| 168 | call StopVimInTerminal(buf) |
| 169 | call delete('XtestPopup') |
| 170 | endfunc |
| 171 | |
| 172 | func Test_popup_with_syntax_setbufvar() |
| 173 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 174 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 175 | endif |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 176 | let lines =<< trim END |
| 177 | call setline(1, range(1, 100)) |
| 178 | hi PopupColor ctermbg=lightgrey |
| 179 | let winid = popup_create([ |
| 180 | \ '#include <stdio.h>', |
| 181 | \ 'int main(void)', |
| 182 | \ '{', |
| 183 | \ ' printf(567);', |
| 184 | \ '}', |
| 185 | \], {'line': 3, 'col': 21, 'highlight': 'PopupColor'}) |
| 186 | call setbufvar(winbufnr(winid), '&syntax', 'cpp') |
| 187 | END |
| 188 | call writefile(lines, 'XtestPopup') |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 189 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 190 | call VerifyScreenDump(buf, 'Test_popupwin_11', {}) |
| 191 | |
| 192 | " clean up |
| 193 | call StopVimInTerminal(buf) |
| 194 | call delete('XtestPopup') |
| 195 | endfunc |
| 196 | |
Bram Moolenaar | ac2450a | 2019-06-09 18:04:28 +0200 | [diff] [blame] | 197 | func Test_popup_with_matches() |
| 198 | if !CanRunVimInTerminal() |
| 199 | throw 'Skipped: cannot make screendumps' |
| 200 | endif |
| 201 | let lines =<< trim END |
| 202 | call setline(1, ['111 222 333', '444 555 666']) |
| 203 | let winid = popup_create([ |
| 204 | \ '111 222 333', |
| 205 | \ '444 555 666', |
| 206 | \], {'line': 3, 'col': 10, 'border': []}) |
| 207 | set hlsearch |
| 208 | /666 |
| 209 | call matchadd('ErrorMsg', '111') |
| 210 | call matchadd('ErrorMsg', '444') |
| 211 | call win_execute(winid, "call matchadd('ErrorMsg', '111')") |
| 212 | call win_execute(winid, "call matchadd('ErrorMsg', '555')") |
| 213 | END |
| 214 | call writefile(lines, 'XtestPopupMatches') |
| 215 | let buf = RunVimInTerminal('-S XtestPopupMatches', {'rows': 10}) |
| 216 | call VerifyScreenDump(buf, 'Test_popupwin_matches', {}) |
| 217 | |
| 218 | " clean up |
| 219 | call StopVimInTerminal(buf) |
| 220 | call delete('XtestPopupMatches') |
| 221 | endfunc |
| 222 | |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 223 | func Test_popup_all_corners() |
| 224 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 225 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 226 | endif |
| 227 | let lines =<< trim END |
| 228 | call setline(1, repeat([repeat('-', 60)], 15)) |
| 229 | set so=0 |
| 230 | normal 2G3|r# |
| 231 | let winid1 = popup_create(['first', 'second'], { |
| 232 | \ 'line': 'cursor+1', |
| 233 | \ 'col': 'cursor', |
| 234 | \ 'pos': 'topleft', |
| 235 | \ 'border': [], |
| 236 | \ 'padding': [], |
| 237 | \ }) |
| 238 | normal 25|r@ |
| 239 | let winid1 = popup_create(['First', 'SeconD'], { |
| 240 | \ 'line': 'cursor+1', |
| 241 | \ 'col': 'cursor', |
| 242 | \ 'pos': 'topright', |
| 243 | \ 'border': [], |
| 244 | \ 'padding': [], |
| 245 | \ }) |
| 246 | normal 9G29|r% |
| 247 | let winid1 = popup_create(['fiRSt', 'seCOnd'], { |
| 248 | \ 'line': 'cursor-1', |
| 249 | \ 'col': 'cursor', |
| 250 | \ 'pos': 'botleft', |
| 251 | \ 'border': [], |
| 252 | \ 'padding': [], |
| 253 | \ }) |
| 254 | normal 51|r& |
| 255 | let winid1 = popup_create(['FIrsT', 'SEcoND'], { |
| 256 | \ 'line': 'cursor-1', |
| 257 | \ 'col': 'cursor', |
| 258 | \ 'pos': 'botright', |
| 259 | \ 'border': [], |
| 260 | \ 'padding': [], |
| 261 | \ }) |
| 262 | END |
| 263 | call writefile(lines, 'XtestPopupCorners') |
| 264 | let buf = RunVimInTerminal('-S XtestPopupCorners', {'rows': 12}) |
| 265 | call VerifyScreenDump(buf, 'Test_popupwin_corners', {}) |
| 266 | |
| 267 | " clean up |
| 268 | call StopVimInTerminal(buf) |
| 269 | call delete('XtestPopupCorners') |
| 270 | endfunc |
| 271 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 272 | func Test_popup_firstline() |
| 273 | if !CanRunVimInTerminal() |
| 274 | throw 'Skipped: cannot make screendumps' |
| 275 | endif |
| 276 | let lines =<< trim END |
| 277 | call setline(1, range(1, 20)) |
| 278 | call popup_create(['1111', '222222', '33333', '44', '5', '666666', '77777', '888', '9999999999999999'], { |
| 279 | \ 'maxheight': 4, |
| 280 | \ 'firstline': 3, |
| 281 | \ }) |
| 282 | END |
| 283 | call writefile(lines, 'XtestPopupFirstline') |
| 284 | let buf = RunVimInTerminal('-S XtestPopupFirstline', {'rows': 10}) |
| 285 | call VerifyScreenDump(buf, 'Test_popupwin_firstline', {}) |
| 286 | |
| 287 | " clean up |
| 288 | call StopVimInTerminal(buf) |
| 289 | call delete('XtestPopupFirstline') |
| 290 | endfunc |
| 291 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 292 | func Test_popup_drag() |
| 293 | if !CanRunVimInTerminal() |
| 294 | throw 'Skipped: cannot make screendumps' |
| 295 | endif |
| 296 | " create a popup that covers the command line |
| 297 | let lines =<< trim END |
| 298 | call setline(1, range(1, 20)) |
| 299 | let winid = popup_create(['1111', '222222', '33333'], { |
| 300 | \ 'drag': 1, |
| 301 | \ 'border': [], |
| 302 | \ 'line': &lines - 4, |
| 303 | \ }) |
| 304 | func Dragit() |
| 305 | call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt") |
| 306 | endfunc |
| 307 | map <silent> <F3> :call test_setmouse(&lines - 4, &columns / 2)<CR> |
| 308 | map <silent> <F4> :call test_setmouse(&lines - 8, &columns / 2)<CR> |
| 309 | END |
| 310 | call writefile(lines, 'XtestPopupDrag') |
| 311 | let buf = RunVimInTerminal('-S XtestPopupDrag', {'rows': 10}) |
| 312 | call VerifyScreenDump(buf, 'Test_popupwin_drag_01', {}) |
| 313 | |
| 314 | call term_sendkeys(buf, ":call Dragit()\<CR>") |
| 315 | call VerifyScreenDump(buf, 'Test_popupwin_drag_02', {}) |
| 316 | |
| 317 | " clean up |
| 318 | call StopVimInTerminal(buf) |
| 319 | call delete('XtestPopupDrag') |
| 320 | endfunc |
| 321 | |
Bram Moolenaar | bd75b53 | 2019-06-14 23:41:55 +0200 | [diff] [blame] | 322 | func Test_popup_select() |
| 323 | if !CanRunVimInTerminal() |
| 324 | throw 'Skipped: cannot make screendumps' |
| 325 | endif |
Bram Moolenaar | 650a637 | 2019-06-15 00:29:33 +0200 | [diff] [blame^] | 326 | if !has('clipboard') |
| 327 | throw 'Skipped: clipboard feature missing' |
| 328 | endif |
Bram Moolenaar | bd75b53 | 2019-06-14 23:41:55 +0200 | [diff] [blame] | 329 | " create a popup with some text to be selected |
| 330 | let lines =<< trim END |
| 331 | call setline(1, range(1, 20)) |
| 332 | let winid = popup_create(['the word', 'some more', 'several words here'], { |
| 333 | \ 'drag': 1, |
| 334 | \ 'border': [], |
| 335 | \ 'line': 3, |
| 336 | \ 'col': 10, |
| 337 | \ }) |
| 338 | func Select1() |
| 339 | call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt") |
| 340 | endfunc |
| 341 | map <silent> <F3> :call test_setmouse(4, 15)<CR> |
| 342 | map <silent> <F4> :call test_setmouse(6, 23)<CR> |
| 343 | END |
| 344 | call writefile(lines, 'XtestPopupSelect') |
| 345 | let buf = RunVimInTerminal('-S XtestPopupSelect', {'rows': 10}) |
| 346 | call term_sendkeys(buf, ":call Select1()\<CR>") |
| 347 | call VerifyScreenDump(buf, 'Test_popupwin_select_01', {}) |
| 348 | |
| 349 | call term_sendkeys(buf, ":call popup_close(winid)\<CR>") |
| 350 | call term_sendkeys(buf, "\"*p") |
| 351 | call VerifyScreenDump(buf, 'Test_popupwin_select_02', {}) |
| 352 | |
| 353 | " clean up |
| 354 | call StopVimInTerminal(buf) |
| 355 | call delete('XtestPopupSelect') |
| 356 | endfunc |
| 357 | |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 358 | func Test_popup_in_tab() |
| 359 | " default popup is local to tab, not visible when in other tab |
| 360 | let winid = popup_create("text", {}) |
Bram Moolenaar | 7c7f01e | 2019-06-12 21:06:32 +0200 | [diff] [blame] | 361 | let bufnr = winbufnr(winid) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 362 | call assert_equal(1, popup_getpos(winid).visible) |
| 363 | tabnew |
| 364 | call assert_equal(0, popup_getpos(winid).visible) |
| 365 | quit |
| 366 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 7c7f01e | 2019-06-12 21:06:32 +0200 | [diff] [blame] | 367 | |
| 368 | call assert_equal(1, bufexists(bufnr)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 369 | call popup_clear() |
Bram Moolenaar | 7c7f01e | 2019-06-12 21:06:32 +0200 | [diff] [blame] | 370 | " buffer is gone now |
| 371 | call assert_equal(0, bufexists(bufnr)) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 372 | |
| 373 | " global popup is visible in any tab |
| 374 | let winid = popup_create("text", {'tab': -1}) |
| 375 | call assert_equal(1, popup_getpos(winid).visible) |
| 376 | tabnew |
| 377 | call assert_equal(1, popup_getpos(winid).visible) |
| 378 | quit |
| 379 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 380 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 381 | endfunc |
| 382 | |
| 383 | func Test_popup_valid_arguments() |
| 384 | " Zero value is like the property wasn't there |
| 385 | let winid = popup_create("text", {"col": 0}) |
| 386 | let pos = popup_getpos(winid) |
| 387 | call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 388 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 389 | |
| 390 | " using cursor column has minimum value of 1 |
| 391 | let winid = popup_create("text", {"col": 'cursor-100'}) |
| 392 | let pos = popup_getpos(winid) |
| 393 | call assert_equal(1, pos.col) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 394 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 395 | |
| 396 | " center |
| 397 | let winid = popup_create("text", {"pos": 'center'}) |
| 398 | let pos = popup_getpos(winid) |
| 399 | let around = (&columns - pos.width) / 2 |
| 400 | call assert_inrange(around - 1, around + 1, pos.col) |
| 401 | let around = (&lines - pos.height) / 2 |
| 402 | call assert_inrange(around - 1, around + 1, pos.line) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 403 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 404 | endfunc |
| 405 | |
| 406 | func Test_popup_invalid_arguments() |
| 407 | call assert_fails('call popup_create(666, {})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 408 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 409 | call assert_fails('call popup_create("text", "none")', 'E715:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 410 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 411 | |
| 412 | call assert_fails('call popup_create("text", {"col": "xxx"})', 'E475:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 413 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 414 | call assert_fails('call popup_create("text", {"col": "cursor8"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 415 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 416 | call assert_fails('call popup_create("text", {"col": "cursor+x"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 417 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 418 | call assert_fails('call popup_create("text", {"col": "cursor+8x"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 419 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 420 | |
| 421 | call assert_fails('call popup_create("text", {"line": "xxx"})', 'E475:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 422 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 423 | call assert_fails('call popup_create("text", {"line": "cursor8"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 424 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 425 | call assert_fails('call popup_create("text", {"line": "cursor+x"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 426 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 427 | call assert_fails('call popup_create("text", {"line": "cursor+8x"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 428 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 429 | |
| 430 | call assert_fails('call popup_create("text", {"pos": "there"})', 'E475:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 431 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 432 | call assert_fails('call popup_create("text", {"padding": "none"})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 433 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 434 | call assert_fails('call popup_create("text", {"border": "none"})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 435 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 436 | call assert_fails('call popup_create("text", {"borderhighlight": "none"})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 437 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 438 | call assert_fails('call popup_create("text", {"borderchars": "none"})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 439 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 440 | |
| 441 | call assert_fails('call popup_create([{"text": "text"}, 666], {})', 'E715:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 442 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 443 | call assert_fails('call popup_create([{"text": "text", "props": "none"}], {})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 444 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 445 | call assert_fails('call popup_create([{"text": "text", "props": ["none"]}], {})', 'E715:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 446 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 447 | endfunc |
| 448 | |
Bram Moolenaar | eea1699 | 2019-05-31 17:34:48 +0200 | [diff] [blame] | 449 | func Test_win_execute_closing_curwin() |
| 450 | split |
| 451 | let winid = popup_create('some text', {}) |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 452 | call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 453 | call popup_clear() |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 454 | endfunc |
| 455 | |
| 456 | func Test_win_execute_not_allowed() |
| 457 | let winid = popup_create('some text', {}) |
| 458 | call assert_fails('call win_execute(winid, "split")', 'E994:') |
| 459 | call assert_fails('call win_execute(winid, "vsplit")', 'E994:') |
| 460 | call assert_fails('call win_execute(winid, "close")', 'E994:') |
| 461 | call assert_fails('call win_execute(winid, "bdelete")', 'E994:') |
Bram Moolenaar | 2d24784 | 2019-06-01 17:06:25 +0200 | [diff] [blame] | 462 | call assert_fails('call win_execute(winid, "bwipe!")', 'E994:') |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 463 | call assert_fails('call win_execute(winid, "tabnew")', 'E994:') |
| 464 | call assert_fails('call win_execute(winid, "tabnext")', 'E994:') |
| 465 | call assert_fails('call win_execute(winid, "next")', 'E994:') |
| 466 | call assert_fails('call win_execute(winid, "rewind")', 'E994:') |
| 467 | call assert_fails('call win_execute(winid, "buf")', 'E994:') |
| 468 | call assert_fails('call win_execute(winid, "edit")', 'E994:') |
| 469 | call assert_fails('call win_execute(winid, "enew")', 'E994:') |
| 470 | call assert_fails('call win_execute(winid, "wincmd x")', 'E994:') |
| 471 | call assert_fails('call win_execute(winid, "wincmd w")', 'E994:') |
| 472 | call assert_fails('call win_execute(winid, "wincmd t")', 'E994:') |
| 473 | call assert_fails('call win_execute(winid, "wincmd b")', 'E994:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 474 | call popup_clear() |
Bram Moolenaar | eea1699 | 2019-05-31 17:34:48 +0200 | [diff] [blame] | 475 | endfunc |
| 476 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 477 | func Test_popup_with_wrap() |
| 478 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 479 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 480 | endif |
| 481 | let lines =<< trim END |
| 482 | call setline(1, range(1, 100)) |
| 483 | let winid = popup_create( |
| 484 | \ 'a long line that wont fit', |
| 485 | \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 1}) |
| 486 | END |
| 487 | call writefile(lines, 'XtestPopup') |
| 488 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 489 | call VerifyScreenDump(buf, 'Test_popupwin_wrap', {}) |
| 490 | |
| 491 | " clean up |
| 492 | call StopVimInTerminal(buf) |
| 493 | call delete('XtestPopup') |
| 494 | endfunc |
| 495 | |
| 496 | func Test_popup_without_wrap() |
| 497 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 498 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 499 | endif |
| 500 | let lines =<< trim END |
| 501 | call setline(1, range(1, 100)) |
| 502 | let winid = popup_create( |
| 503 | \ 'a long line that wont fit', |
| 504 | \ {'line': 3, 'col': 20, 'maxwidth': 10, 'wrap': 0}) |
| 505 | END |
| 506 | call writefile(lines, 'XtestPopup') |
| 507 | let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10}) |
| 508 | call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {}) |
| 509 | |
| 510 | " clean up |
| 511 | call StopVimInTerminal(buf) |
| 512 | call delete('XtestPopup') |
| 513 | endfunc |
| 514 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 515 | func Test_popup_time() |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 516 | if !has('timers') |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 517 | throw 'Skipped, timer feature not supported' |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 518 | endif |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 519 | topleft vnew |
| 520 | call setline(1, 'hello') |
| 521 | |
| 522 | call popup_create('world', { |
| 523 | \ 'line': 1, |
| 524 | \ 'col': 1, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 525 | \ 'minwidth': 20, |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 526 | \ 'time': 500, |
| 527 | \}) |
| 528 | redraw |
| 529 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 530 | call assert_equal('world', line) |
| 531 | |
| 532 | sleep 700m |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 533 | redraw |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 534 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 535 | call assert_equal('hello', line) |
| 536 | |
| 537 | call popup_create('on the command line', { |
| 538 | \ 'line': &lines, |
| 539 | \ 'col': 10, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 540 | \ 'minwidth': 20, |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 541 | \ 'time': 500, |
| 542 | \}) |
| 543 | redraw |
| 544 | let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '') |
| 545 | call assert_match('.*on the command line.*', line) |
| 546 | |
| 547 | sleep 700m |
| 548 | redraw |
| 549 | let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '') |
| 550 | call assert_notmatch('.*on the command line.*', line) |
| 551 | |
| 552 | bwipe! |
| 553 | endfunc |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 554 | |
| 555 | func Test_popup_hide() |
| 556 | topleft vnew |
| 557 | call setline(1, 'hello') |
| 558 | |
| 559 | let winid = popup_create('world', { |
| 560 | \ 'line': 1, |
| 561 | \ 'col': 1, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 562 | \ 'minwidth': 20, |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 563 | \}) |
| 564 | redraw |
| 565 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 566 | call assert_equal('world', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 567 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 568 | " buffer is still listed and active |
| 569 | call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u')) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 570 | |
| 571 | call popup_hide(winid) |
| 572 | redraw |
| 573 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 574 | call assert_equal('hello', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 575 | call assert_equal(0, popup_getpos(winid).visible) |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 576 | " buffer is still listed but hidden |
| 577 | call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u')) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 578 | |
| 579 | call popup_show(winid) |
| 580 | redraw |
| 581 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 582 | call assert_equal('world', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 583 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 584 | |
| 585 | |
| 586 | call popup_close(winid) |
| 587 | redraw |
| 588 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 589 | call assert_equal('hello', line) |
| 590 | |
| 591 | " error is given for existing non-popup window |
| 592 | call assert_fails('call popup_hide(win_getid())', 'E993:') |
| 593 | |
| 594 | " no error non-existing window |
| 595 | call popup_hide(1234234) |
| 596 | call popup_show(41234234) |
| 597 | |
| 598 | bwipe! |
| 599 | endfunc |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 600 | |
| 601 | func Test_popup_move() |
| 602 | topleft vnew |
| 603 | call setline(1, 'hello') |
| 604 | |
| 605 | let winid = popup_create('world', { |
| 606 | \ 'line': 1, |
| 607 | \ 'col': 1, |
| 608 | \ 'minwidth': 20, |
| 609 | \}) |
| 610 | redraw |
| 611 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 612 | call assert_equal('world ', line) |
| 613 | |
| 614 | call popup_move(winid, {'line': 2, 'col': 2}) |
| 615 | redraw |
| 616 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 617 | call assert_equal('hello ', line) |
| 618 | let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '') |
| 619 | call assert_equal('~world', line) |
| 620 | |
| 621 | call popup_move(winid, {'line': 1}) |
| 622 | redraw |
| 623 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 624 | call assert_equal('hworld', line) |
| 625 | |
| 626 | call popup_close(winid) |
| 627 | |
| 628 | bwipe! |
| 629 | endfunc |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 630 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 631 | func Test_popup_getpos() |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 632 | let winid = popup_create('hello', { |
| 633 | \ 'line': 2, |
| 634 | \ 'col': 3, |
| 635 | \ 'minwidth': 10, |
| 636 | \ 'minheight': 11, |
| 637 | \}) |
| 638 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 639 | let res = popup_getpos(winid) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 640 | call assert_equal(2, res.line) |
| 641 | call assert_equal(3, res.col) |
| 642 | call assert_equal(10, res.width) |
| 643 | call assert_equal(11, res.height) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 644 | call assert_equal(1, res.visible) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 645 | |
| 646 | call popup_close(winid) |
| 647 | endfunc |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 648 | |
| 649 | func Test_popup_width_longest() |
| 650 | let tests = [ |
| 651 | \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15], |
| 652 | \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15], |
| 653 | \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15], |
| 654 | \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15], |
| 655 | \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15], |
| 656 | \ ] |
| 657 | |
| 658 | for test in tests |
| 659 | let winid = popup_create(test[0], {'line': 2, 'col': 3}) |
| 660 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 661 | let position = popup_getpos(winid) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 662 | call assert_equal(test[1], position.width) |
| 663 | call popup_close(winid) |
| 664 | endfor |
| 665 | endfunc |
| 666 | |
| 667 | func Test_popup_wraps() |
| 668 | let tests = [ |
| 669 | \ ['nowrap', 6, 1], |
| 670 | \ ['a line that wraps once', 12, 2], |
| 671 | \ ['a line that wraps two times', 12, 3], |
| 672 | \ ] |
| 673 | for test in tests |
| 674 | let winid = popup_create(test[0], |
| 675 | \ {'line': 2, 'col': 3, 'maxwidth': 12}) |
| 676 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 677 | let position = popup_getpos(winid) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 678 | call assert_equal(test[1], position.width) |
| 679 | call assert_equal(test[2], position.height) |
| 680 | |
| 681 | call popup_close(winid) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 682 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 683 | endfor |
| 684 | endfunc |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 685 | |
| 686 | func Test_popup_getoptions() |
| 687 | let winid = popup_create('hello', { |
| 688 | \ 'line': 2, |
| 689 | \ 'col': 3, |
| 690 | \ 'minwidth': 10, |
| 691 | \ 'minheight': 11, |
| 692 | \ 'maxwidth': 20, |
| 693 | \ 'maxheight': 21, |
| 694 | \ 'zindex': 100, |
| 695 | \ 'time': 5000, |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 696 | \ 'fixed': 1 |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 697 | \}) |
| 698 | redraw |
| 699 | let res = popup_getoptions(winid) |
| 700 | call assert_equal(2, res.line) |
| 701 | call assert_equal(3, res.col) |
| 702 | call assert_equal(10, res.minwidth) |
| 703 | call assert_equal(11, res.minheight) |
| 704 | call assert_equal(20, res.maxwidth) |
| 705 | call assert_equal(21, res.maxheight) |
| 706 | call assert_equal(100, res.zindex) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 707 | call assert_equal(1, res.fixed) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 708 | if has('timers') |
| 709 | call assert_equal(5000, res.time) |
| 710 | endif |
| 711 | call popup_close(winid) |
| 712 | |
| 713 | let winid = popup_create('hello', {}) |
| 714 | redraw |
| 715 | let res = popup_getoptions(winid) |
| 716 | call assert_equal(0, res.line) |
| 717 | call assert_equal(0, res.col) |
| 718 | call assert_equal(0, res.minwidth) |
| 719 | call assert_equal(0, res.minheight) |
| 720 | call assert_equal(0, res.maxwidth) |
| 721 | call assert_equal(0, res.maxheight) |
| 722 | call assert_equal(50, res.zindex) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 723 | call assert_equal(0, res.fixed) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 724 | if has('timers') |
| 725 | call assert_equal(0, res.time) |
| 726 | endif |
| 727 | call popup_close(winid) |
| 728 | call assert_equal({}, popup_getoptions(winid)) |
| 729 | endfunc |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 730 | |
| 731 | func Test_popup_option_values() |
| 732 | new |
| 733 | " window-local |
| 734 | setlocal number |
| 735 | setlocal nowrap |
| 736 | " buffer-local |
| 737 | setlocal omnifunc=Something |
| 738 | " global/buffer-local |
| 739 | setlocal path=/there |
| 740 | " global/window-local |
| 741 | setlocal scrolloff=9 |
| 742 | |
| 743 | let winid = popup_create('hello', {}) |
| 744 | call assert_equal(0, getwinvar(winid, '&number')) |
| 745 | call assert_equal(1, getwinvar(winid, '&wrap')) |
| 746 | call assert_equal('', getwinvar(winid, '&omnifunc')) |
| 747 | call assert_equal(&g:path, getwinvar(winid, '&path')) |
| 748 | call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff')) |
| 749 | |
| 750 | call popup_close(winid) |
| 751 | bwipe |
| 752 | endfunc |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 753 | |
| 754 | func Test_popup_atcursor() |
| 755 | topleft vnew |
| 756 | call setline(1, [ |
| 757 | \ 'xxxxxxxxxxxxxxxxx', |
| 758 | \ 'xxxxxxxxxxxxxxxxx', |
| 759 | \ 'xxxxxxxxxxxxxxxxx', |
| 760 | \]) |
| 761 | |
| 762 | call cursor(2, 2) |
| 763 | redraw |
| 764 | let winid = popup_atcursor('vim', {}) |
| 765 | redraw |
| 766 | let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
| 767 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 768 | call popup_close(winid) |
| 769 | |
| 770 | call cursor(3, 4) |
| 771 | redraw |
| 772 | let winid = popup_atcursor('vim', {}) |
| 773 | redraw |
| 774 | let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '') |
| 775 | call assert_equal('xxxvimxxxxxxxxxxx', line) |
| 776 | call popup_close(winid) |
| 777 | |
| 778 | call cursor(1, 1) |
| 779 | redraw |
| 780 | let winid = popup_create('vim', { |
| 781 | \ 'line': 'cursor+2', |
| 782 | \ 'col': 'cursor+1', |
| 783 | \}) |
| 784 | redraw |
| 785 | let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '') |
| 786 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 787 | call popup_close(winid) |
| 788 | |
| 789 | call cursor(3, 3) |
| 790 | redraw |
| 791 | let winid = popup_create('vim', { |
| 792 | \ 'line': 'cursor-2', |
| 793 | \ 'col': 'cursor-1', |
| 794 | \}) |
| 795 | redraw |
| 796 | let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
| 797 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 798 | call popup_close(winid) |
| 799 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 800 | " just enough room above |
| 801 | call cursor(3, 3) |
| 802 | redraw |
| 803 | let winid = popup_atcursor(['vim', 'is great'], {}) |
| 804 | redraw |
| 805 | let pos = popup_getpos(winid) |
| 806 | call assert_equal(1, pos.line) |
| 807 | call popup_close(winid) |
| 808 | |
| 809 | " not enough room above, popup goes below the cursor |
| 810 | call cursor(3, 3) |
| 811 | redraw |
| 812 | let winid = popup_atcursor(['vim', 'is', 'great'], {}) |
| 813 | redraw |
| 814 | let pos = popup_getpos(winid) |
| 815 | call assert_equal(4, pos.line) |
| 816 | call popup_close(winid) |
| 817 | |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 818 | " cursor in first line, popup in line 2 |
| 819 | call cursor(1, 1) |
| 820 | redraw |
| 821 | let winid = popup_atcursor(['vim', 'is', 'great'], {}) |
| 822 | redraw |
| 823 | let pos = popup_getpos(winid) |
| 824 | call assert_equal(2, pos.line) |
| 825 | call popup_close(winid) |
| 826 | |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 827 | bwipe! |
| 828 | endfunc |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 829 | |
| 830 | func Test_popup_filter() |
| 831 | new |
| 832 | call setline(1, 'some text') |
| 833 | |
| 834 | func MyPopupFilter(winid, c) |
| 835 | if a:c == 'e' |
| 836 | let g:eaten = 'e' |
| 837 | return 1 |
| 838 | endif |
| 839 | if a:c == '0' |
| 840 | let g:ignored = '0' |
| 841 | return 0 |
| 842 | endif |
| 843 | if a:c == 'x' |
| 844 | call popup_close(a:winid) |
| 845 | return 1 |
| 846 | endif |
| 847 | return 0 |
| 848 | endfunc |
| 849 | |
| 850 | let winid = popup_create('something', {'filter': 'MyPopupFilter'}) |
| 851 | redraw |
| 852 | |
| 853 | " e is consumed by the filter |
| 854 | call feedkeys('e', 'xt') |
| 855 | call assert_equal('e', g:eaten) |
| 856 | |
| 857 | " 0 is ignored by the filter |
| 858 | normal $ |
| 859 | call assert_equal(9, getcurpos()[2]) |
| 860 | call feedkeys('0', 'xt') |
| 861 | call assert_equal('0', g:ignored) |
| 862 | call assert_equal(1, getcurpos()[2]) |
| 863 | |
| 864 | " x closes the popup |
| 865 | call feedkeys('x', 'xt') |
| 866 | call assert_equal('e', g:eaten) |
| 867 | call assert_equal(-1, winbufnr(winid)) |
| 868 | |
| 869 | delfunc MyPopupFilter |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 870 | call popup_clear() |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 871 | endfunc |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 872 | |
| 873 | func Test_popup_close_callback() |
| 874 | func PopupDone(id, result) |
| 875 | let g:result = a:result |
| 876 | endfunc |
| 877 | let winid = popup_create('something', {'callback': 'PopupDone'}) |
| 878 | redraw |
| 879 | call popup_close(winid, 'done') |
| 880 | call assert_equal('done', g:result) |
| 881 | endfunc |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 882 | |
| 883 | func Test_popup_empty() |
| 884 | let winid = popup_create('', {'padding': [2,2,2,2]}) |
| 885 | redraw |
| 886 | let pos = popup_getpos(winid) |
| 887 | call assert_equal(4, pos.width) |
| 888 | call assert_equal(5, pos.height) |
| 889 | |
| 890 | let winid = popup_create([], {'border': []}) |
| 891 | redraw |
| 892 | let pos = popup_getpos(winid) |
| 893 | call assert_equal(2, pos.width) |
| 894 | call assert_equal(3, pos.height) |
| 895 | endfunc |
Bram Moolenaar | 988c433 | 2019-06-02 14:12:11 +0200 | [diff] [blame] | 896 | |
| 897 | func Test_popup_never_behind() |
| 898 | if !CanRunVimInTerminal() |
Bram Moolenaar | 5d30ff1 | 2019-06-06 16:12:12 +0200 | [diff] [blame] | 899 | throw 'Skipped: cannot make screendumps' |
Bram Moolenaar | 988c433 | 2019-06-02 14:12:11 +0200 | [diff] [blame] | 900 | endif |
| 901 | " +-----------------------------+ |
| 902 | " | | | |
| 903 | " | | | |
| 904 | " | | | |
| 905 | " | line1 | |
| 906 | " |------------line2------------| |
| 907 | " | line3 | |
| 908 | " | line4 | |
| 909 | " | | |
| 910 | " | | |
| 911 | " +-----------------------------+ |
| 912 | let lines =<< trim END |
| 913 | only |
| 914 | split |
| 915 | vsplit |
| 916 | let info_window1 = getwininfo()[0] |
| 917 | let line = info_window1['height'] |
| 918 | let col = info_window1['width'] |
| 919 | call popup_create(['line1', 'line2', 'line3', 'line4'], { |
| 920 | \ 'line' : line, |
| 921 | \ 'col' : col, |
| 922 | \ }) |
| 923 | END |
| 924 | call writefile(lines, 'XtestPopupBehind') |
| 925 | let buf = RunVimInTerminal('-S XtestPopupBehind', {'rows': 10}) |
| 926 | call term_sendkeys(buf, "\<C-W>w") |
| 927 | call VerifyScreenDump(buf, 'Test_popupwin_behind', {}) |
| 928 | |
| 929 | " clean up |
| 930 | call StopVimInTerminal(buf) |
| 931 | call delete('XtestPopupBehind') |
| 932 | endfunc |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 933 | |
| 934 | func s:VerifyPosition( p, msg, line, col, width, height ) |
| 935 | call assert_equal( a:line, popup_getpos( a:p ).line, a:msg . ' (l)' ) |
| 936 | call assert_equal( a:col, popup_getpos( a:p ).col, a:msg . ' (c)' ) |
| 937 | call assert_equal( a:width, popup_getpos( a:p ).width, a:msg . ' (w)' ) |
| 938 | call assert_equal( a:height, popup_getpos( a:p ).height, a:msg . ' (h)' ) |
| 939 | endfunc |
| 940 | |
| 941 | func Test_popup_position_adjust() |
| 942 | " Anything placed past 2 cells from of the right of the screen is moved to the |
| 943 | " left. |
| 944 | " |
| 945 | " When wrapping is disabled, we also shift to the left to display on the |
| 946 | " screen, unless fixed is set. |
| 947 | |
| 948 | " Entries for cases which don't vary based on wrapping. |
| 949 | " Format is per tests described below |
| 950 | let both_wrap_tests = [ |
| 951 | \ [ 'a', 5, &columns, 5, &columns - 2, 1, 1 ], |
| 952 | \ [ 'b', 5, &columns + 1, 5, &columns - 2, 1, 1 ], |
| 953 | \ [ 'c', 5, &columns - 1, 5, &columns - 2, 1, 1 ], |
| 954 | \ [ 'd', 5, &columns - 2, 5, &columns - 2, 1, 1 ], |
| 955 | \ [ 'e', 5, &columns - 3, 5, &columns - 3, 1, 1 ], |
| 956 | \ |
| 957 | \ [ 'aa', 5, &columns, 5, &columns - 2, 2, 1 ], |
| 958 | \ [ 'bb', 5, &columns + 1, 5, &columns - 2, 2, 1 ], |
| 959 | \ [ 'cc', 5, &columns - 1, 5, &columns - 2, 2, 1 ], |
| 960 | \ [ 'dd', 5, &columns - 2, 5, &columns - 2, 2, 1 ], |
| 961 | \ [ 'ee', 5, &columns - 3, 5, &columns - 3, 2, 1 ], |
| 962 | \ |
| 963 | \ [ 'aaa', 5, &columns, 5, &columns - 2, 3, 1 ], |
| 964 | \ [ 'bbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ], |
| 965 | \ [ 'ccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ], |
| 966 | \ [ 'ddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ], |
| 967 | \ [ 'eee', 5, &columns - 3, 5, &columns - 3, 3, 1 ], |
| 968 | \ ] |
| 969 | |
| 970 | " these test groups are dicts with: |
| 971 | " - comment: something to identify the group of tests by |
| 972 | " - options: dict of options to merge with the row/col in tests |
| 973 | " - tests: list of cases. Each one is a list with elements: |
| 974 | " - text |
| 975 | " - row |
| 976 | " - col |
| 977 | " - expected row |
| 978 | " - expected col |
| 979 | " - expected width |
| 980 | " - expected height |
| 981 | let tests = [ |
| 982 | \ { |
| 983 | \ 'comment': 'left-aligned with wrapping', |
| 984 | \ 'options': { |
| 985 | \ 'wrap': 1, |
| 986 | \ 'pos': 'botleft', |
| 987 | \ }, |
| 988 | \ 'tests': both_wrap_tests + [ |
| 989 | \ [ 'aaaa', 5, &columns, 4, &columns - 2, 3, 2 ], |
| 990 | \ [ 'bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2 ], |
| 991 | \ [ 'cccc', 5, &columns - 1, 4, &columns - 2, 3, 2 ], |
| 992 | \ [ 'dddd', 5, &columns - 2, 4, &columns - 2, 3, 2 ], |
| 993 | \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ], |
| 994 | \ ], |
| 995 | \ }, |
| 996 | \ { |
| 997 | \ 'comment': 'left aligned without wrapping', |
| 998 | \ 'options': { |
| 999 | \ 'wrap': 0, |
| 1000 | \ 'pos': 'botleft', |
| 1001 | \ }, |
| 1002 | \ 'tests': both_wrap_tests + [ |
| 1003 | \ [ 'aaaa', 5, &columns, 5, &columns - 3, 4, 1 ], |
| 1004 | \ [ 'bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1 ], |
| 1005 | \ [ 'cccc', 5, &columns - 1, 5, &columns - 3, 4, 1 ], |
| 1006 | \ [ 'dddd', 5, &columns - 2, 5, &columns - 3, 4, 1 ], |
| 1007 | \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ], |
| 1008 | \ ], |
| 1009 | \ }, |
| 1010 | \ { |
| 1011 | \ 'comment': 'left aligned with fixed position', |
| 1012 | \ 'options': { |
| 1013 | \ 'wrap': 0, |
| 1014 | \ 'fixed': 1, |
| 1015 | \ 'pos': 'botleft', |
| 1016 | \ }, |
| 1017 | \ 'tests': both_wrap_tests + [ |
| 1018 | \ [ 'aaaa', 5, &columns, 5, &columns - 2, 3, 1 ], |
| 1019 | \ [ 'bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1 ], |
| 1020 | \ [ 'cccc', 5, &columns - 1, 5, &columns - 2, 3, 1 ], |
| 1021 | \ [ 'dddd', 5, &columns - 2, 5, &columns - 2, 3, 1 ], |
| 1022 | \ [ 'eeee', 5, &columns - 3, 5, &columns - 3, 4, 1 ], |
| 1023 | \ ], |
| 1024 | \ }, |
| 1025 | \ ] |
| 1026 | |
| 1027 | for test_group in tests |
| 1028 | for test in test_group.tests |
| 1029 | let [ text, line, col, e_line, e_col, e_width, e_height ] = test |
| 1030 | let options = { |
| 1031 | \ 'line': line, |
| 1032 | \ 'col': col, |
| 1033 | \ } |
| 1034 | call extend( options, test_group.options ) |
| 1035 | |
| 1036 | let p = popup_create( text, options ) |
| 1037 | |
| 1038 | let msg = string( extend( options, { 'text': text } ) ) |
| 1039 | call s:VerifyPosition( p, msg, e_line, e_col, e_width, e_height ) |
| 1040 | call popup_close( p ) |
| 1041 | endfor |
| 1042 | endfor |
| 1043 | |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1044 | call popup_clear() |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1045 | %bwipe! |
| 1046 | endfunc |
| 1047 | |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1048 | func Test_adjust_left_past_screen_width() |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1049 | " width of screen |
| 1050 | let X = join(map(range(&columns), {->'X'}), '') |
| 1051 | |
| 1052 | let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } ) |
| 1053 | call s:VerifyPosition( p, 'full width topleft', 1, 1, &columns, 1 ) |
| 1054 | |
| 1055 | redraw |
| 1056 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1057 | call assert_equal(X, line) |
| 1058 | |
| 1059 | call popup_close( p ) |
| 1060 | redraw |
| 1061 | |
| 1062 | " Same if placed on the right hand side |
| 1063 | let p = popup_create( X, { 'line': 1, 'col': &columns, 'wrap': 0 } ) |
| 1064 | call s:VerifyPosition( p, 'full width topright', 1, 1, &columns, 1 ) |
| 1065 | |
| 1066 | redraw |
| 1067 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1068 | call assert_equal(X, line) |
| 1069 | |
| 1070 | call popup_close( p ) |
| 1071 | redraw |
| 1072 | |
| 1073 | " Extend so > window width |
| 1074 | let X .= 'x' |
| 1075 | |
| 1076 | let p = popup_create( X, { 'line': 1, 'col': 1, 'wrap': 0 } ) |
| 1077 | call s:VerifyPosition( p, 'full width + 1 topleft', 1, 1, &columns, 1 ) |
| 1078 | |
| 1079 | redraw |
| 1080 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1081 | call assert_equal(X[ : -2 ], line) |
| 1082 | |
| 1083 | call popup_close( p ) |
| 1084 | redraw |
| 1085 | |
| 1086 | " Shifted then truncated (the x is not visible) |
| 1087 | let p = popup_create( X, { 'line': 1, 'col': &columns - 3, 'wrap': 0 } ) |
| 1088 | call s:VerifyPosition( p, 'full width + 1 topright', 1, 1, &columns, 1 ) |
| 1089 | |
| 1090 | redraw |
| 1091 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1092 | call assert_equal(X[ : -2 ], line) |
| 1093 | |
| 1094 | call popup_close( p ) |
| 1095 | redraw |
| 1096 | |
| 1097 | " Not shifted, just truncated |
| 1098 | let p = popup_create( X, |
| 1099 | \ { 'line': 1, 'col': 2, 'wrap': 0, 'fixed': 1 } ) |
| 1100 | call s:VerifyPosition( p, 'full width + 1 fixed', 1, 2, &columns - 1, 1) |
| 1101 | |
| 1102 | redraw |
| 1103 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1104 | let e_line = ' ' . X[ 1 : -2 ] |
| 1105 | call assert_equal(e_line, line) |
| 1106 | |
| 1107 | call popup_close( p ) |
| 1108 | redraw |
| 1109 | |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1110 | call popup_clear() |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1111 | %bwipe! |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1112 | endfunc |
| 1113 | |
| 1114 | func Test_popup_moved() |
| 1115 | new |
| 1116 | call test_override('char_avail', 1) |
| 1117 | call setline(1, ['one word to move around', 'a WORD.and->some thing']) |
| 1118 | |
| 1119 | exe "normal gg0/word\<CR>" |
| 1120 | let winid = popup_atcursor('text', {'moved': 'any'}) |
| 1121 | redraw |
| 1122 | call assert_equal(1, popup_getpos(winid).visible) |
| 1123 | " trigger the check for last_cursormoved by going into insert mode |
| 1124 | call feedkeys("li\<Esc>", 'xt') |
| 1125 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1126 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1127 | |
| 1128 | exe "normal gg0/word\<CR>" |
| 1129 | let winid = popup_atcursor('text', {'moved': 'word'}) |
| 1130 | redraw |
| 1131 | call assert_equal(1, popup_getpos(winid).visible) |
| 1132 | call feedkeys("hi\<Esc>", 'xt') |
| 1133 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1134 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1135 | |
| 1136 | exe "normal gg0/word\<CR>" |
| 1137 | let winid = popup_atcursor('text', {'moved': 'word'}) |
| 1138 | redraw |
| 1139 | call assert_equal(1, popup_getpos(winid).visible) |
| 1140 | call feedkeys("li\<Esc>", 'xt') |
| 1141 | call assert_equal(1, popup_getpos(winid).visible) |
| 1142 | call feedkeys("ei\<Esc>", 'xt') |
| 1143 | call assert_equal(1, popup_getpos(winid).visible) |
| 1144 | call feedkeys("eli\<Esc>", 'xt') |
| 1145 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1146 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1147 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1148 | " WORD is the default |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1149 | exe "normal gg0/WORD\<CR>" |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1150 | let winid = popup_atcursor('text', {}) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1151 | redraw |
| 1152 | call assert_equal(1, popup_getpos(winid).visible) |
| 1153 | call feedkeys("eli\<Esc>", 'xt') |
| 1154 | call assert_equal(1, popup_getpos(winid).visible) |
| 1155 | call feedkeys("wi\<Esc>", 'xt') |
| 1156 | call assert_equal(1, popup_getpos(winid).visible) |
| 1157 | call feedkeys("Eli\<Esc>", 'xt') |
| 1158 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1159 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1160 | |
| 1161 | exe "normal gg0/word\<CR>" |
| 1162 | let winid = popup_atcursor('text', {'moved': [5, 10]}) |
| 1163 | redraw |
| 1164 | call assert_equal(1, popup_getpos(winid).visible) |
| 1165 | call feedkeys("eli\<Esc>", 'xt') |
| 1166 | call feedkeys("ei\<Esc>", 'xt') |
| 1167 | call assert_equal(1, popup_getpos(winid).visible) |
| 1168 | call feedkeys("eli\<Esc>", 'xt') |
| 1169 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1170 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1171 | |
| 1172 | bwipe! |
| 1173 | call test_override('ALL', 0) |
| 1174 | endfunc |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1175 | |
| 1176 | func Test_notifications() |
| 1177 | if !has('timers') |
| 1178 | throw 'Skipped, timer feature not supported' |
| 1179 | endif |
| 1180 | if !CanRunVimInTerminal() |
| 1181 | throw 'Skipped: cannot make screendumps' |
| 1182 | endif |
| 1183 | |
| 1184 | call writefile([ |
| 1185 | \ "call setline(1, range(1, 20))", |
| 1186 | \ "hi Notification ctermbg=lightblue", |
| 1187 | \ "call popup_notification('first notification', {})", |
| 1188 | \], 'XtestNotifications') |
| 1189 | let buf = RunVimInTerminal('-S XtestNotifications', {'rows': 10}) |
| 1190 | call VerifyScreenDump(buf, 'Test_popupwin_notify_01', {}) |
| 1191 | |
| 1192 | " second one goes below the first one |
| 1193 | call term_sendkeys(buf, ":call popup_notification('another important notification', {'highlight': 'Notification'})\<CR>") |
| 1194 | call VerifyScreenDump(buf, 'Test_popupwin_notify_02', {}) |
| 1195 | |
| 1196 | |
| 1197 | " clean up |
| 1198 | call StopVimInTerminal(buf) |
| 1199 | call delete('XtestNotifications') |
| 1200 | endfunc |