Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1 | " Tests for popup windows |
| 2 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | CheckFeature textprop |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 5 | |
| 6 | source screendump.vim |
| 7 | |
| 8 | func Test_simple_popup() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 9 | CheckScreendump |
| 10 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 11 | let lines =<< trim END |
| 12 | call setline(1, range(1, 100)) |
| 13 | hi PopupColor1 ctermbg=lightblue |
| 14 | hi PopupColor2 ctermbg=lightcyan |
| 15 | hi Comment ctermfg=red |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 16 | call prop_type_add('comment', #{highlight: 'Comment'}) |
| 17 | let winid = popup_create('hello there', #{line: 3, col: 11, minwidth: 20, highlight: 'PopupColor1'}) |
| 18 | let winid2 = popup_create(['another one', 'another two', 'another three'], #{line: 3, col: 25, minwidth: 20}) |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 19 | call setwinvar(winid2, '&wincolor', 'PopupColor2') |
| 20 | END |
| 21 | call writefile(lines, 'XtestPopup') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 22 | let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10}) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 23 | call VerifyScreenDump(buf, 'Test_popupwin_01', {}) |
| 24 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 25 | " Add a tabpage |
| 26 | call term_sendkeys(buf, ":tabnew\<CR>") |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 27 | call term_sendkeys(buf, ":let popupwin = popup_create([" |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 28 | \ .. "#{text: 'other tab'}," |
| 29 | \ .. "#{text: 'a comment line', props: [#{" |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 30 | \ .. "col: 3, length: 7, minwidth: 20, type: 'comment'" |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 31 | \ .. "}]}," |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 32 | \ .. "], #{line: 4, col: 9, minwidth: 20})\<CR>") |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 33 | call VerifyScreenDump(buf, 'Test_popupwin_02', {}) |
| 34 | |
| 35 | " switch back to first tabpage |
| 36 | call term_sendkeys(buf, "gt") |
| 37 | call VerifyScreenDump(buf, 'Test_popupwin_03', {}) |
| 38 | |
| 39 | " close that tabpage |
| 40 | call term_sendkeys(buf, ":quit!\<CR>") |
| 41 | call VerifyScreenDump(buf, 'Test_popupwin_04', {}) |
| 42 | |
Bram Moolenaar | 202d982 | 2019-06-11 21:56:30 +0200 | [diff] [blame] | 43 | " set 'columns' to a small value, size must be recomputed |
| 44 | call term_sendkeys(buf, ":let cols = &columns\<CR>") |
| 45 | call term_sendkeys(buf, ":set columns=12\<CR>") |
| 46 | call VerifyScreenDump(buf, 'Test_popupwin_04a', {}) |
| 47 | call term_sendkeys(buf, ":let &columns = cols\<CR>") |
| 48 | |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 49 | " resize popup, show empty line at bottom |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 50 | call term_sendkeys(buf, ":call popup_move(popupwin, #{minwidth: 15, maxwidth: 25, minheight: 3, maxheight: 5})\<CR>") |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 51 | call term_sendkeys(buf, ":redraw\<CR>") |
| 52 | call VerifyScreenDump(buf, 'Test_popupwin_05', {}) |
| 53 | |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 54 | " show not fitting line at bottom |
| 55 | call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>") |
| 56 | call term_sendkeys(buf, ":redraw\<CR>") |
| 57 | call VerifyScreenDump(buf, 'Test_popupwin_06', {}) |
| 58 | |
Bram Moolenaar | 24a5ac5 | 2019-06-08 19:01:18 +0200 | [diff] [blame] | 59 | " move popup over ruler |
| 60 | call term_sendkeys(buf, ":set cmdheight=2\<CR>") |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 61 | call term_sendkeys(buf, ":call popup_move(popupwin, #{line: 7, col: 55})\<CR>") |
Bram Moolenaar | b8be54d | 2019-07-14 18:22:59 +0200 | [diff] [blame] | 62 | call term_sendkeys(buf, ":\<CR>") |
Bram Moolenaar | 24a5ac5 | 2019-06-08 19:01:18 +0200 | [diff] [blame] | 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() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 79 | CheckScreendump |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 80 | |
Bram Moolenaar | 3bfd04e | 2019-06-01 20:45:21 +0200 | [diff] [blame] | 81 | for iter in range(0, 1) |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 82 | let lines =<< trim END |
| 83 | call setline(1, range(1, 100)) |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 84 | call popup_create('hello border', #{line: 2, col: 3, border: []}) |
| 85 | call popup_create('hello padding', #{line: 2, col: 23, padding: []}) |
Bram Moolenaar | c363fe1 | 2019-08-04 18:13:46 +0200 | [diff] [blame] | 86 | call popup_create('hello both', #{line: 2, col: 43, border: [], padding: [], highlight: 'Normal'}) |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 87 | call popup_create('border TL', #{line: 6, col: 3, border: [1, 0, 0, 4]}) |
| 88 | call popup_create('paddings', #{line: 6, col: 23, padding: [1, 3, 2, 4]}) |
| 89 | call popup_create('wrapped longer text', #{line: 8, col: 55, padding: [0, 3, 0, 3], border: [0, 1, 0, 1]}) |
| 90 | call popup_create('right aligned text', #{line: 11, col: 56, wrap: 0, padding: [0, 3, 0, 3], border: [0, 1, 0, 1]}) |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 91 | END |
| 92 | call insert(lines, iter == 1 ? '' : 'set enc=latin1') |
| 93 | call writefile(lines, 'XtestPopupBorder') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 94 | let buf = RunVimInTerminal('-S XtestPopupBorder', #{rows: 15}) |
Bram Moolenaar | 3bfd04e | 2019-06-01 20:45:21 +0200 | [diff] [blame] | 95 | call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {}) |
| 96 | |
| 97 | call StopVimInTerminal(buf) |
| 98 | call delete('XtestPopupBorder') |
| 99 | endfor |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 100 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 101 | let lines =<< trim END |
| 102 | call setline(1, range(1, 100)) |
| 103 | hi BlueColor ctermbg=lightblue |
| 104 | hi TopColor ctermbg=253 |
| 105 | hi RightColor ctermbg=245 |
| 106 | hi BottomColor ctermbg=240 |
| 107 | hi LeftColor ctermbg=248 |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 108 | call popup_create('hello border', #{line: 2, col: 3, border: [], borderhighlight: ['BlueColor']}) |
| 109 | call popup_create(['hello border', 'and more'], #{line: 2, col: 23, border: [], borderhighlight: ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']}) |
| 110 | call popup_create(['hello border', 'lines only'], #{line: 2, col: 43, border: [], borderhighlight: ['BlueColor'], borderchars: ['x']}) |
| 111 | call popup_create(['hello border', 'with corners'], #{line: 2, col: 60, border: [], borderhighlight: ['BlueColor'], borderchars: ['x', '#']}) |
| 112 | let winid = popup_create(['hello border', 'with numbers'], #{line: 6, col: 3, border: [], borderhighlight: ['BlueColor'], borderchars: ['0', '1', '2', '3', '4', '5', '6', '7']}) |
| 113 | call popup_create(['hello border', 'just blanks'], #{line: 7, col: 23, border: [], borderhighlight: ['BlueColor'], borderchars: [' ']}) |
Bram Moolenaar | 3dabd71 | 2019-07-08 23:30:22 +0200 | [diff] [blame] | 114 | func MultiByte() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 115 | call popup_create(['hello'], #{line: 8, col: 43, border: [], borderchars: ['─', '│', '─', '│', '┌', '┐', '┘', '└']}) |
Bram Moolenaar | 3dabd71 | 2019-07-08 23:30:22 +0200 | [diff] [blame] | 116 | endfunc |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 117 | END |
| 118 | call writefile(lines, 'XtestPopupBorder') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 119 | let buf = RunVimInTerminal('-S XtestPopupBorder', #{rows: 12}) |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 120 | call VerifyScreenDump(buf, 'Test_popupwin_22', {}) |
| 121 | |
Bram Moolenaar | ad24a71 | 2019-06-17 20:05:45 +0200 | [diff] [blame] | 122 | " check that changing borderchars triggers a redraw |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 123 | call term_sendkeys(buf, ":call popup_setoptions(winid, #{borderchars: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']})\<CR>") |
Bram Moolenaar | ad24a71 | 2019-06-17 20:05:45 +0200 | [diff] [blame] | 124 | call VerifyScreenDump(buf, 'Test_popupwin_23', {}) |
| 125 | |
Bram Moolenaar | 3dabd71 | 2019-07-08 23:30:22 +0200 | [diff] [blame] | 126 | " check multi-byte border only with 'ambiwidth' single |
| 127 | if &ambiwidth == 'single' |
| 128 | call term_sendkeys(buf, ":call MultiByte()\<CR>") |
| 129 | call VerifyScreenDump(buf, 'Test_popupwin_24', {}) |
| 130 | endif |
| 131 | |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 132 | call StopVimInTerminal(buf) |
| 133 | call delete('XtestPopupBorder') |
| 134 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 135 | let with_border_or_padding = #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 136 | \ line: 2, |
| 137 | \ core_line: 3, |
| 138 | \ col: 3, |
| 139 | \ core_col: 4, |
| 140 | \ width: 14, |
| 141 | \ core_width: 12, |
| 142 | \ height: 3, |
| 143 | \ core_height: 1, |
| 144 | \ firstline: 1, |
| 145 | \ scrollbar: 0, |
| 146 | \ visible: 1} |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 147 | let winid = popup_create('hello border', #{line: 2, col: 3, border: []})", |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 148 | call assert_equal(with_border_or_padding, popup_getpos(winid)) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 149 | let options = popup_getoptions(winid) |
| 150 | call assert_equal([], options.border) |
| 151 | call assert_false(has_key(options, "padding")) |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 152 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 153 | let winid = popup_create('hello padding', #{line: 2, col: 3, padding: []}) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 154 | let with_border_or_padding.width = 15 |
| 155 | let with_border_or_padding.core_width = 13 |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 156 | call assert_equal(with_border_or_padding, popup_getpos(winid)) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 157 | let options = popup_getoptions(winid) |
| 158 | call assert_false(has_key(options, "border")) |
| 159 | call assert_equal([], options.padding) |
| 160 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 161 | call popup_setoptions(winid, #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 162 | \ padding: [1, 2, 3, 4], |
| 163 | \ border: [4, 0, 7, 8], |
| 164 | \ borderhighlight: ['Top', 'Right', 'Bottom', 'Left'], |
| 165 | \ borderchars: ['1', '^', '2', '>', '3', 'v', '4', '<'], |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 166 | \ }) |
| 167 | let options = popup_getoptions(winid) |
| 168 | call assert_equal([1, 0, 1, 1], options.border) |
| 169 | call assert_equal([1, 2, 3, 4], options.padding) |
| 170 | call assert_equal(['Top', 'Right', 'Bottom', 'Left'], options.borderhighlight) |
| 171 | call assert_equal(['1', '^', '2', '>', '3', 'v', '4', '<'], options.borderchars) |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 172 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 173 | let winid = popup_create('hello both', #{line: 3, col: 8, border: [], padding: []}) |
| 174 | call assert_equal(#{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 175 | \ line: 3, |
| 176 | \ core_line: 5, |
| 177 | \ col: 8, |
| 178 | \ core_col: 10, |
| 179 | \ width: 14, |
| 180 | \ core_width: 10, |
| 181 | \ height: 5, |
| 182 | \ scrollbar: 0, |
| 183 | \ core_height: 1, |
| 184 | \ firstline: 1, |
| 185 | \ visible: 1}, popup_getpos(winid)) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 186 | |
| 187 | call popup_clear() |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 188 | endfunc |
| 189 | |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 190 | func Test_popup_with_syntax_win_execute() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 191 | CheckScreendump |
| 192 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 193 | let lines =<< trim END |
| 194 | call setline(1, range(1, 100)) |
| 195 | hi PopupColor ctermbg=lightblue |
| 196 | let winid = popup_create([ |
| 197 | \ '#include <stdio.h>', |
| 198 | \ 'int main(void)', |
| 199 | \ '{', |
| 200 | \ ' printf(123);', |
| 201 | \ '}', |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 202 | \], #{line: 3, col: 25, highlight: 'PopupColor'}) |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 203 | call win_execute(winid, 'set syntax=cpp') |
| 204 | END |
| 205 | call writefile(lines, 'XtestPopup') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 206 | let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10}) |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 207 | call VerifyScreenDump(buf, 'Test_popupwin_10', {}) |
| 208 | |
| 209 | " clean up |
| 210 | call StopVimInTerminal(buf) |
| 211 | call delete('XtestPopup') |
| 212 | endfunc |
| 213 | |
| 214 | func Test_popup_with_syntax_setbufvar() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 215 | CheckScreendump |
| 216 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 217 | let lines =<< trim END |
| 218 | call setline(1, range(1, 100)) |
| 219 | hi PopupColor ctermbg=lightgrey |
| 220 | let winid = popup_create([ |
| 221 | \ '#include <stdio.h>', |
| 222 | \ 'int main(void)', |
| 223 | \ '{', |
Bram Moolenaar | e089c3f | 2019-07-09 20:25:25 +0200 | [diff] [blame] | 224 | \ "\tprintf(567);", |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 225 | \ '}', |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 226 | \], #{line: 3, col: 21, highlight: 'PopupColor'}) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 227 | call setbufvar(winbufnr(winid), '&syntax', 'cpp') |
| 228 | END |
| 229 | call writefile(lines, 'XtestPopup') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 230 | let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10}) |
Bram Moolenaar | b423012 | 2019-05-30 18:40:53 +0200 | [diff] [blame] | 231 | call VerifyScreenDump(buf, 'Test_popupwin_11', {}) |
| 232 | |
| 233 | " clean up |
| 234 | call StopVimInTerminal(buf) |
| 235 | call delete('XtestPopup') |
| 236 | endfunc |
| 237 | |
Bram Moolenaar | ac2450a | 2019-06-09 18:04:28 +0200 | [diff] [blame] | 238 | func Test_popup_with_matches() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 239 | CheckScreendump |
| 240 | |
Bram Moolenaar | ac2450a | 2019-06-09 18:04:28 +0200 | [diff] [blame] | 241 | let lines =<< trim END |
| 242 | call setline(1, ['111 222 333', '444 555 666']) |
| 243 | let winid = popup_create([ |
| 244 | \ '111 222 333', |
| 245 | \ '444 555 666', |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 246 | \], #{line: 3, col: 10, border: []}) |
Bram Moolenaar | ac2450a | 2019-06-09 18:04:28 +0200 | [diff] [blame] | 247 | set hlsearch |
| 248 | /666 |
| 249 | call matchadd('ErrorMsg', '111') |
| 250 | call matchadd('ErrorMsg', '444') |
| 251 | call win_execute(winid, "call matchadd('ErrorMsg', '111')") |
| 252 | call win_execute(winid, "call matchadd('ErrorMsg', '555')") |
| 253 | END |
| 254 | call writefile(lines, 'XtestPopupMatches') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 255 | let buf = RunVimInTerminal('-S XtestPopupMatches', #{rows: 10}) |
Bram Moolenaar | ac2450a | 2019-06-09 18:04:28 +0200 | [diff] [blame] | 256 | call VerifyScreenDump(buf, 'Test_popupwin_matches', {}) |
| 257 | |
| 258 | " clean up |
| 259 | call StopVimInTerminal(buf) |
| 260 | call delete('XtestPopupMatches') |
| 261 | endfunc |
| 262 | |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 263 | func Test_popup_all_corners() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 264 | CheckScreendump |
| 265 | |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 266 | let lines =<< trim END |
| 267 | call setline(1, repeat([repeat('-', 60)], 15)) |
| 268 | set so=0 |
| 269 | normal 2G3|r# |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 270 | let winid1 = popup_create(['first', 'second'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 271 | \ line: 'cursor+1', |
| 272 | \ col: 'cursor', |
| 273 | \ pos: 'topleft', |
| 274 | \ border: [], |
| 275 | \ padding: [], |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 276 | \ }) |
| 277 | normal 25|r@ |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 278 | let winid1 = popup_create(['First', 'SeconD'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 279 | \ line: 'cursor+1', |
| 280 | \ col: 'cursor', |
| 281 | \ pos: 'topright', |
| 282 | \ border: [], |
| 283 | \ padding: [], |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 284 | \ }) |
| 285 | normal 9G29|r% |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 286 | let winid1 = popup_create(['fiRSt', 'seCOnd'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 287 | \ line: 'cursor-1', |
| 288 | \ col: 'cursor', |
| 289 | \ pos: 'botleft', |
| 290 | \ border: [], |
| 291 | \ padding: [], |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 292 | \ }) |
| 293 | normal 51|r& |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 294 | let winid1 = popup_create(['FIrsT', 'SEcoND'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 295 | \ line: 'cursor-1', |
| 296 | \ col: 'cursor', |
| 297 | \ pos: 'botright', |
| 298 | \ border: [], |
| 299 | \ padding: [], |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 300 | \ }) |
| 301 | END |
| 302 | call writefile(lines, 'XtestPopupCorners') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 303 | let buf = RunVimInTerminal('-S XtestPopupCorners', #{rows: 12}) |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 304 | call VerifyScreenDump(buf, 'Test_popupwin_corners', {}) |
| 305 | |
| 306 | " clean up |
| 307 | call StopVimInTerminal(buf) |
| 308 | call delete('XtestPopupCorners') |
| 309 | endfunc |
| 310 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 311 | func Test_popup_firstline() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 312 | CheckScreendump |
| 313 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 314 | let lines =<< trim END |
| 315 | call setline(1, range(1, 20)) |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 316 | call popup_create(['1111', '222222', '33333', '44', '5', '666666', '77777', '888', '9999999999999999'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 317 | \ maxheight: 4, |
| 318 | \ firstline: 3, |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 319 | \ }) |
| 320 | END |
| 321 | call writefile(lines, 'XtestPopupFirstline') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 322 | let buf = RunVimInTerminal('-S XtestPopupFirstline', #{rows: 10}) |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 323 | call VerifyScreenDump(buf, 'Test_popupwin_firstline', {}) |
| 324 | |
| 325 | " clean up |
| 326 | call StopVimInTerminal(buf) |
| 327 | call delete('XtestPopupFirstline') |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 328 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 329 | let winid = popup_create(['1111', '222222', '33333', '44444'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 330 | \ maxheight: 2, |
| 331 | \ firstline: 3, |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 332 | \ }) |
| 333 | call assert_equal(3, popup_getoptions(winid).firstline) |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 334 | call popup_setoptions(winid, #{firstline: 1}) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 335 | call assert_equal(1, popup_getoptions(winid).firstline) |
| 336 | |
| 337 | call popup_close(winid) |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 338 | endfunc |
| 339 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 340 | func Test_popup_drag() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 341 | CheckScreendump |
| 342 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 343 | " create a popup that covers the command line |
| 344 | let lines =<< trim END |
| 345 | call setline(1, range(1, 20)) |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 346 | let winid = popup_create(['1111', '222222', '33333'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 347 | \ drag: 1, |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 348 | \ resize: 1, |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 349 | \ border: [], |
| 350 | \ line: &lines - 4, |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 351 | \ }) |
| 352 | func Dragit() |
| 353 | call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt") |
| 354 | endfunc |
| 355 | map <silent> <F3> :call test_setmouse(&lines - 4, &columns / 2)<CR> |
| 356 | map <silent> <F4> :call test_setmouse(&lines - 8, &columns / 2)<CR> |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 357 | func Resize() |
| 358 | call feedkeys("\<F5>\<LeftMouse>\<F6>\<LeftDrag>\<LeftRelease>", "xt") |
| 359 | endfunc |
| 360 | map <silent> <F5> :call test_setmouse(6, 41)<CR> |
| 361 | map <silent> <F6> :call test_setmouse(7, 45)<CR> |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 362 | END |
| 363 | call writefile(lines, 'XtestPopupDrag') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 364 | let buf = RunVimInTerminal('-S XtestPopupDrag', #{rows: 10}) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 365 | call VerifyScreenDump(buf, 'Test_popupwin_drag_01', {}) |
| 366 | |
| 367 | call term_sendkeys(buf, ":call Dragit()\<CR>") |
| 368 | call VerifyScreenDump(buf, 'Test_popupwin_drag_02', {}) |
| 369 | |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 370 | call term_sendkeys(buf, ":call Resize()\<CR>") |
| 371 | call VerifyScreenDump(buf, 'Test_popupwin_drag_03', {}) |
| 372 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 373 | " clean up |
| 374 | call StopVimInTerminal(buf) |
| 375 | call delete('XtestPopupDrag') |
| 376 | endfunc |
| 377 | |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 378 | func Test_popup_close_with_mouse() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 379 | CheckScreendump |
| 380 | |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 381 | let lines =<< trim END |
| 382 | call setline(1, range(1, 20)) |
| 383 | " With border, can click on X |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 384 | let winid = popup_create('foobar', #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 385 | \ close: 'button', |
| 386 | \ border: [], |
| 387 | \ line: 1, |
| 388 | \ col: 1, |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 389 | \ }) |
| 390 | func CloseMsg(id, result) |
| 391 | echomsg 'Popup closed with ' .. a:result |
| 392 | endfunc |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 393 | let winid = popup_create('notification', #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 394 | \ close: 'click', |
| 395 | \ line: 3, |
| 396 | \ col: 15, |
| 397 | \ callback: 'CloseMsg', |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 398 | \ }) |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 399 | let winid = popup_create('no border here', #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 400 | \ close: 'button', |
| 401 | \ line: 5, |
| 402 | \ col: 3, |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 403 | \ }) |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 404 | let winid = popup_create('only padding', #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 405 | \ close: 'button', |
| 406 | \ padding: [], |
| 407 | \ line: 5, |
| 408 | \ col: 23, |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 409 | \ }) |
| 410 | func CloseWithX() |
| 411 | call feedkeys("\<F3>\<LeftMouse>\<LeftRelease>", "xt") |
| 412 | endfunc |
| 413 | map <silent> <F3> :call test_setmouse(1, len('foobar') + 2)<CR> |
| 414 | func CloseWithClick() |
| 415 | call feedkeys("\<F4>\<LeftMouse>\<LeftRelease>", "xt") |
| 416 | endfunc |
| 417 | map <silent> <F4> :call test_setmouse(3, 17)<CR> |
| 418 | END |
| 419 | call writefile(lines, 'XtestPopupClose') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 420 | let buf = RunVimInTerminal('-S XtestPopupClose', #{rows: 10}) |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 421 | call VerifyScreenDump(buf, 'Test_popupwin_close_01', {}) |
| 422 | |
| 423 | call term_sendkeys(buf, ":call CloseWithX()\<CR>") |
| 424 | call VerifyScreenDump(buf, 'Test_popupwin_close_02', {}) |
| 425 | |
| 426 | call term_sendkeys(buf, ":call CloseWithClick()\<CR>") |
| 427 | call VerifyScreenDump(buf, 'Test_popupwin_close_03', {}) |
| 428 | |
| 429 | " clean up |
| 430 | call StopVimInTerminal(buf) |
| 431 | call delete('XtestPopupClose') |
| 432 | endfunction |
| 433 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 434 | func Test_popup_with_mask() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 435 | CheckScreendump |
| 436 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 437 | let lines =<< trim END |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 438 | call setline(1, repeat([join(range(1, 42), '')], 13)) |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 439 | hi PopupColor ctermbg=lightgrey |
| 440 | let winid = popup_create([ |
| 441 | \ 'some text', |
| 442 | \ 'another line', |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 443 | \], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 444 | \ line: 1, |
| 445 | \ col: 10, |
| 446 | \ wrap: 0, |
| 447 | \ fixed: 1, |
| 448 | \ zindex: 90, |
| 449 | \ padding: [], |
| 450 | \ highlight: 'PopupColor', |
| 451 | \ mask: [[1,1,1,1], [-5,-1,4,4], [7,9,2,3], [2,4,3,3]]}) |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 452 | call popup_create([ |
| 453 | \ 'xxxxxxxxx', |
| 454 | \ 'yyyyyyyyy', |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 455 | \], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 456 | \ line: 3, |
| 457 | \ col: 18, |
| 458 | \ zindex: 20}) |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 459 | let winidb = popup_create([ |
| 460 | \ 'just one line', |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 461 | \], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 462 | \ line: 7, |
| 463 | \ col: 10, |
| 464 | \ wrap: 0, |
| 465 | \ fixed: 1, |
| 466 | \ close: 'button', |
| 467 | \ zindex: 90, |
| 468 | \ padding: [], |
| 469 | \ border: [], |
| 470 | \ mask: [[1,2,1,1], [-5,-1,4,4], [7,9,2,3], [3,5,5,5],[-7,-4,5,5]]}) |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 471 | END |
| 472 | call writefile(lines, 'XtestPopupMask') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 473 | let buf = RunVimInTerminal('-S XtestPopupMask', #{rows: 13}) |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 474 | call VerifyScreenDump(buf, 'Test_popupwin_mask_1', {}) |
| 475 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 476 | call term_sendkeys(buf, ":call popup_move(winid, #{col: 11, line: 2})\<CR>") |
| 477 | call term_sendkeys(buf, ":call popup_move(winidb, #{col: 12})\<CR>") |
Bram Moolenaar | b8be54d | 2019-07-14 18:22:59 +0200 | [diff] [blame] | 478 | call term_sendkeys(buf, ":\<CR>") |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 479 | call VerifyScreenDump(buf, 'Test_popupwin_mask_2', {}) |
| 480 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 481 | call term_sendkeys(buf, ":call popup_move(winid, #{col: 65, line: 2})\<CR>") |
| 482 | call term_sendkeys(buf, ":call popup_move(winidb, #{col: 63})\<CR>") |
Bram Moolenaar | b8be54d | 2019-07-14 18:22:59 +0200 | [diff] [blame] | 483 | call term_sendkeys(buf, ":\<CR>") |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 484 | call VerifyScreenDump(buf, 'Test_popupwin_mask_3', {}) |
| 485 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 486 | call term_sendkeys(buf, ":call popup_move(winid, #{pos: 'topright', col: 12, line: 2})\<CR>") |
| 487 | call term_sendkeys(buf, ":call popup_move(winidb, #{pos: 'topright', col: 12})\<CR>") |
Bram Moolenaar | b8be54d | 2019-07-14 18:22:59 +0200 | [diff] [blame] | 488 | call term_sendkeys(buf, ":\<CR>") |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 489 | call VerifyScreenDump(buf, 'Test_popupwin_mask_4', {}) |
| 490 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 491 | call term_sendkeys(buf, ":call popup_move(winid, #{pos: 'topright', col: 12, line: 11})\<CR>") |
| 492 | call term_sendkeys(buf, ":call popup_move(winidb, #{pos: 'topleft', col: 42, line: 11})\<CR>") |
Bram Moolenaar | b8be54d | 2019-07-14 18:22:59 +0200 | [diff] [blame] | 493 | call term_sendkeys(buf, ":\<CR>") |
Bram Moolenaar | b420747 | 2019-07-12 16:05:45 +0200 | [diff] [blame] | 494 | call VerifyScreenDump(buf, 'Test_popupwin_mask_5', {}) |
| 495 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 496 | " clean up |
| 497 | call StopVimInTerminal(buf) |
| 498 | call delete('XtestPopupMask') |
| 499 | endfunc |
| 500 | |
Bram Moolenaar | bd75b53 | 2019-06-14 23:41:55 +0200 | [diff] [blame] | 501 | func Test_popup_select() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 502 | CheckScreendump |
| 503 | CheckFeature clipboard_working |
| 504 | |
Bram Moolenaar | bd75b53 | 2019-06-14 23:41:55 +0200 | [diff] [blame] | 505 | " create a popup with some text to be selected |
| 506 | let lines =<< trim END |
Bram Moolenaar | 1755ec4 | 2019-06-15 13:13:54 +0200 | [diff] [blame] | 507 | set clipboard=autoselect |
Bram Moolenaar | bd75b53 | 2019-06-14 23:41:55 +0200 | [diff] [blame] | 508 | call setline(1, range(1, 20)) |
Bram Moolenaar | 4dd751b | 2019-08-17 19:10:53 +0200 | [diff] [blame] | 509 | let winid = popup_create(['the word', 'some more', 'several words here', 'invisible', '5', '6', '7'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 510 | \ drag: 1, |
| 511 | \ border: [], |
| 512 | \ line: 3, |
| 513 | \ col: 10, |
Bram Moolenaar | 4dd751b | 2019-08-17 19:10:53 +0200 | [diff] [blame] | 514 | \ maxheight: 3, |
Bram Moolenaar | bd75b53 | 2019-06-14 23:41:55 +0200 | [diff] [blame] | 515 | \ }) |
| 516 | func Select1() |
| 517 | call feedkeys("\<F3>\<LeftMouse>\<F4>\<LeftDrag>\<LeftRelease>", "xt") |
| 518 | endfunc |
| 519 | map <silent> <F3> :call test_setmouse(4, 15)<CR> |
| 520 | map <silent> <F4> :call test_setmouse(6, 23)<CR> |
| 521 | END |
| 522 | call writefile(lines, 'XtestPopupSelect') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 523 | let buf = RunVimInTerminal('-S XtestPopupSelect', #{rows: 10}) |
Bram Moolenaar | bd75b53 | 2019-06-14 23:41:55 +0200 | [diff] [blame] | 524 | call term_sendkeys(buf, ":call Select1()\<CR>") |
| 525 | call VerifyScreenDump(buf, 'Test_popupwin_select_01', {}) |
| 526 | |
| 527 | call term_sendkeys(buf, ":call popup_close(winid)\<CR>") |
| 528 | call term_sendkeys(buf, "\"*p") |
Bram Moolenaar | 8ccabf6 | 2019-07-12 18:12:51 +0200 | [diff] [blame] | 529 | " clean the command line, sometimes it still shows a command |
| 530 | call term_sendkeys(buf, ":\<esc>") |
| 531 | |
Bram Moolenaar | bd75b53 | 2019-06-14 23:41:55 +0200 | [diff] [blame] | 532 | call VerifyScreenDump(buf, 'Test_popupwin_select_02', {}) |
| 533 | |
| 534 | " clean up |
| 535 | call StopVimInTerminal(buf) |
| 536 | call delete('XtestPopupSelect') |
| 537 | endfunc |
| 538 | |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 539 | func Test_popup_in_tab() |
| 540 | " default popup is local to tab, not visible when in other tab |
| 541 | let winid = popup_create("text", {}) |
Bram Moolenaar | 7c7f01e | 2019-06-12 21:06:32 +0200 | [diff] [blame] | 542 | let bufnr = winbufnr(winid) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 543 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 544 | call assert_equal(0, popup_getoptions(winid).tabpage) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 545 | tabnew |
| 546 | call assert_equal(0, popup_getpos(winid).visible) |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 547 | call assert_equal(1, popup_getoptions(winid).tabpage) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 548 | quit |
| 549 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 7c7f01e | 2019-06-12 21:06:32 +0200 | [diff] [blame] | 550 | |
| 551 | call assert_equal(1, bufexists(bufnr)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 552 | call popup_clear() |
Bram Moolenaar | 7c7f01e | 2019-06-12 21:06:32 +0200 | [diff] [blame] | 553 | " buffer is gone now |
| 554 | call assert_equal(0, bufexists(bufnr)) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 555 | |
| 556 | " global popup is visible in any tab |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 557 | let winid = popup_create("text", #{tabpage: -1}) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 558 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 559 | call assert_equal(-1, popup_getoptions(winid).tabpage) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 560 | tabnew |
| 561 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 562 | call assert_equal(-1, popup_getoptions(winid).tabpage) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 563 | quit |
| 564 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 565 | call popup_clear() |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 566 | |
| 567 | " create popup in other tab |
| 568 | tabnew |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 569 | let winid = popup_create("text", #{tabpage: 1}) |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 570 | call assert_equal(0, popup_getpos(winid).visible) |
| 571 | call assert_equal(1, popup_getoptions(winid).tabpage) |
| 572 | quit |
| 573 | call assert_equal(1, popup_getpos(winid).visible) |
| 574 | call assert_equal(0, popup_getoptions(winid).tabpage) |
| 575 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 576 | endfunc |
| 577 | |
| 578 | func Test_popup_valid_arguments() |
| 579 | " Zero value is like the property wasn't there |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 580 | let winid = popup_create("text", #{col: 0}) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 581 | let pos = popup_getpos(winid) |
| 582 | call assert_inrange(&columns / 2 - 1, &columns / 2 + 1, pos.col) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 583 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 584 | |
| 585 | " using cursor column has minimum value of 1 |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 586 | let winid = popup_create("text", #{col: 'cursor-100'}) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 587 | let pos = popup_getpos(winid) |
| 588 | call assert_equal(1, pos.col) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 589 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 590 | |
| 591 | " center |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 592 | let winid = popup_create("text", #{pos: 'center'}) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 593 | let pos = popup_getpos(winid) |
| 594 | let around = (&columns - pos.width) / 2 |
| 595 | call assert_inrange(around - 1, around + 1, pos.col) |
| 596 | let around = (&lines - pos.height) / 2 |
| 597 | call assert_inrange(around - 1, around + 1, pos.line) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 598 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 599 | endfunc |
| 600 | |
| 601 | func Test_popup_invalid_arguments() |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 602 | call assert_fails('call popup_create(666, {})', 'E86:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 603 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 604 | call assert_fails('call popup_create("text", "none")', 'E715:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 605 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 606 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 607 | call assert_fails('call popup_create("text", #{col: "xxx"})', 'E475:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 608 | call popup_clear() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 609 | call assert_fails('call popup_create("text", #{col: "cursor8"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 610 | call popup_clear() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 611 | call assert_fails('call popup_create("text", #{col: "cursor+x"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 612 | call popup_clear() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 613 | call assert_fails('call popup_create("text", #{col: "cursor+8x"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 614 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 615 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 616 | call assert_fails('call popup_create("text", #{line: "xxx"})', 'E475:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 617 | call popup_clear() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 618 | call assert_fails('call popup_create("text", #{line: "cursor8"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 619 | call popup_clear() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 620 | call assert_fails('call popup_create("text", #{line: "cursor+x"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 621 | call popup_clear() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 622 | call assert_fails('call popup_create("text", #{line: "cursor+8x"})', 'E15:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 623 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 624 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 625 | call assert_fails('call popup_create("text", #{pos: "there"})', 'E475:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 626 | call popup_clear() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 627 | call assert_fails('call popup_create("text", #{padding: "none"})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 628 | call popup_clear() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 629 | call assert_fails('call popup_create("text", #{border: "none"})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 630 | call popup_clear() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 631 | call assert_fails('call popup_create("text", #{borderhighlight: "none"})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 632 | call popup_clear() |
Bram Moolenaar | 403d090 | 2019-07-17 21:37:32 +0200 | [diff] [blame] | 633 | call assert_fails('call popup_create("text", #{borderhighlight: test_null_list()})', 'E714:') |
| 634 | call popup_clear() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 635 | call assert_fails('call popup_create("text", #{borderchars: "none"})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 636 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 637 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 638 | call assert_fails('call popup_create([#{text: "text"}, 666], {})', 'E715:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 639 | call popup_clear() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 640 | call assert_fails('call popup_create([#{text: "text", props: "none"}], {})', 'E714:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 641 | call popup_clear() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 642 | call assert_fails('call popup_create([#{text: "text", props: ["none"]}], {})', 'E715:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 643 | call popup_clear() |
Bram Moolenaar | cfdbc5a | 2019-07-17 21:27:52 +0200 | [diff] [blame] | 644 | call assert_fails('call popup_create("text", #{mask: ["asdf"]})', 'E475:') |
| 645 | call popup_clear() |
| 646 | call assert_fails('call popup_create("text", #{mask: test_null_list()})', 'E475:') |
Bram Moolenaar | 749fa0a | 2019-08-03 16:18:07 +0200 | [diff] [blame] | 647 | call assert_fails('call popup_create("text", #{mapping: []})', 'E745:') |
Bram Moolenaar | cfdbc5a | 2019-07-17 21:27:52 +0200 | [diff] [blame] | 648 | call popup_clear() |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 649 | endfunc |
| 650 | |
Bram Moolenaar | eea1699 | 2019-05-31 17:34:48 +0200 | [diff] [blame] | 651 | func Test_win_execute_closing_curwin() |
| 652 | split |
| 653 | let winid = popup_create('some text', {}) |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 654 | call assert_fails('call win_execute(winid, winnr() .. "close")', 'E994') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 655 | call popup_clear() |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 656 | endfunc |
| 657 | |
| 658 | func Test_win_execute_not_allowed() |
| 659 | let winid = popup_create('some text', {}) |
| 660 | call assert_fails('call win_execute(winid, "split")', 'E994:') |
| 661 | call assert_fails('call win_execute(winid, "vsplit")', 'E994:') |
| 662 | call assert_fails('call win_execute(winid, "close")', 'E994:') |
| 663 | call assert_fails('call win_execute(winid, "bdelete")', 'E994:') |
Bram Moolenaar | 2d24784 | 2019-06-01 17:06:25 +0200 | [diff] [blame] | 664 | call assert_fails('call win_execute(winid, "bwipe!")', 'E994:') |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 665 | call assert_fails('call win_execute(winid, "tabnew")', 'E994:') |
| 666 | call assert_fails('call win_execute(winid, "tabnext")', 'E994:') |
| 667 | call assert_fails('call win_execute(winid, "next")', 'E994:') |
| 668 | call assert_fails('call win_execute(winid, "rewind")', 'E994:') |
| 669 | call assert_fails('call win_execute(winid, "buf")', 'E994:') |
| 670 | call assert_fails('call win_execute(winid, "edit")', 'E994:') |
| 671 | call assert_fails('call win_execute(winid, "enew")', 'E994:') |
| 672 | call assert_fails('call win_execute(winid, "wincmd x")', 'E994:') |
| 673 | call assert_fails('call win_execute(winid, "wincmd w")', 'E994:') |
| 674 | call assert_fails('call win_execute(winid, "wincmd t")', 'E994:') |
| 675 | call assert_fails('call win_execute(winid, "wincmd b")', 'E994:') |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 676 | call popup_clear() |
Bram Moolenaar | eea1699 | 2019-05-31 17:34:48 +0200 | [diff] [blame] | 677 | endfunc |
| 678 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 679 | func Test_popup_with_wrap() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 680 | CheckScreendump |
| 681 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 682 | let lines =<< trim END |
| 683 | call setline(1, range(1, 100)) |
| 684 | let winid = popup_create( |
| 685 | \ 'a long line that wont fit', |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 686 | \ #{line: 3, col: 20, maxwidth: 10, wrap: 1}) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 687 | END |
| 688 | call writefile(lines, 'XtestPopup') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 689 | let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10}) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 690 | call VerifyScreenDump(buf, 'Test_popupwin_wrap', {}) |
| 691 | |
| 692 | " clean up |
| 693 | call StopVimInTerminal(buf) |
| 694 | call delete('XtestPopup') |
| 695 | endfunc |
| 696 | |
| 697 | func Test_popup_without_wrap() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 698 | CheckScreendump |
| 699 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 700 | let lines =<< trim END |
| 701 | call setline(1, range(1, 100)) |
| 702 | let winid = popup_create( |
| 703 | \ 'a long line that wont fit', |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 704 | \ #{line: 3, col: 20, maxwidth: 10, wrap: 0}) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 705 | END |
| 706 | call writefile(lines, 'XtestPopup') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 707 | let buf = RunVimInTerminal('-S XtestPopup', #{rows: 10}) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 708 | call VerifyScreenDump(buf, 'Test_popupwin_nowrap', {}) |
| 709 | |
| 710 | " clean up |
| 711 | call StopVimInTerminal(buf) |
| 712 | call delete('XtestPopup') |
| 713 | endfunc |
| 714 | |
Bram Moolenaar | 331bafd | 2019-07-20 17:46:05 +0200 | [diff] [blame] | 715 | func Test_popup_with_showbreak() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 716 | CheckScreendump |
| 717 | |
Bram Moolenaar | 331bafd | 2019-07-20 17:46:05 +0200 | [diff] [blame] | 718 | let lines =<< trim END |
| 719 | set showbreak=>>\ |
| 720 | call setline(1, range(1, 20)) |
| 721 | let winid = popup_dialog( |
| 722 | \ 'a long line here', |
| 723 | \ #{filter: 'popup_filter_yesno'}) |
| 724 | END |
| 725 | call writefile(lines, 'XtestPopupShowbreak') |
| 726 | let buf = RunVimInTerminal('-S XtestPopupShowbreak', #{rows: 10}) |
| 727 | call VerifyScreenDump(buf, 'Test_popupwin_showbreak', {}) |
| 728 | |
| 729 | " clean up |
| 730 | call term_sendkeys(buf, "y") |
| 731 | call StopVimInTerminal(buf) |
| 732 | call delete('XtestPopupShowbreak') |
| 733 | endfunc |
| 734 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 735 | func Test_popup_time() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 736 | CheckFeature timers |
| 737 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 738 | topleft vnew |
| 739 | call setline(1, 'hello') |
| 740 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 741 | let winid = popup_create('world', #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 742 | \ line: 1, |
| 743 | \ col: 1, |
| 744 | \ minwidth: 20, |
| 745 | \ time: 500, |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 746 | \}) |
| 747 | redraw |
| 748 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 749 | call assert_equal('world', line) |
| 750 | |
Bram Moolenaar | b4f0628 | 2019-07-12 21:07:54 +0200 | [diff] [blame] | 751 | call assert_equal(winid, popup_locate(1, 1)) |
| 752 | call assert_equal(winid, popup_locate(1, 20)) |
| 753 | call assert_equal(0, popup_locate(1, 21)) |
| 754 | call assert_equal(0, popup_locate(2, 1)) |
| 755 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 756 | sleep 700m |
Bram Moolenaar | 35d5af6 | 2019-05-26 20:44:10 +0200 | [diff] [blame] | 757 | redraw |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 758 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 759 | call assert_equal('hello', line) |
| 760 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 761 | call popup_create('on the command line', #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 762 | \ line: &lines, |
| 763 | \ col: 10, |
| 764 | \ minwidth: 20, |
| 765 | \ time: 500, |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 766 | \}) |
| 767 | redraw |
| 768 | let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '') |
| 769 | call assert_match('.*on the command line.*', line) |
| 770 | |
| 771 | sleep 700m |
| 772 | redraw |
| 773 | let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '') |
| 774 | call assert_notmatch('.*on the command line.*', line) |
| 775 | |
| 776 | bwipe! |
| 777 | endfunc |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 778 | |
| 779 | func Test_popup_hide() |
| 780 | topleft vnew |
| 781 | call setline(1, 'hello') |
| 782 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 783 | let winid = popup_create('world', #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 784 | \ line: 1, |
| 785 | \ col: 1, |
| 786 | \ minwidth: 20, |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 787 | \}) |
| 788 | redraw |
| 789 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 790 | call assert_equal('world', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 791 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 792 | " buffer is still listed and active |
| 793 | call assert_match(winbufnr(winid) .. 'u a.*\[Popup\]', execute('ls u')) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 794 | |
| 795 | call popup_hide(winid) |
| 796 | redraw |
| 797 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 798 | call assert_equal('hello', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 799 | call assert_equal(0, popup_getpos(winid).visible) |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 800 | " buffer is still listed but hidden |
| 801 | call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u')) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 802 | |
| 803 | call popup_show(winid) |
| 804 | redraw |
| 805 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 806 | call assert_equal('world', line) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 807 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 808 | |
| 809 | |
| 810 | call popup_close(winid) |
| 811 | redraw |
| 812 | let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '') |
| 813 | call assert_equal('hello', line) |
| 814 | |
| 815 | " error is given for existing non-popup window |
| 816 | call assert_fails('call popup_hide(win_getid())', 'E993:') |
| 817 | |
| 818 | " no error non-existing window |
| 819 | call popup_hide(1234234) |
| 820 | call popup_show(41234234) |
| 821 | |
| 822 | bwipe! |
| 823 | endfunc |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 824 | |
| 825 | func Test_popup_move() |
| 826 | topleft vnew |
| 827 | call setline(1, 'hello') |
| 828 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 829 | let winid = popup_create('world', #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 830 | \ line: 1, |
| 831 | \ col: 1, |
| 832 | \ minwidth: 20, |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 833 | \}) |
| 834 | redraw |
| 835 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 836 | call assert_equal('world ', line) |
| 837 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 838 | call popup_move(winid, #{line: 2, col: 2}) |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 839 | redraw |
| 840 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 841 | call assert_equal('hello ', line) |
| 842 | let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '') |
| 843 | call assert_equal('~world', line) |
| 844 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 845 | call popup_move(winid, #{line: 1}) |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 846 | redraw |
| 847 | let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '') |
| 848 | call assert_equal('hworld', line) |
| 849 | |
| 850 | call popup_close(winid) |
| 851 | |
| 852 | bwipe! |
| 853 | endfunc |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 854 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 855 | func Test_popup_getpos() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 856 | let winid = popup_create('hello', #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 857 | \ line: 2, |
| 858 | \ col: 3, |
| 859 | \ minwidth: 10, |
| 860 | \ minheight: 11, |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 861 | \}) |
| 862 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 863 | let res = popup_getpos(winid) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 864 | call assert_equal(2, res.line) |
| 865 | call assert_equal(3, res.col) |
| 866 | call assert_equal(10, res.width) |
| 867 | call assert_equal(11, res.height) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 868 | call assert_equal(1, res.visible) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 869 | |
| 870 | call popup_close(winid) |
| 871 | endfunc |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 872 | |
| 873 | func Test_popup_width_longest() |
| 874 | let tests = [ |
| 875 | \ [['hello', 'this', 'window', 'displays', 'all of its text'], 15], |
| 876 | \ [['hello', 'this', 'window', 'all of its text', 'displays'], 15], |
| 877 | \ [['hello', 'this', 'all of its text', 'window', 'displays'], 15], |
| 878 | \ [['hello', 'all of its text', 'this', 'window', 'displays'], 15], |
| 879 | \ [['all of its text', 'hello', 'this', 'window', 'displays'], 15], |
| 880 | \ ] |
| 881 | |
| 882 | for test in tests |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 883 | let winid = popup_create(test[0], #{line: 2, col: 3}) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 884 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 885 | let position = popup_getpos(winid) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 886 | call assert_equal(test[1], position.width) |
| 887 | call popup_close(winid) |
| 888 | endfor |
| 889 | endfunc |
| 890 | |
| 891 | func Test_popup_wraps() |
| 892 | let tests = [ |
| 893 | \ ['nowrap', 6, 1], |
| 894 | \ ['a line that wraps once', 12, 2], |
| 895 | \ ['a line that wraps two times', 12, 3], |
| 896 | \ ] |
| 897 | for test in tests |
| 898 | let winid = popup_create(test[0], |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 899 | \ #{line: 2, col: 3, maxwidth: 12}) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 900 | redraw |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 901 | let position = popup_getpos(winid) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 902 | call assert_equal(test[1], position.width) |
| 903 | call assert_equal(test[2], position.height) |
| 904 | |
| 905 | call popup_close(winid) |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 906 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 907 | endfor |
| 908 | endfunc |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 909 | |
| 910 | func Test_popup_getoptions() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 911 | let winid = popup_create('hello', #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 912 | \ line: 2, |
| 913 | \ col: 3, |
| 914 | \ minwidth: 10, |
| 915 | \ minheight: 11, |
| 916 | \ maxwidth: 20, |
| 917 | \ maxheight: 21, |
| 918 | \ zindex: 100, |
| 919 | \ time: 5000, |
| 920 | \ fixed: 1 |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 921 | \}) |
| 922 | redraw |
| 923 | let res = popup_getoptions(winid) |
| 924 | call assert_equal(2, res.line) |
| 925 | call assert_equal(3, res.col) |
| 926 | call assert_equal(10, res.minwidth) |
| 927 | call assert_equal(11, res.minheight) |
| 928 | call assert_equal(20, res.maxwidth) |
| 929 | call assert_equal(21, res.maxheight) |
| 930 | call assert_equal(100, res.zindex) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 931 | call assert_equal(1, res.fixed) |
Bram Moolenaar | b8350ab | 2019-08-04 17:59:49 +0200 | [diff] [blame] | 932 | call assert_equal(1, res.mapping) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 933 | if has('timers') |
| 934 | call assert_equal(5000, res.time) |
| 935 | endif |
| 936 | call popup_close(winid) |
| 937 | |
| 938 | let winid = popup_create('hello', {}) |
| 939 | redraw |
| 940 | let res = popup_getoptions(winid) |
| 941 | call assert_equal(0, res.line) |
| 942 | call assert_equal(0, res.col) |
| 943 | call assert_equal(0, res.minwidth) |
| 944 | call assert_equal(0, res.minheight) |
| 945 | call assert_equal(0, res.maxwidth) |
| 946 | call assert_equal(0, res.maxheight) |
| 947 | call assert_equal(50, res.zindex) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 948 | call assert_equal(0, res.fixed) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 949 | if has('timers') |
| 950 | call assert_equal(0, res.time) |
| 951 | endif |
| 952 | call popup_close(winid) |
| 953 | call assert_equal({}, popup_getoptions(winid)) |
| 954 | endfunc |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 955 | |
| 956 | func Test_popup_option_values() |
| 957 | new |
| 958 | " window-local |
| 959 | setlocal number |
| 960 | setlocal nowrap |
| 961 | " buffer-local |
| 962 | setlocal omnifunc=Something |
| 963 | " global/buffer-local |
| 964 | setlocal path=/there |
| 965 | " global/window-local |
| 966 | setlocal scrolloff=9 |
| 967 | |
| 968 | let winid = popup_create('hello', {}) |
| 969 | call assert_equal(0, getwinvar(winid, '&number')) |
| 970 | call assert_equal(1, getwinvar(winid, '&wrap')) |
| 971 | call assert_equal('', getwinvar(winid, '&omnifunc')) |
| 972 | call assert_equal(&g:path, getwinvar(winid, '&path')) |
| 973 | call assert_equal(&g:scrolloff, getwinvar(winid, '&scrolloff')) |
| 974 | |
| 975 | call popup_close(winid) |
| 976 | bwipe |
| 977 | endfunc |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 978 | |
| 979 | func Test_popup_atcursor() |
| 980 | topleft vnew |
| 981 | call setline(1, [ |
| 982 | \ 'xxxxxxxxxxxxxxxxx', |
| 983 | \ 'xxxxxxxxxxxxxxxxx', |
| 984 | \ 'xxxxxxxxxxxxxxxxx', |
| 985 | \]) |
| 986 | |
| 987 | call cursor(2, 2) |
| 988 | redraw |
| 989 | let winid = popup_atcursor('vim', {}) |
| 990 | redraw |
| 991 | let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
| 992 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 993 | call popup_close(winid) |
| 994 | |
| 995 | call cursor(3, 4) |
| 996 | redraw |
| 997 | let winid = popup_atcursor('vim', {}) |
| 998 | redraw |
| 999 | let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '') |
| 1000 | call assert_equal('xxxvimxxxxxxxxxxx', line) |
| 1001 | call popup_close(winid) |
| 1002 | |
| 1003 | call cursor(1, 1) |
| 1004 | redraw |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1005 | let winid = popup_create('vim', #{ |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1006 | \ line: 'cursor+2', |
| 1007 | \ col: 'cursor+1', |
| 1008 | \}) |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1009 | redraw |
| 1010 | let line = join(map(range(1, 17), 'screenstring(3, v:val)'), '') |
| 1011 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 1012 | call popup_close(winid) |
| 1013 | |
| 1014 | call cursor(3, 3) |
| 1015 | redraw |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1016 | let winid = popup_create('vim', #{ |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1017 | \ line: 'cursor-2', |
| 1018 | \ col: 'cursor-1', |
| 1019 | \}) |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1020 | redraw |
| 1021 | let line = join(map(range(1, 17), 'screenstring(1, v:val)'), '') |
| 1022 | call assert_equal('xvimxxxxxxxxxxxxx', line) |
| 1023 | call popup_close(winid) |
| 1024 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 1025 | " just enough room above |
| 1026 | call cursor(3, 3) |
| 1027 | redraw |
| 1028 | let winid = popup_atcursor(['vim', 'is great'], {}) |
| 1029 | redraw |
| 1030 | let pos = popup_getpos(winid) |
| 1031 | call assert_equal(1, pos.line) |
| 1032 | call popup_close(winid) |
| 1033 | |
| 1034 | " not enough room above, popup goes below the cursor |
| 1035 | call cursor(3, 3) |
| 1036 | redraw |
| 1037 | let winid = popup_atcursor(['vim', 'is', 'great'], {}) |
| 1038 | redraw |
| 1039 | let pos = popup_getpos(winid) |
| 1040 | call assert_equal(4, pos.line) |
| 1041 | call popup_close(winid) |
| 1042 | |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 1043 | " cursor in first line, popup in line 2 |
| 1044 | call cursor(1, 1) |
| 1045 | redraw |
| 1046 | let winid = popup_atcursor(['vim', 'is', 'great'], {}) |
| 1047 | redraw |
| 1048 | let pos = popup_getpos(winid) |
| 1049 | call assert_equal(2, pos.line) |
| 1050 | call popup_close(winid) |
| 1051 | |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1052 | bwipe! |
| 1053 | endfunc |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1054 | |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1055 | func Test_popup_beval() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 1056 | CheckScreendump |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1057 | |
| 1058 | let lines =<< trim END |
| 1059 | call setline(1, range(1, 20)) |
| 1060 | call setline(5, 'here is some text to hover over') |
| 1061 | set balloonevalterm |
| 1062 | set balloonexpr=BalloonExpr() |
| 1063 | set balloondelay=100 |
| 1064 | func BalloonExpr() |
| 1065 | let s:winid = popup_beval([v:beval_text], {}) |
| 1066 | return '' |
| 1067 | endfunc |
| 1068 | func Hover() |
| 1069 | call test_setmouse(5, 15) |
| 1070 | call feedkeys("\<MouseMove>\<Ignore>", "xt") |
| 1071 | sleep 100m |
| 1072 | endfunc |
| 1073 | func MoveOntoPopup() |
| 1074 | call test_setmouse(4, 17) |
| 1075 | call feedkeys("\<F4>\<MouseMove>\<Ignore>", "xt") |
| 1076 | endfunc |
| 1077 | func MoveAway() |
| 1078 | call test_setmouse(5, 13) |
| 1079 | call feedkeys("\<F5>\<MouseMove>\<Ignore>", "xt") |
| 1080 | endfunc |
| 1081 | END |
| 1082 | call writefile(lines, 'XtestPopupBeval') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1083 | let buf = RunVimInTerminal('-S XtestPopupBeval', #{rows: 10}) |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1084 | call term_wait(buf, 100) |
| 1085 | call term_sendkeys(buf, 'j') |
| 1086 | call term_sendkeys(buf, ":call Hover()\<CR>") |
| 1087 | call VerifyScreenDump(buf, 'Test_popupwin_beval_1', {}) |
| 1088 | |
| 1089 | call term_sendkeys(buf, ":call MoveOntoPopup()\<CR>") |
| 1090 | call VerifyScreenDump(buf, 'Test_popupwin_beval_2', {}) |
| 1091 | |
| 1092 | call term_sendkeys(buf, ":call MoveAway()\<CR>") |
| 1093 | call VerifyScreenDump(buf, 'Test_popupwin_beval_3', {}) |
| 1094 | |
| 1095 | " clean up |
| 1096 | call StopVimInTerminal(buf) |
| 1097 | call delete('XtestPopupBeval') |
| 1098 | endfunc |
| 1099 | |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1100 | func Test_popup_filter() |
| 1101 | new |
| 1102 | call setline(1, 'some text') |
| 1103 | |
| 1104 | func MyPopupFilter(winid, c) |
| 1105 | if a:c == 'e' |
| 1106 | let g:eaten = 'e' |
| 1107 | return 1 |
| 1108 | endif |
| 1109 | if a:c == '0' |
| 1110 | let g:ignored = '0' |
| 1111 | return 0 |
| 1112 | endif |
| 1113 | if a:c == 'x' |
| 1114 | call popup_close(a:winid) |
| 1115 | return 1 |
| 1116 | endif |
| 1117 | return 0 |
| 1118 | endfunc |
| 1119 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1120 | let winid = popup_create('something', #{filter: 'MyPopupFilter'}) |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1121 | redraw |
| 1122 | |
| 1123 | " e is consumed by the filter |
| 1124 | call feedkeys('e', 'xt') |
| 1125 | call assert_equal('e', g:eaten) |
| 1126 | |
| 1127 | " 0 is ignored by the filter |
| 1128 | normal $ |
| 1129 | call assert_equal(9, getcurpos()[2]) |
| 1130 | call feedkeys('0', 'xt') |
| 1131 | call assert_equal('0', g:ignored) |
| 1132 | call assert_equal(1, getcurpos()[2]) |
| 1133 | |
| 1134 | " x closes the popup |
| 1135 | call feedkeys('x', 'xt') |
| 1136 | call assert_equal('e', g:eaten) |
| 1137 | call assert_equal(-1, winbufnr(winid)) |
| 1138 | |
| 1139 | delfunc MyPopupFilter |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1140 | call popup_clear() |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1141 | endfunc |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1142 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1143 | func ShowDialog(key, result) |
| 1144 | let s:cb_res = 999 |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1145 | let winid = popup_dialog('do you want to quit (Yes/no)?', #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 1146 | \ filter: 'popup_filter_yesno', |
| 1147 | \ callback: 'QuitCallback', |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1148 | \ }) |
| 1149 | redraw |
| 1150 | call feedkeys(a:key, "xt") |
| 1151 | call assert_equal(winid, s:cb_winid) |
| 1152 | call assert_equal(a:result, s:cb_res) |
| 1153 | endfunc |
| 1154 | |
| 1155 | func Test_popup_dialog() |
| 1156 | func QuitCallback(id, res) |
| 1157 | let s:cb_winid = a:id |
| 1158 | let s:cb_res = a:res |
| 1159 | endfunc |
| 1160 | |
| 1161 | let winid = ShowDialog("y", 1) |
| 1162 | let winid = ShowDialog("Y", 1) |
| 1163 | let winid = ShowDialog("n", 0) |
| 1164 | let winid = ShowDialog("N", 0) |
| 1165 | let winid = ShowDialog("x", 0) |
| 1166 | let winid = ShowDialog("X", 0) |
| 1167 | let winid = ShowDialog("\<Esc>", 0) |
| 1168 | let winid = ShowDialog("\<C-C>", -1) |
| 1169 | |
| 1170 | delfunc QuitCallback |
| 1171 | endfunc |
| 1172 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1173 | func ShowMenu(key, result) |
| 1174 | let s:cb_res = 999 |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1175 | let winid = popup_menu(['one', 'two', 'something else'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 1176 | \ callback: 'QuitCallback', |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1177 | \ }) |
| 1178 | redraw |
| 1179 | call feedkeys(a:key, "xt") |
| 1180 | call assert_equal(winid, s:cb_winid) |
| 1181 | call assert_equal(a:result, s:cb_res) |
| 1182 | endfunc |
| 1183 | |
| 1184 | func Test_popup_menu() |
| 1185 | func QuitCallback(id, res) |
| 1186 | let s:cb_winid = a:id |
| 1187 | let s:cb_res = a:res |
| 1188 | endfunc |
Bram Moolenaar | 749fa0a | 2019-08-03 16:18:07 +0200 | [diff] [blame] | 1189 | " mapping won't be used in popup |
| 1190 | map j k |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1191 | |
| 1192 | let winid = ShowMenu(" ", 1) |
| 1193 | let winid = ShowMenu("j \<CR>", 2) |
| 1194 | let winid = ShowMenu("JjK \<CR>", 2) |
| 1195 | let winid = ShowMenu("jjjjjj ", 3) |
| 1196 | let winid = ShowMenu("kkk ", 1) |
| 1197 | let winid = ShowMenu("x", -1) |
| 1198 | let winid = ShowMenu("X", -1) |
| 1199 | let winid = ShowMenu("\<Esc>", -1) |
| 1200 | let winid = ShowMenu("\<C-C>", -1) |
| 1201 | |
| 1202 | delfunc QuitCallback |
Bram Moolenaar | 749fa0a | 2019-08-03 16:18:07 +0200 | [diff] [blame] | 1203 | unmap j |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1204 | endfunc |
| 1205 | |
| 1206 | func Test_popup_menu_screenshot() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 1207 | CheckScreendump |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1208 | |
| 1209 | let lines =<< trim END |
| 1210 | call setline(1, range(1, 20)) |
| 1211 | hi PopupSelected ctermbg=lightblue |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1212 | call popup_menu(['one', 'two', 'another'], #{callback: 'MenuDone', title: ' make a choice from the list '}) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1213 | func MenuDone(id, res) |
| 1214 | echomsg "selected " .. a:res |
| 1215 | endfunc |
| 1216 | END |
| 1217 | call writefile(lines, 'XtestPopupMenu') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1218 | let buf = RunVimInTerminal('-S XtestPopupMenu', #{rows: 10}) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1219 | call VerifyScreenDump(buf, 'Test_popupwin_menu_01', {}) |
| 1220 | |
| 1221 | call term_sendkeys(buf, "jj") |
| 1222 | call VerifyScreenDump(buf, 'Test_popupwin_menu_02', {}) |
| 1223 | |
| 1224 | call term_sendkeys(buf, " ") |
| 1225 | call VerifyScreenDump(buf, 'Test_popupwin_menu_03', {}) |
| 1226 | |
| 1227 | " clean up |
| 1228 | call StopVimInTerminal(buf) |
| 1229 | call delete('XtestPopupMenu') |
| 1230 | endfunc |
| 1231 | |
Bram Moolenaar | f914a33 | 2019-07-20 15:09:56 +0200 | [diff] [blame] | 1232 | func Test_popup_menu_narrow() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 1233 | CheckScreendump |
Bram Moolenaar | f914a33 | 2019-07-20 15:09:56 +0200 | [diff] [blame] | 1234 | |
| 1235 | let lines =<< trim END |
| 1236 | call setline(1, range(1, 20)) |
| 1237 | hi PopupSelected ctermbg=green |
| 1238 | call popup_menu(['one', 'two', 'three'], #{callback: 'MenuDone'}) |
| 1239 | func MenuDone(id, res) |
| 1240 | echomsg "selected " .. a:res |
| 1241 | endfunc |
| 1242 | END |
| 1243 | call writefile(lines, 'XtestPopupNarrowMenu') |
| 1244 | let buf = RunVimInTerminal('-S XtestPopupNarrowMenu', #{rows: 10}) |
| 1245 | call VerifyScreenDump(buf, 'Test_popupwin_menu_04', {}) |
| 1246 | |
| 1247 | " clean up |
| 1248 | call term_sendkeys(buf, "x") |
| 1249 | call StopVimInTerminal(buf) |
| 1250 | call delete('XtestPopupNarrowMenu') |
| 1251 | endfunc |
| 1252 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 1253 | func Test_popup_title() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 1254 | CheckScreendump |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 1255 | |
| 1256 | " Create a popup without title or border, a line of padding will be added to |
| 1257 | " put the title on. |
| 1258 | let lines =<< trim END |
| 1259 | call setline(1, range(1, 20)) |
Bram Moolenaar | 5d458a7 | 2019-08-04 21:12:15 +0200 | [diff] [blame] | 1260 | let winid = popup_create(['one', 'two', 'another'], #{title: 'Title String'}) |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 1261 | END |
| 1262 | call writefile(lines, 'XtestPopupTitle') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1263 | let buf = RunVimInTerminal('-S XtestPopupTitle', #{rows: 10}) |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 1264 | call VerifyScreenDump(buf, 'Test_popupwin_title', {}) |
| 1265 | |
Bram Moolenaar | 5d458a7 | 2019-08-04 21:12:15 +0200 | [diff] [blame] | 1266 | call term_sendkeys(buf, ":call popup_setoptions(winid, #{maxwidth: 20, title: 'a very long title that is not going to fit'})\<CR>") |
| 1267 | call term_sendkeys(buf, ":\<CR>") |
| 1268 | call VerifyScreenDump(buf, 'Test_popupwin_longtitle_1', {}) |
| 1269 | |
| 1270 | call term_sendkeys(buf, ":call popup_setoptions(winid, #{border: []})\<CR>") |
| 1271 | call term_sendkeys(buf, ":\<CR>") |
| 1272 | call VerifyScreenDump(buf, 'Test_popupwin_longtitle_2', {}) |
| 1273 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 1274 | " clean up |
| 1275 | call StopVimInTerminal(buf) |
| 1276 | call delete('XtestPopupTitle') |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1277 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1278 | let winid = popup_create('something', #{title: 'Some Title'}) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1279 | call assert_equal('Some Title', popup_getoptions(winid).title) |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1280 | call popup_setoptions(winid, #{title: 'Another Title'}) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1281 | call assert_equal('Another Title', popup_getoptions(winid).title) |
| 1282 | |
| 1283 | call popup_clear() |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 1284 | endfunc |
| 1285 | |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1286 | func Test_popup_close_callback() |
| 1287 | func PopupDone(id, result) |
| 1288 | let g:result = a:result |
| 1289 | endfunc |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1290 | let winid = popup_create('something', #{callback: 'PopupDone'}) |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1291 | redraw |
| 1292 | call popup_close(winid, 'done') |
| 1293 | call assert_equal('done', g:result) |
| 1294 | endfunc |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 1295 | |
| 1296 | func Test_popup_empty() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1297 | let winid = popup_create('', #{padding: [2,2,2,2]}) |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 1298 | redraw |
| 1299 | let pos = popup_getpos(winid) |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1300 | call assert_equal(5, pos.width) |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 1301 | call assert_equal(5, pos.height) |
| 1302 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1303 | let winid = popup_create([], #{border: []}) |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 1304 | redraw |
| 1305 | let pos = popup_getpos(winid) |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1306 | call assert_equal(3, pos.width) |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 1307 | call assert_equal(3, pos.height) |
| 1308 | endfunc |
Bram Moolenaar | 988c433 | 2019-06-02 14:12:11 +0200 | [diff] [blame] | 1309 | |
| 1310 | func Test_popup_never_behind() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 1311 | CheckScreendump |
| 1312 | |
Bram Moolenaar | 988c433 | 2019-06-02 14:12:11 +0200 | [diff] [blame] | 1313 | " +-----------------------------+ |
| 1314 | " | | | |
| 1315 | " | | | |
| 1316 | " | | | |
| 1317 | " | line1 | |
| 1318 | " |------------line2------------| |
| 1319 | " | line3 | |
| 1320 | " | line4 | |
| 1321 | " | | |
| 1322 | " | | |
| 1323 | " +-----------------------------+ |
| 1324 | let lines =<< trim END |
| 1325 | only |
| 1326 | split |
| 1327 | vsplit |
| 1328 | let info_window1 = getwininfo()[0] |
| 1329 | let line = info_window1['height'] |
| 1330 | let col = info_window1['width'] |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1331 | call popup_create(['line1', 'line2', 'line3', 'line4'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 1332 | \ line : line, |
| 1333 | \ col : col, |
Bram Moolenaar | 988c433 | 2019-06-02 14:12:11 +0200 | [diff] [blame] | 1334 | \ }) |
| 1335 | END |
| 1336 | call writefile(lines, 'XtestPopupBehind') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1337 | let buf = RunVimInTerminal('-S XtestPopupBehind', #{rows: 10}) |
Bram Moolenaar | 988c433 | 2019-06-02 14:12:11 +0200 | [diff] [blame] | 1338 | call term_sendkeys(buf, "\<C-W>w") |
| 1339 | call VerifyScreenDump(buf, 'Test_popupwin_behind', {}) |
| 1340 | |
| 1341 | " clean up |
| 1342 | call StopVimInTerminal(buf) |
| 1343 | call delete('XtestPopupBehind') |
| 1344 | endfunc |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1345 | |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1346 | func s:VerifyPosition(p, msg, line, col, width, height) |
| 1347 | call assert_equal(a:line, popup_getpos(a:p).line, a:msg . ' (l)') |
| 1348 | call assert_equal(a:col, popup_getpos(a:p).col, a:msg . ' (c)') |
| 1349 | call assert_equal(a:width, popup_getpos(a:p).width, a:msg . ' (w)') |
| 1350 | call assert_equal(a:height, popup_getpos(a:p).height, a:msg . ' (h)') |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1351 | endfunc |
| 1352 | |
| 1353 | func Test_popup_position_adjust() |
| 1354 | " Anything placed past 2 cells from of the right of the screen is moved to the |
| 1355 | " left. |
| 1356 | " |
| 1357 | " When wrapping is disabled, we also shift to the left to display on the |
| 1358 | " screen, unless fixed is set. |
| 1359 | |
| 1360 | " Entries for cases which don't vary based on wrapping. |
| 1361 | " Format is per tests described below |
| 1362 | let both_wrap_tests = [ |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1363 | \ ['a', 5, &columns, 5, &columns - 2, 1, 1], |
| 1364 | \ ['b', 5, &columns + 1, 5, &columns - 2, 1, 1], |
| 1365 | \ ['c', 5, &columns - 1, 5, &columns - 2, 1, 1], |
| 1366 | \ ['d', 5, &columns - 2, 5, &columns - 2, 1, 1], |
| 1367 | \ ['e', 5, &columns - 3, 5, &columns - 3, 1, 1], |
| 1368 | \ |
| 1369 | \ ['aa', 5, &columns, 5, &columns - 2, 2, 1], |
| 1370 | \ ['bb', 5, &columns + 1, 5, &columns - 2, 2, 1], |
| 1371 | \ ['cc', 5, &columns - 1, 5, &columns - 2, 2, 1], |
| 1372 | \ ['dd', 5, &columns - 2, 5, &columns - 2, 2, 1], |
| 1373 | \ ['ee', 5, &columns - 3, 5, &columns - 3, 2, 1], |
| 1374 | \ |
| 1375 | \ ['aaa', 5, &columns, 5, &columns - 2, 3, 1], |
| 1376 | \ ['bbb', 5, &columns + 1, 5, &columns - 2, 3, 1], |
| 1377 | \ ['ccc', 5, &columns - 1, 5, &columns - 2, 3, 1], |
| 1378 | \ ['ddd', 5, &columns - 2, 5, &columns - 2, 3, 1], |
| 1379 | \ ['eee', 5, &columns - 3, 5, &columns - 3, 3, 1], |
| 1380 | \ ] |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1381 | |
| 1382 | " these test groups are dicts with: |
| 1383 | " - comment: something to identify the group of tests by |
| 1384 | " - options: dict of options to merge with the row/col in tests |
| 1385 | " - tests: list of cases. Each one is a list with elements: |
| 1386 | " - text |
| 1387 | " - row |
| 1388 | " - col |
| 1389 | " - expected row |
| 1390 | " - expected col |
| 1391 | " - expected width |
| 1392 | " - expected height |
| 1393 | let tests = [ |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1394 | \ #{ |
| 1395 | \ comment: 'left-aligned with wrapping', |
| 1396 | \ options: #{ |
| 1397 | \ wrap: 1, |
| 1398 | \ pos: 'botleft', |
| 1399 | \ }, |
| 1400 | \ tests: both_wrap_tests + [ |
| 1401 | \ ['aaaa', 5, &columns, 4, &columns - 2, 3, 2], |
| 1402 | \ ['bbbb', 5, &columns + 1, 4, &columns - 2, 3, 2], |
| 1403 | \ ['cccc', 5, &columns - 1, 4, &columns - 2, 3, 2], |
| 1404 | \ ['dddd', 5, &columns - 2, 4, &columns - 2, 3, 2], |
| 1405 | \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1], |
| 1406 | \ ], |
| 1407 | \ }, |
| 1408 | \ #{ |
| 1409 | \ comment: 'left aligned without wrapping', |
| 1410 | \ options: #{ |
| 1411 | \ wrap: 0, |
| 1412 | \ pos: 'botleft', |
| 1413 | \ }, |
| 1414 | \ tests: both_wrap_tests + [ |
| 1415 | \ ['aaaa', 5, &columns, 5, &columns - 3, 4, 1], |
| 1416 | \ ['bbbb', 5, &columns + 1, 5, &columns - 3, 4, 1], |
| 1417 | \ ['cccc', 5, &columns - 1, 5, &columns - 3, 4, 1], |
| 1418 | \ ['dddd', 5, &columns - 2, 5, &columns - 3, 4, 1], |
| 1419 | \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1], |
| 1420 | \ ], |
| 1421 | \ }, |
| 1422 | \ #{ |
| 1423 | \ comment: 'left aligned with fixed position', |
| 1424 | \ options: #{ |
| 1425 | \ wrap: 0, |
| 1426 | \ fixed: 1, |
| 1427 | \ pos: 'botleft', |
| 1428 | \ }, |
| 1429 | \ tests: both_wrap_tests + [ |
| 1430 | \ ['aaaa', 5, &columns, 5, &columns - 2, 3, 1], |
| 1431 | \ ['bbbb', 5, &columns + 1, 5, &columns - 2, 3, 1], |
| 1432 | \ ['cccc', 5, &columns - 1, 5, &columns - 2, 3, 1], |
| 1433 | \ ['dddd', 5, &columns - 2, 5, &columns - 2, 3, 1], |
| 1434 | \ ['eeee', 5, &columns - 3, 5, &columns - 3, 4, 1], |
| 1435 | \ ], |
| 1436 | \ }, |
| 1437 | \ ] |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1438 | |
| 1439 | for test_group in tests |
| 1440 | for test in test_group.tests |
| 1441 | let [ text, line, col, e_line, e_col, e_width, e_height ] = test |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1442 | let options = #{ |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1443 | \ line: line, |
| 1444 | \ col: col, |
| 1445 | \ } |
| 1446 | call extend(options, test_group.options) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1447 | |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1448 | let p = popup_create(text, options) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1449 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1450 | let msg = string(extend(options, #{text: text})) |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 1451 | call s:VerifyPosition(p, msg, e_line, e_col, e_width, e_height) |
| 1452 | call popup_close(p) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1453 | endfor |
| 1454 | endfor |
| 1455 | |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1456 | call popup_clear() |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1457 | %bwipe! |
| 1458 | endfunc |
| 1459 | |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1460 | func Test_adjust_left_past_screen_width() |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1461 | " width of screen |
| 1462 | let X = join(map(range(&columns), {->'X'}), '') |
| 1463 | |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1464 | let p = popup_create(X, #{line: 1, col: 1, wrap: 0}) |
| 1465 | call s:VerifyPosition(p, 'full width topleft', 1, 1, &columns, 1) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1466 | |
| 1467 | redraw |
| 1468 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1469 | call assert_equal(X, line) |
| 1470 | |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1471 | call popup_close(p) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1472 | redraw |
| 1473 | |
| 1474 | " Same if placed on the right hand side |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1475 | let p = popup_create(X, #{line: 1, col: &columns, wrap: 0}) |
| 1476 | call s:VerifyPosition(p, 'full width topright', 1, 1, &columns, 1) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1477 | |
| 1478 | redraw |
| 1479 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1480 | call assert_equal(X, line) |
| 1481 | |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1482 | call popup_close(p) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1483 | redraw |
| 1484 | |
| 1485 | " Extend so > window width |
| 1486 | let X .= 'x' |
| 1487 | |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1488 | let p = popup_create(X, #{line: 1, col: 1, wrap: 0}) |
| 1489 | call s:VerifyPosition(p, 'full width + 1 topleft', 1, 1, &columns, 1) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1490 | |
| 1491 | redraw |
| 1492 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1493 | call assert_equal(X[ : -2 ], line) |
| 1494 | |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1495 | call popup_close(p) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1496 | redraw |
| 1497 | |
| 1498 | " Shifted then truncated (the x is not visible) |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1499 | let p = popup_create(X, #{line: 1, col: &columns - 3, wrap: 0}) |
| 1500 | call s:VerifyPosition(p, 'full width + 1 topright', 1, 1, &columns, 1) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1501 | |
| 1502 | redraw |
| 1503 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1504 | call assert_equal(X[ : -2 ], line) |
| 1505 | |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1506 | call popup_close(p) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1507 | redraw |
| 1508 | |
| 1509 | " Not shifted, just truncated |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1510 | let p = popup_create(X, |
| 1511 | \ #{line: 1, col: 2, wrap: 0, fixed: 1}) |
| 1512 | call s:VerifyPosition(p, 'full width + 1 fixed', 1, 2, &columns - 1, 1) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1513 | |
| 1514 | redraw |
| 1515 | let line = join(map(range(1, &columns + 1), 'screenstring(1, v:val)'), '') |
| 1516 | let e_line = ' ' . X[ 1 : -2 ] |
| 1517 | call assert_equal(e_line, line) |
| 1518 | |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1519 | call popup_close(p) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1520 | redraw |
| 1521 | |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1522 | call popup_clear() |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1523 | %bwipe! |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1524 | endfunc |
| 1525 | |
| 1526 | func Test_popup_moved() |
| 1527 | new |
| 1528 | call test_override('char_avail', 1) |
| 1529 | call setline(1, ['one word to move around', 'a WORD.and->some thing']) |
| 1530 | |
| 1531 | exe "normal gg0/word\<CR>" |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1532 | let winid = popup_atcursor('text', #{moved: 'any'}) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1533 | redraw |
| 1534 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1535 | call assert_equal([1, 4, 4], popup_getoptions(winid).moved) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1536 | " trigger the check for last_cursormoved by going into insert mode |
| 1537 | call feedkeys("li\<Esc>", 'xt') |
| 1538 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1539 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1540 | |
| 1541 | exe "normal gg0/word\<CR>" |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1542 | let winid = popup_atcursor('text', #{moved: 'word'}) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1543 | redraw |
| 1544 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1545 | call assert_equal([1, 4, 7], popup_getoptions(winid).moved) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1546 | call feedkeys("hi\<Esc>", 'xt') |
| 1547 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1548 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1549 | |
| 1550 | exe "normal gg0/word\<CR>" |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1551 | let winid = popup_atcursor('text', #{moved: 'word'}) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1552 | redraw |
| 1553 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1554 | call assert_equal([1, 4, 7], popup_getoptions(winid).moved) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1555 | call feedkeys("li\<Esc>", 'xt') |
| 1556 | call assert_equal(1, popup_getpos(winid).visible) |
| 1557 | call feedkeys("ei\<Esc>", 'xt') |
| 1558 | call assert_equal(1, popup_getpos(winid).visible) |
| 1559 | call feedkeys("eli\<Esc>", 'xt') |
| 1560 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1561 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1562 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1563 | " WORD is the default |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1564 | exe "normal gg0/WORD\<CR>" |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1565 | let winid = popup_atcursor('text', {}) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1566 | redraw |
| 1567 | call assert_equal(1, popup_getpos(winid).visible) |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1568 | call assert_equal([2, 2, 15], popup_getoptions(winid).moved) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1569 | call feedkeys("eli\<Esc>", 'xt') |
| 1570 | call assert_equal(1, popup_getpos(winid).visible) |
| 1571 | call feedkeys("wi\<Esc>", 'xt') |
| 1572 | call assert_equal(1, popup_getpos(winid).visible) |
| 1573 | call feedkeys("Eli\<Esc>", 'xt') |
| 1574 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1575 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1576 | |
| 1577 | exe "normal gg0/word\<CR>" |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1578 | let winid = popup_atcursor('text', #{moved: [5, 10]}) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1579 | redraw |
| 1580 | call assert_equal(1, popup_getpos(winid).visible) |
| 1581 | call feedkeys("eli\<Esc>", 'xt') |
| 1582 | call feedkeys("ei\<Esc>", 'xt') |
| 1583 | call assert_equal(1, popup_getpos(winid).visible) |
| 1584 | call feedkeys("eli\<Esc>", 'xt') |
| 1585 | call assert_equal({}, popup_getpos(winid)) |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1586 | call popup_clear() |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1587 | |
| 1588 | bwipe! |
| 1589 | call test_override('ALL', 0) |
| 1590 | endfunc |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1591 | |
| 1592 | func Test_notifications() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 1593 | CheckFeature timers |
| 1594 | CheckScreendump |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1595 | |
| 1596 | call writefile([ |
| 1597 | \ "call setline(1, range(1, 20))", |
| 1598 | \ "hi Notification ctermbg=lightblue", |
| 1599 | \ "call popup_notification('first notification', {})", |
| 1600 | \], 'XtestNotifications') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1601 | let buf = RunVimInTerminal('-S XtestNotifications', #{rows: 10}) |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1602 | call VerifyScreenDump(buf, 'Test_popupwin_notify_01', {}) |
| 1603 | |
| 1604 | " second one goes below the first one |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 1605 | call term_sendkeys(buf, ":hi link PopupNotification Notification\<CR>") |
| 1606 | call term_sendkeys(buf, ":call popup_notification('another important notification', {})\<CR>") |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1607 | call VerifyScreenDump(buf, 'Test_popupwin_notify_02', {}) |
| 1608 | |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1609 | " clean up |
| 1610 | call StopVimInTerminal(buf) |
| 1611 | call delete('XtestNotifications') |
| 1612 | endfunc |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1613 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1614 | func Test_popup_scrollbar() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 1615 | CheckScreendump |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1616 | |
| 1617 | let lines =<< trim END |
| 1618 | call setline(1, range(1, 20)) |
Bram Moolenaar | 8da4181 | 2019-06-26 18:04:54 +0200 | [diff] [blame] | 1619 | hi ScrollThumb ctermbg=blue |
| 1620 | hi ScrollBar ctermbg=red |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1621 | let winid = popup_create(['one', 'two', 'three', 'four', 'five', |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1622 | \ 'six', 'seven', 'eight', 'nine'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 1623 | \ minwidth: 8, |
| 1624 | \ maxheight: 4, |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1625 | \ }) |
Bram Moolenaar | 53a95d6 | 2019-06-26 03:54:08 +0200 | [diff] [blame] | 1626 | func ScrollUp() |
| 1627 | call feedkeys("\<F3>\<ScrollWheelUp>", "xt") |
| 1628 | endfunc |
| 1629 | func ScrollDown() |
| 1630 | call feedkeys("\<F3>\<ScrollWheelDown>", "xt") |
| 1631 | endfunc |
Bram Moolenaar | f9c85f5 | 2019-06-29 07:41:35 +0200 | [diff] [blame] | 1632 | func ClickTop() |
| 1633 | call feedkeys("\<F4>\<LeftMouse>", "xt") |
| 1634 | endfunc |
| 1635 | func ClickBot() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1636 | call popup_setoptions(g:winid, #{border: [], close: 'button'}) |
Bram Moolenaar | f9c85f5 | 2019-06-29 07:41:35 +0200 | [diff] [blame] | 1637 | call feedkeys("\<F5>\<LeftMouse>", "xt") |
| 1638 | endfunc |
Bram Moolenaar | 53a95d6 | 2019-06-26 03:54:08 +0200 | [diff] [blame] | 1639 | map <silent> <F3> :call test_setmouse(5, 36)<CR> |
Bram Moolenaar | f9c85f5 | 2019-06-29 07:41:35 +0200 | [diff] [blame] | 1640 | map <silent> <F4> :call test_setmouse(4, 42)<CR> |
| 1641 | map <silent> <F5> :call test_setmouse(7, 42)<CR> |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1642 | END |
| 1643 | call writefile(lines, 'XtestPopupScroll') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1644 | let buf = RunVimInTerminal('-S XtestPopupScroll', #{rows: 10}) |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1645 | call VerifyScreenDump(buf, 'Test_popupwin_scroll_1', {}) |
| 1646 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1647 | call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 2})\<CR>") |
Bram Moolenaar | b8be54d | 2019-07-14 18:22:59 +0200 | [diff] [blame] | 1648 | call term_sendkeys(buf, ":\<CR>") |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1649 | call VerifyScreenDump(buf, 'Test_popupwin_scroll_2', {}) |
| 1650 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1651 | call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 6})\<CR>") |
Bram Moolenaar | b8be54d | 2019-07-14 18:22:59 +0200 | [diff] [blame] | 1652 | call term_sendkeys(buf, ":\<CR>") |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1653 | call VerifyScreenDump(buf, 'Test_popupwin_scroll_3', {}) |
| 1654 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1655 | call term_sendkeys(buf, ":call popup_setoptions(winid, #{firstline: 9})\<CR>") |
Bram Moolenaar | b8be54d | 2019-07-14 18:22:59 +0200 | [diff] [blame] | 1656 | call term_sendkeys(buf, ":\<CR>") |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1657 | call VerifyScreenDump(buf, 'Test_popupwin_scroll_4', {}) |
| 1658 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1659 | call term_sendkeys(buf, ":call popup_setoptions(winid, #{scrollbarhighlight: 'ScrollBar', thumbhighlight: 'ScrollThumb'})\<CR>") |
Bram Moolenaar | 53a95d6 | 2019-06-26 03:54:08 +0200 | [diff] [blame] | 1660 | call term_sendkeys(buf, ":call ScrollUp()\<CR>") |
| 1661 | call VerifyScreenDump(buf, 'Test_popupwin_scroll_5', {}) |
| 1662 | |
| 1663 | call term_sendkeys(buf, ":call ScrollDown()\<CR>") |
| 1664 | call VerifyScreenDump(buf, 'Test_popupwin_scroll_6', {}) |
| 1665 | |
| 1666 | call term_sendkeys(buf, ":call ScrollDown()\<CR>") |
Bram Moolenaar | 13b47c3 | 2019-06-28 21:55:48 +0200 | [diff] [blame] | 1667 | " wait a bit, otherwise it fails sometimes (double click recognized?) |
| 1668 | sleep 100m |
Bram Moolenaar | 53a95d6 | 2019-06-26 03:54:08 +0200 | [diff] [blame] | 1669 | call term_sendkeys(buf, ":call ScrollDown()\<CR>") |
| 1670 | call VerifyScreenDump(buf, 'Test_popupwin_scroll_7', {}) |
| 1671 | |
Bram Moolenaar | f9c85f5 | 2019-06-29 07:41:35 +0200 | [diff] [blame] | 1672 | call term_sendkeys(buf, ":call ClickTop()\<CR>") |
| 1673 | sleep 100m |
| 1674 | call term_sendkeys(buf, ":call ClickTop()\<CR>") |
| 1675 | call VerifyScreenDump(buf, 'Test_popupwin_scroll_8', {}) |
| 1676 | |
| 1677 | call term_sendkeys(buf, ":call ClickBot()\<CR>") |
| 1678 | call VerifyScreenDump(buf, 'Test_popupwin_scroll_9', {}) |
| 1679 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1680 | " clean up |
| 1681 | call StopVimInTerminal(buf) |
| 1682 | call delete('XtestPopupScroll') |
| 1683 | endfunc |
| 1684 | |
Bram Moolenaar | 437a746 | 2019-07-05 20:17:22 +0200 | [diff] [blame] | 1685 | func Test_popup_fitting_scrollbar() |
| 1686 | " this was causing a crash, divide by zero |
| 1687 | let winid = popup_create([ |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1688 | \ 'one', 'two', 'longer line that wraps', 'four', 'five'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 1689 | \ scrollbar: 1, |
| 1690 | \ maxwidth: 10, |
| 1691 | \ maxheight: 5, |
| 1692 | \ firstline: 2}) |
Bram Moolenaar | 437a746 | 2019-07-05 20:17:22 +0200 | [diff] [blame] | 1693 | redraw |
| 1694 | call popup_clear() |
| 1695 | endfunc |
| 1696 | |
Bram Moolenaar | 6313c4f | 2019-06-16 20:39:13 +0200 | [diff] [blame] | 1697 | func Test_popup_settext() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 1698 | CheckScreendump |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1699 | |
| 1700 | let lines =<< trim END |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1701 | let opts = #{wrap: 0} |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1702 | let p = popup_create('test', opts) |
| 1703 | call popup_settext(p, 'this is a text') |
| 1704 | END |
| 1705 | |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1706 | call writefile(lines, 'XtestPopupSetText') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1707 | let buf = RunVimInTerminal('-S XtestPopupSetText', #{rows: 10}) |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1708 | call VerifyScreenDump(buf, 'Test_popup_settext_01', {}) |
| 1709 | |
| 1710 | " Setting to empty string clears it |
| 1711 | call term_sendkeys(buf, ":call popup_settext(p, '')\<CR>") |
| 1712 | call VerifyScreenDump(buf, 'Test_popup_settext_02', {}) |
| 1713 | |
| 1714 | " Setting a list |
| 1715 | call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>") |
| 1716 | call VerifyScreenDump(buf, 'Test_popup_settext_03', {}) |
| 1717 | |
| 1718 | " Shrinking with a list |
| 1719 | call term_sendkeys(buf, ":call popup_settext(p, ['a'])\<CR>") |
| 1720 | call VerifyScreenDump(buf, 'Test_popup_settext_04', {}) |
| 1721 | |
| 1722 | " Growing with a list |
| 1723 | call term_sendkeys(buf, ":call popup_settext(p, ['a','b','c'])\<CR>") |
| 1724 | call VerifyScreenDump(buf, 'Test_popup_settext_03', {}) |
| 1725 | |
| 1726 | " Empty list clears |
| 1727 | call term_sendkeys(buf, ":call popup_settext(p, [])\<CR>") |
| 1728 | call VerifyScreenDump(buf, 'Test_popup_settext_05', {}) |
| 1729 | |
| 1730 | " Dicts |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1731 | call term_sendkeys(buf, ":call popup_settext(p, [#{text: 'aaaa'}, #{text: 'bbbb'}, #{text: 'cccc'}])\<CR>") |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1732 | call VerifyScreenDump(buf, 'Test_popup_settext_06', {}) |
| 1733 | |
| 1734 | " clean up |
| 1735 | call StopVimInTerminal(buf) |
| 1736 | call delete('XtestPopupSetText') |
Bram Moolenaar | 6313c4f | 2019-06-16 20:39:13 +0200 | [diff] [blame] | 1737 | endfunc |
| 1738 | |
| 1739 | func Test_popup_hidden() |
| 1740 | new |
| 1741 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1742 | let winid = popup_atcursor('text', #{hidden: 1}) |
Bram Moolenaar | 6313c4f | 2019-06-16 20:39:13 +0200 | [diff] [blame] | 1743 | redraw |
| 1744 | call assert_equal(0, popup_getpos(winid).visible) |
| 1745 | call popup_close(winid) |
| 1746 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1747 | let winid = popup_create('text', #{hidden: 1}) |
Bram Moolenaar | 6313c4f | 2019-06-16 20:39:13 +0200 | [diff] [blame] | 1748 | redraw |
| 1749 | call assert_equal(0, popup_getpos(winid).visible) |
| 1750 | call popup_close(winid) |
| 1751 | |
| 1752 | func QuitCallback(id, res) |
| 1753 | let s:cb_winid = a:id |
| 1754 | let s:cb_res = a:res |
| 1755 | endfunc |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1756 | let winid = popup_dialog('make a choice', #{hidden: 1, |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 1757 | \ filter: 'popup_filter_yesno', |
| 1758 | \ callback: 'QuitCallback', |
Bram Moolenaar | 6313c4f | 2019-06-16 20:39:13 +0200 | [diff] [blame] | 1759 | \ }) |
| 1760 | redraw |
| 1761 | call assert_equal(0, popup_getpos(winid).visible) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1762 | call assert_equal(function('popup_filter_yesno'), popup_getoptions(winid).filter) |
| 1763 | call assert_equal(function('QuitCallback'), popup_getoptions(winid).callback) |
Bram Moolenaar | 6313c4f | 2019-06-16 20:39:13 +0200 | [diff] [blame] | 1764 | exe "normal anot used by filter\<Esc>" |
| 1765 | call assert_equal('not used by filter', getline(1)) |
| 1766 | |
| 1767 | call popup_show(winid) |
| 1768 | call feedkeys('y', "xt") |
| 1769 | call assert_equal(1, s:cb_res) |
| 1770 | |
| 1771 | bwipe! |
| 1772 | delfunc QuitCallback |
| 1773 | endfunc |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1774 | |
| 1775 | " Test options not checked elsewhere |
| 1776 | func Test_set_get_options() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1777 | let winid = popup_create('some text', #{highlight: 'Beautiful'}) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1778 | let options = popup_getoptions(winid) |
| 1779 | call assert_equal(1, options.wrap) |
| 1780 | call assert_equal(0, options.drag) |
| 1781 | call assert_equal('Beautiful', options.highlight) |
| 1782 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1783 | call popup_setoptions(winid, #{wrap: 0, drag: 1, highlight: 'Another'}) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1784 | let options = popup_getoptions(winid) |
| 1785 | call assert_equal(0, options.wrap) |
| 1786 | call assert_equal(1, options.drag) |
| 1787 | call assert_equal('Another', options.highlight) |
| 1788 | |
| 1789 | call popup_close(winid) |
| 1790 | endfunc |
Bram Moolenaar | 75a1a94 | 2019-06-20 03:45:36 +0200 | [diff] [blame] | 1791 | |
| 1792 | func Test_popupwin_garbage_collect() |
| 1793 | func MyPopupFilter(x, winid, c) |
| 1794 | " NOP |
| 1795 | endfunc |
| 1796 | |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1797 | let winid = popup_create('something', #{filter: function('MyPopupFilter', [{}])}) |
Bram Moolenaar | 75a1a94 | 2019-06-20 03:45:36 +0200 | [diff] [blame] | 1798 | call test_garbagecollect_now() |
| 1799 | redraw |
| 1800 | " Must not crach caused by invalid memory access |
| 1801 | call feedkeys('j', 'xt') |
| 1802 | call assert_true(v:true) |
| 1803 | |
| 1804 | call popup_close(winid) |
| 1805 | delfunc MyPopupFilter |
| 1806 | endfunc |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1807 | |
| 1808 | func Test_popupwin_with_buffer() |
| 1809 | call writefile(['some text', 'in a buffer'], 'XsomeFile') |
| 1810 | let buf = bufadd('XsomeFile') |
| 1811 | call assert_equal(0, bufloaded(buf)) |
| 1812 | let winid = popup_create(buf, {}) |
| 1813 | call assert_notequal(0, winid) |
| 1814 | let pos = popup_getpos(winid) |
| 1815 | call assert_equal(2, pos.height) |
| 1816 | call assert_equal(1, bufloaded(buf)) |
| 1817 | call popup_close(winid) |
| 1818 | call assert_equal({}, popup_getpos(winid)) |
| 1819 | call assert_equal(1, bufloaded(buf)) |
| 1820 | exe 'bwipe! ' .. buf |
Bram Moolenaar | 7866b87 | 2019-07-01 22:21:01 +0200 | [diff] [blame] | 1821 | |
| 1822 | edit test_popupwin.vim |
| 1823 | let winid = popup_create(bufnr(''), {}) |
| 1824 | redraw |
| 1825 | call popup_close(winid) |
Bram Moolenaar | 3940ec6 | 2019-07-05 21:53:24 +0200 | [diff] [blame] | 1826 | call delete('XsomeFile') |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1827 | endfunc |
Bram Moolenaar | e296e31 | 2019-07-03 23:20:18 +0200 | [diff] [blame] | 1828 | |
| 1829 | func Test_popupwin_width() |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1830 | let winid = popup_create(repeat(['short', 'long long long line', 'medium width'], 50), #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 1831 | \ maxwidth: 40, |
| 1832 | \ maxheight: 10, |
Bram Moolenaar | e296e31 | 2019-07-03 23:20:18 +0200 | [diff] [blame] | 1833 | \ }) |
| 1834 | for top in range(1, 20) |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1835 | call popup_setoptions(winid, #{firstline: top}) |
Bram Moolenaar | e296e31 | 2019-07-03 23:20:18 +0200 | [diff] [blame] | 1836 | redraw |
| 1837 | call assert_equal(19, popup_getpos(winid).width) |
| 1838 | endfor |
| 1839 | call popup_clear() |
| 1840 | endfunc |
Bram Moolenaar | 5ca1ac3 | 2019-07-04 15:39:28 +0200 | [diff] [blame] | 1841 | |
| 1842 | func Test_popupwin_buf_close() |
| 1843 | let buf = bufadd('Xtestbuf') |
| 1844 | call bufload(buf) |
| 1845 | call setbufline(buf, 1, ['just', 'some', 'lines']) |
| 1846 | let winid = popup_create(buf, {}) |
| 1847 | redraw |
| 1848 | call assert_equal(3, popup_getpos(winid).height) |
| 1849 | let bufinfo = getbufinfo(buf)[0] |
| 1850 | call assert_equal(1, bufinfo.changed) |
| 1851 | call assert_equal(0, bufinfo.hidden) |
| 1852 | call assert_equal(0, bufinfo.listed) |
| 1853 | call assert_equal(1, bufinfo.loaded) |
| 1854 | call assert_equal([], bufinfo.windows) |
| 1855 | call assert_equal([winid], bufinfo.popups) |
| 1856 | |
| 1857 | call popup_close(winid) |
| 1858 | call assert_equal({}, popup_getpos(winid)) |
| 1859 | let bufinfo = getbufinfo(buf)[0] |
| 1860 | call assert_equal(1, bufinfo.changed) |
| 1861 | call assert_equal(1, bufinfo.hidden) |
| 1862 | call assert_equal(0, bufinfo.listed) |
| 1863 | call assert_equal(1, bufinfo.loaded) |
| 1864 | call assert_equal([], bufinfo.windows) |
| 1865 | call assert_equal([], bufinfo.popups) |
| 1866 | exe 'bwipe! ' .. buf |
| 1867 | endfunc |
Bram Moolenaar | 017c269 | 2019-07-13 14:17:51 +0200 | [diff] [blame] | 1868 | |
| 1869 | func Test_popup_menu_with_maxwidth() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 1870 | CheckScreendump |
Bram Moolenaar | 017c269 | 2019-07-13 14:17:51 +0200 | [diff] [blame] | 1871 | |
| 1872 | let lines =<< trim END |
| 1873 | call setline(1, range(1, 10)) |
| 1874 | hi ScrollThumb ctermbg=blue |
| 1875 | hi ScrollBar ctermbg=red |
| 1876 | func PopupMenu(lines, line, col, scrollbar = 0) |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1877 | return popup_menu(a:lines, #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 1878 | \ maxwidth: 10, |
| 1879 | \ maxheight: 3, |
| 1880 | \ pos : 'topleft', |
| 1881 | \ col : a:col, |
| 1882 | \ line : a:line, |
| 1883 | \ scrollbar : a:scrollbar, |
Bram Moolenaar | 017c269 | 2019-07-13 14:17:51 +0200 | [diff] [blame] | 1884 | \ }) |
| 1885 | endfunc |
| 1886 | call PopupMenu(['x'], 1, 1) |
| 1887 | call PopupMenu(['123456789|'], 1, 16) |
| 1888 | call PopupMenu(['123456789|' .. ' '], 7, 1) |
| 1889 | call PopupMenu([repeat('123456789|', 100)], 7, 16) |
| 1890 | call PopupMenu(repeat(['123456789|' .. ' '], 5), 1, 33, 1) |
| 1891 | END |
| 1892 | call writefile(lines, 'XtestPopupMenuMaxWidth') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1893 | let buf = RunVimInTerminal('-S XtestPopupMenuMaxWidth', #{rows: 13}) |
Bram Moolenaar | 017c269 | 2019-07-13 14:17:51 +0200 | [diff] [blame] | 1894 | call VerifyScreenDump(buf, 'Test_popupwin_menu_maxwidth_1', {}) |
| 1895 | |
| 1896 | " close the menu popupwin. |
| 1897 | call term_sendkeys(buf, " ") |
| 1898 | call term_sendkeys(buf, " ") |
| 1899 | call term_sendkeys(buf, " ") |
| 1900 | call term_sendkeys(buf, " ") |
| 1901 | call term_sendkeys(buf, " ") |
| 1902 | |
| 1903 | " clean up |
| 1904 | call StopVimInTerminal(buf) |
| 1905 | call delete('XtestPopupMenuMaxWidth') |
| 1906 | endfunc |
| 1907 | |
Bram Moolenaar | a901a37 | 2019-07-13 16:38:50 +0200 | [diff] [blame] | 1908 | func Test_popup_menu_with_scrollbar() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 1909 | CheckScreendump |
Bram Moolenaar | a901a37 | 2019-07-13 16:38:50 +0200 | [diff] [blame] | 1910 | |
| 1911 | let lines =<< trim END |
| 1912 | call setline(1, range(1, 20)) |
| 1913 | hi ScrollThumb ctermbg=blue |
| 1914 | hi ScrollBar ctermbg=red |
| 1915 | call popup_menu(['one', 'two', 'three', 'four', 'five', |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1916 | \ 'six', 'seven', 'eight', 'nine'], #{ |
Bram Moolenaar | d5abb4c | 2019-07-13 22:46:10 +0200 | [diff] [blame] | 1917 | \ minwidth: 8, |
| 1918 | \ maxheight: 3, |
Bram Moolenaar | a901a37 | 2019-07-13 16:38:50 +0200 | [diff] [blame] | 1919 | \ }) |
| 1920 | END |
| 1921 | call writefile(lines, 'XtestPopupMenuScroll') |
Bram Moolenaar | 4c6d904 | 2019-07-16 22:04:02 +0200 | [diff] [blame] | 1922 | let buf = RunVimInTerminal('-S XtestPopupMenuScroll', #{rows: 10}) |
Bram Moolenaar | a901a37 | 2019-07-13 16:38:50 +0200 | [diff] [blame] | 1923 | |
| 1924 | call term_sendkeys(buf, "j") |
| 1925 | call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_1', {}) |
| 1926 | |
| 1927 | call term_sendkeys(buf, "jjj") |
| 1928 | call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_2', {}) |
| 1929 | |
| 1930 | " if the cursor is the bottom line, it stays at the bottom line. |
| 1931 | call term_sendkeys(buf, repeat("j", 20)) |
| 1932 | call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_3', {}) |
| 1933 | |
| 1934 | call term_sendkeys(buf, "kk") |
| 1935 | call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_4', {}) |
| 1936 | |
| 1937 | call term_sendkeys(buf, "k") |
| 1938 | call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_5', {}) |
| 1939 | |
| 1940 | " if the cursor is in the top line, it stays in the top line. |
| 1941 | call term_sendkeys(buf, repeat("k", 20)) |
| 1942 | call VerifyScreenDump(buf, 'Test_popupwin_menu_scroll_6', {}) |
| 1943 | |
| 1944 | " close the menu popupwin. |
| 1945 | call term_sendkeys(buf, " ") |
| 1946 | |
| 1947 | " clean up |
| 1948 | call StopVimInTerminal(buf) |
| 1949 | call delete('XtestPopupMenuScroll') |
| 1950 | endfunc |
| 1951 | |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 1952 | func Test_popup_menu_filter() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 1953 | CheckScreendump |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 1954 | |
| 1955 | let lines =<< trim END |
| 1956 | function! MyFilter(winid, key) abort |
| 1957 | if a:key == "0" |
| 1958 | call win_execute(a:winid, "call setpos('.', [0, 1, 1, 0])") |
| 1959 | return 1 |
| 1960 | endif |
| 1961 | if a:key == "G" |
| 1962 | call win_execute(a:winid, "call setpos('.', [0, line('$'), 1, 0])") |
| 1963 | return 1 |
| 1964 | endif |
| 1965 | if a:key == "j" |
| 1966 | call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0])") |
| 1967 | return 1 |
| 1968 | endif |
| 1969 | if a:key == "k" |
| 1970 | call win_execute(a:winid, "call setpos('.', [0, line('.') - 1, 1, 0])") |
| 1971 | return 1 |
| 1972 | endif |
| 1973 | if a:key == 'x' |
| 1974 | call popup_close(a:winid) |
| 1975 | return 1 |
| 1976 | endif |
| 1977 | return 0 |
| 1978 | endfunction |
| 1979 | call popup_menu(['111', '222', '333', '444', '555', '666', '777', '888', '999'], #{ |
| 1980 | \ maxheight : 3, |
| 1981 | \ filter : 'MyFilter' |
| 1982 | \ }) |
| 1983 | END |
| 1984 | call writefile(lines, 'XtestPopupMenuFilter') |
| 1985 | let buf = RunVimInTerminal('-S XtestPopupMenuFilter', #{rows: 10}) |
| 1986 | |
| 1987 | call term_sendkeys(buf, "j") |
| 1988 | call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_1', {}) |
| 1989 | |
| 1990 | call term_sendkeys(buf, "k") |
| 1991 | call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_2', {}) |
| 1992 | |
| 1993 | call term_sendkeys(buf, "G") |
| 1994 | call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_3', {}) |
| 1995 | |
| 1996 | call term_sendkeys(buf, "0") |
| 1997 | call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_4', {}) |
| 1998 | |
| 1999 | call term_sendkeys(buf, "x") |
| 2000 | |
| 2001 | " clean up |
| 2002 | call StopVimInTerminal(buf) |
| 2003 | call delete('XtestPopupMenuFilter') |
| 2004 | endfunc |
| 2005 | |
| 2006 | func Test_popup_cursorline() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 2007 | CheckScreendump |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 2008 | |
| 2009 | let winid = popup_create('some text', {}) |
| 2010 | call assert_equal(0, popup_getoptions(winid).cursorline) |
| 2011 | call popup_close(winid) |
| 2012 | |
| 2013 | let winid = popup_create('some text', #{ cursorline: 1, }) |
| 2014 | call assert_equal(1, popup_getoptions(winid).cursorline) |
| 2015 | call popup_close(winid) |
| 2016 | |
| 2017 | let winid = popup_create('some text', #{ cursorline: 0, }) |
| 2018 | call assert_equal(0, popup_getoptions(winid).cursorline) |
| 2019 | call popup_close(winid) |
| 2020 | |
| 2021 | let winid = popup_menu('some text', {}) |
| 2022 | call assert_equal(1, popup_getoptions(winid).cursorline) |
| 2023 | call popup_close(winid) |
| 2024 | |
| 2025 | let winid = popup_menu('some text', #{ cursorline: 1, }) |
| 2026 | call assert_equal(1, popup_getoptions(winid).cursorline) |
| 2027 | call popup_close(winid) |
| 2028 | |
| 2029 | let winid = popup_menu('some text', #{ cursorline: 0, }) |
| 2030 | call assert_equal(0, popup_getoptions(winid).cursorline) |
| 2031 | call popup_close(winid) |
| 2032 | |
| 2033 | " --------- |
| 2034 | " Pattern 1 |
| 2035 | " --------- |
| 2036 | let lines =<< trim END |
| 2037 | call popup_create(['111', '222', '333'], #{ cursorline : 0 }) |
| 2038 | END |
| 2039 | call writefile(lines, 'XtestPopupCursorLine') |
| 2040 | let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10}) |
| 2041 | call VerifyScreenDump(buf, 'Test_popupwin_cursorline_1', {}) |
| 2042 | call term_sendkeys(buf, ":call popup_clear()\<cr>") |
| 2043 | call StopVimInTerminal(buf) |
| 2044 | |
| 2045 | " --------- |
| 2046 | " Pattern 2 |
| 2047 | " --------- |
| 2048 | let lines =<< trim END |
| 2049 | call popup_create(['111', '222', '333'], #{ cursorline : 1 }) |
| 2050 | END |
| 2051 | call writefile(lines, 'XtestPopupCursorLine') |
| 2052 | let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10}) |
| 2053 | call VerifyScreenDump(buf, 'Test_popupwin_cursorline_2', {}) |
| 2054 | call term_sendkeys(buf, ":call popup_clear()\<cr>") |
| 2055 | call StopVimInTerminal(buf) |
| 2056 | |
| 2057 | " --------- |
| 2058 | " Pattern 3 |
| 2059 | " --------- |
| 2060 | let lines =<< trim END |
| 2061 | function! MyFilter(winid, key) abort |
| 2062 | if a:key == "j" |
| 2063 | call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw") |
| 2064 | return 1 |
| 2065 | endif |
| 2066 | if a:key == 'x' |
| 2067 | call popup_close(a:winid) |
| 2068 | return 1 |
| 2069 | endif |
| 2070 | return 0 |
| 2071 | endfunction |
| 2072 | call popup_menu(['111', '222', '333'], #{ |
| 2073 | \ cursorline : 0, |
| 2074 | \ maxheight : 2, |
| 2075 | \ filter : 'MyFilter', |
| 2076 | \ }) |
| 2077 | END |
| 2078 | call writefile(lines, 'XtestPopupCursorLine') |
| 2079 | let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10}) |
| 2080 | call VerifyScreenDump(buf, 'Test_popupwin_cursorline_3', {}) |
| 2081 | call term_sendkeys(buf, "j") |
| 2082 | call term_sendkeys(buf, "j") |
| 2083 | call VerifyScreenDump(buf, 'Test_popupwin_cursorline_4', {}) |
| 2084 | call term_sendkeys(buf, "x") |
| 2085 | call StopVimInTerminal(buf) |
| 2086 | |
| 2087 | " --------- |
| 2088 | " Pattern 4 |
| 2089 | " --------- |
| 2090 | let lines =<< trim END |
| 2091 | function! MyFilter(winid, key) abort |
| 2092 | if a:key == "j" |
| 2093 | call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw") |
| 2094 | return 1 |
| 2095 | endif |
| 2096 | if a:key == 'x' |
| 2097 | call popup_close(a:winid) |
| 2098 | return 1 |
| 2099 | endif |
| 2100 | return 0 |
| 2101 | endfunction |
| 2102 | call popup_menu(['111', '222', '333'], #{ |
| 2103 | \ cursorline : 1, |
| 2104 | \ maxheight : 2, |
| 2105 | \ filter : 'MyFilter', |
| 2106 | \ }) |
| 2107 | END |
| 2108 | call writefile(lines, 'XtestPopupCursorLine') |
| 2109 | let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10}) |
| 2110 | call VerifyScreenDump(buf, 'Test_popupwin_cursorline_5', {}) |
| 2111 | call term_sendkeys(buf, "j") |
| 2112 | call term_sendkeys(buf, "j") |
| 2113 | call VerifyScreenDump(buf, 'Test_popupwin_cursorline_6', {}) |
| 2114 | call term_sendkeys(buf, "x") |
| 2115 | call StopVimInTerminal(buf) |
| 2116 | |
| 2117 | call delete('XtestPopupCursorLine') |
| 2118 | endfunc |
| 2119 | |
Bram Moolenaar | f914a33 | 2019-07-20 15:09:56 +0200 | [diff] [blame] | 2120 | func Test_previewpopup() |
Bram Moolenaar | 4999a7f | 2019-08-10 22:21:48 +0200 | [diff] [blame] | 2121 | CheckScreendump |
| 2122 | |
Bram Moolenaar | f914a33 | 2019-07-20 15:09:56 +0200 | [diff] [blame] | 2123 | call writefile([ |
| 2124 | \ "!_TAG_FILE_ENCODING\tutf-8\t//", |
| 2125 | \ "another\tXtagfile\t/^this is another", |
| 2126 | \ "theword\tXtagfile\t/^theword"], |
| 2127 | \ 'Xtags') |
| 2128 | call writefile(range(1,20) |
| 2129 | \ + ['theword is here'] |
| 2130 | \ + range(22, 27) |
| 2131 | \ + ['this is another place'] |
| 2132 | \ + range(29, 40), |
| 2133 | \ "Xtagfile") |
Bram Moolenaar | 1b6d9c4 | 2019-08-05 21:52:04 +0200 | [diff] [blame] | 2134 | call writefile(range(1,10) |
| 2135 | \ + ['searched word is here'] |
| 2136 | \ + range(12, 20), |
| 2137 | \ "Xheader.h") |
Bram Moolenaar | f914a33 | 2019-07-20 15:09:56 +0200 | [diff] [blame] | 2138 | let lines =<< trim END |
| 2139 | set tags=Xtags |
| 2140 | call setline(1, [ |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 2141 | \ 'one', |
Bram Moolenaar | 1b6d9c4 | 2019-08-05 21:52:04 +0200 | [diff] [blame] | 2142 | \ '#include "Xheader.h"', |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 2143 | \ 'three', |
| 2144 | \ 'four', |
| 2145 | \ 'five', |
| 2146 | \ 'six', |
| 2147 | \ 'seven', |
| 2148 | \ 'find theword somewhere', |
| 2149 | \ 'nine', |
| 2150 | \ 'this is another word', |
| 2151 | \ 'very long line where the word is also another']) |
Bram Moolenaar | f914a33 | 2019-07-20 15:09:56 +0200 | [diff] [blame] | 2152 | set previewpopup=height:4,width:40 |
Bram Moolenaar | 1b6d9c4 | 2019-08-05 21:52:04 +0200 | [diff] [blame] | 2153 | set path=. |
Bram Moolenaar | f914a33 | 2019-07-20 15:09:56 +0200 | [diff] [blame] | 2154 | END |
| 2155 | call writefile(lines, 'XtestPreviewPopup') |
| 2156 | let buf = RunVimInTerminal('-S XtestPreviewPopup', #{rows: 14}) |
| 2157 | |
| 2158 | call term_sendkeys(buf, "/theword\<CR>\<C-W>}") |
| 2159 | call term_sendkeys(buf, ":\<CR>") |
| 2160 | call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_1', {}) |
| 2161 | |
| 2162 | call term_sendkeys(buf, "/another\<CR>\<C-W>}") |
| 2163 | call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_2', {}) |
| 2164 | |
Bram Moolenaar | c7c5f10 | 2019-08-21 18:31:03 +0200 | [diff] [blame] | 2165 | call term_sendkeys(buf, ":call popup_move(popup_findpreview(), #{col: 15})\<CR>") |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 2166 | call term_sendkeys(buf, ":\<CR>") |
| 2167 | call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_3', {}) |
| 2168 | |
| 2169 | call term_sendkeys(buf, "/another\<CR>\<C-W>}") |
| 2170 | call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_4', {}) |
| 2171 | |
Bram Moolenaar | 749fa0a | 2019-08-03 16:18:07 +0200 | [diff] [blame] | 2172 | call term_sendkeys(buf, ":cd ..\<CR>:\<CR>") |
| 2173 | call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_5', {}) |
Bram Moolenaar | 1b6d9c4 | 2019-08-05 21:52:04 +0200 | [diff] [blame] | 2174 | call term_sendkeys(buf, ":cd testdir\<CR>") |
| 2175 | |
| 2176 | call term_sendkeys(buf, ":pclose\<CR>") |
Bram Moolenaar | 78d629a | 2019-08-16 17:31:15 +0200 | [diff] [blame] | 2177 | call term_sendkeys(buf, ":\<BS>") |
Bram Moolenaar | 1b6d9c4 | 2019-08-05 21:52:04 +0200 | [diff] [blame] | 2178 | call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_6', {}) |
| 2179 | |
| 2180 | call term_sendkeys(buf, ":pedit +/theword Xtagfile\<CR>") |
| 2181 | call term_sendkeys(buf, ":\<CR>") |
| 2182 | call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_7', {}) |
| 2183 | |
| 2184 | call term_sendkeys(buf, ":pclose\<CR>") |
| 2185 | call term_sendkeys(buf, ":psearch searched\<CR>") |
| 2186 | call term_sendkeys(buf, ":\<CR>") |
| 2187 | call VerifyScreenDump(buf, 'Test_popupwin_previewpopup_8', {}) |
Bram Moolenaar | 749fa0a | 2019-08-03 16:18:07 +0200 | [diff] [blame] | 2188 | |
Bram Moolenaar | f914a33 | 2019-07-20 15:09:56 +0200 | [diff] [blame] | 2189 | call StopVimInTerminal(buf) |
| 2190 | call delete('Xtags') |
| 2191 | call delete('Xtagfile') |
| 2192 | call delete('XtestPreviewPopup') |
Bram Moolenaar | 1b6d9c4 | 2019-08-05 21:52:04 +0200 | [diff] [blame] | 2193 | call delete('Xheader.h') |
Bram Moolenaar | f914a33 | 2019-07-20 15:09:56 +0200 | [diff] [blame] | 2194 | endfunc |
| 2195 | |
Bram Moolenaar | bd483b3 | 2019-08-21 15:13:41 +0200 | [diff] [blame] | 2196 | func Get_popupmenu_lines() |
Bram Moolenaar | 576a4a6 | 2019-08-18 15:25:17 +0200 | [diff] [blame] | 2197 | let lines =<< trim END |
| 2198 | set completeopt+=preview,popup |
| 2199 | set completefunc=CompleteFuncDict |
Bram Moolenaar | 62a0cb4 | 2019-08-18 16:35:23 +0200 | [diff] [blame] | 2200 | hi InfoPopup ctermbg=yellow |
Bram Moolenaar | 576a4a6 | 2019-08-18 15:25:17 +0200 | [diff] [blame] | 2201 | |
| 2202 | func CompleteFuncDict(findstart, base) |
| 2203 | if a:findstart |
| 2204 | if col('.') > 10 |
| 2205 | return col('.') - 10 |
| 2206 | endif |
| 2207 | return 0 |
| 2208 | endif |
| 2209 | |
| 2210 | return { |
| 2211 | \ 'words': [ |
| 2212 | \ { |
| 2213 | \ 'word': 'aword', |
| 2214 | \ 'abbr': 'wrd', |
| 2215 | \ 'menu': 'extra text', |
| 2216 | \ 'info': 'words are cool', |
| 2217 | \ 'kind': 'W', |
| 2218 | \ 'user_data': 'test' |
| 2219 | \ }, |
| 2220 | \ { |
| 2221 | \ 'word': 'anotherword', |
| 2222 | \ 'abbr': 'anotwrd', |
| 2223 | \ 'menu': 'extra text', |
| 2224 | \ 'info': "other words are\ncooler than this and some more text\nto make wrap", |
| 2225 | \ 'kind': 'W', |
| 2226 | \ 'user_data': 'notest' |
| 2227 | \ }, |
| 2228 | \ { |
| 2229 | \ 'word': 'noinfo', |
| 2230 | \ 'abbr': 'noawrd', |
| 2231 | \ 'menu': 'extra text', |
Bram Moolenaar | 62a0cb4 | 2019-08-18 16:35:23 +0200 | [diff] [blame] | 2232 | \ 'info': "lets\nshow\na\nscrollbar\nhere", |
Bram Moolenaar | 576a4a6 | 2019-08-18 15:25:17 +0200 | [diff] [blame] | 2233 | \ 'kind': 'W', |
| 2234 | \ 'user_data': 'notest' |
| 2235 | \ }, |
| 2236 | \ { |
| 2237 | \ 'word': 'thatword', |
| 2238 | \ 'abbr': 'thatwrd', |
| 2239 | \ 'menu': 'extra text', |
| 2240 | \ 'info': 'that word is cool', |
| 2241 | \ 'kind': 'W', |
| 2242 | \ 'user_data': 'notest' |
| 2243 | \ }, |
| 2244 | \ ] |
| 2245 | \ } |
| 2246 | endfunc |
| 2247 | call setline(1, 'text text text text text text text ') |
Bram Moolenaar | c7c5f10 | 2019-08-21 18:31:03 +0200 | [diff] [blame] | 2248 | func ChangeColor() |
| 2249 | let id = popup_findinfo() |
| 2250 | call popup_setoptions(id, #{highlight: 'InfoPopup'}) |
| 2251 | endfunc |
Bram Moolenaar | 576a4a6 | 2019-08-18 15:25:17 +0200 | [diff] [blame] | 2252 | END |
Bram Moolenaar | bd483b3 | 2019-08-21 15:13:41 +0200 | [diff] [blame] | 2253 | return lines |
| 2254 | endfunc |
| 2255 | |
| 2256 | func Test_popupmenu_info_border() |
| 2257 | CheckScreendump |
| 2258 | |
| 2259 | let lines = Get_popupmenu_lines() |
| 2260 | call add(lines, 'set completepopup=height:4,highlight:InfoPopup') |
Bram Moolenaar | 576a4a6 | 2019-08-18 15:25:17 +0200 | [diff] [blame] | 2261 | call writefile(lines, 'XtestInfoPopup') |
Bram Moolenaar | bd483b3 | 2019-08-21 15:13:41 +0200 | [diff] [blame] | 2262 | |
Bram Moolenaar | 576a4a6 | 2019-08-18 15:25:17 +0200 | [diff] [blame] | 2263 | let buf = RunVimInTerminal('-S XtestInfoPopup', #{rows: 14}) |
| 2264 | call term_wait(buf, 50) |
| 2265 | |
| 2266 | call term_sendkeys(buf, "A\<C-X>\<C-U>") |
| 2267 | call VerifyScreenDump(buf, 'Test_popupwin_infopopup_1', {}) |
| 2268 | |
| 2269 | call term_sendkeys(buf, "\<C-N>") |
| 2270 | call VerifyScreenDump(buf, 'Test_popupwin_infopopup_2', {}) |
| 2271 | |
| 2272 | call term_sendkeys(buf, "\<C-N>") |
| 2273 | call VerifyScreenDump(buf, 'Test_popupwin_infopopup_3', {}) |
| 2274 | |
| 2275 | call term_sendkeys(buf, "\<C-N>\<C-N>") |
| 2276 | call VerifyScreenDump(buf, 'Test_popupwin_infopopup_4', {}) |
| 2277 | |
| 2278 | call StopVimInTerminal(buf) |
| 2279 | call delete('XtestInfoPopup') |
| 2280 | endfunc |
| 2281 | |
Bram Moolenaar | bd483b3 | 2019-08-21 15:13:41 +0200 | [diff] [blame] | 2282 | func Test_popupmenu_info_noborder() |
| 2283 | CheckScreendump |
| 2284 | |
| 2285 | let lines = Get_popupmenu_lines() |
| 2286 | call add(lines, 'set completepopup=height:4,border:off') |
| 2287 | call writefile(lines, 'XtestInfoPopupNb') |
| 2288 | |
| 2289 | let buf = RunVimInTerminal('-S XtestInfoPopupNb', #{rows: 14}) |
| 2290 | call term_wait(buf, 50) |
| 2291 | |
| 2292 | call term_sendkeys(buf, "A\<C-X>\<C-U>") |
| 2293 | call VerifyScreenDump(buf, 'Test_popupwin_infopopup_nb_1', {}) |
| 2294 | |
| 2295 | call StopVimInTerminal(buf) |
| 2296 | call delete('XtestInfoPopupNb') |
| 2297 | endfunc |
| 2298 | |
Bram Moolenaar | 258cef5 | 2019-08-21 17:29:29 +0200 | [diff] [blame] | 2299 | func Test_popupmenu_info_align_menu() |
| 2300 | CheckScreendump |
| 2301 | |
| 2302 | let lines = Get_popupmenu_lines() |
| 2303 | call add(lines, 'set completepopup=height:4,border:off,align:menu') |
| 2304 | call writefile(lines, 'XtestInfoPopupNb') |
| 2305 | |
| 2306 | let buf = RunVimInTerminal('-S XtestInfoPopupNb', #{rows: 14}) |
| 2307 | call term_wait(buf, 50) |
| 2308 | |
| 2309 | call term_sendkeys(buf, "A\<C-X>\<C-U>") |
| 2310 | call term_sendkeys(buf, "\<C-N>") |
| 2311 | call term_sendkeys(buf, "\<C-N>") |
| 2312 | call term_sendkeys(buf, "\<C-N>") |
| 2313 | call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_1', {}) |
| 2314 | |
| 2315 | call term_sendkeys(buf, "test text test text test\<C-X>\<C-U>") |
| 2316 | call term_sendkeys(buf, "\<C-N>") |
| 2317 | call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_2', {}) |
| 2318 | |
| 2319 | call term_sendkeys(buf, "\<Esc>") |
Bram Moolenaar | c7c5f10 | 2019-08-21 18:31:03 +0200 | [diff] [blame] | 2320 | call term_sendkeys(buf, ":call ChangeColor()\<CR>") |
Bram Moolenaar | 258cef5 | 2019-08-21 17:29:29 +0200 | [diff] [blame] | 2321 | call term_sendkeys(buf, ":call setline(2, ['x']->repeat(10))\<CR>") |
| 2322 | call term_sendkeys(buf, "Gotest text test text\<C-X>\<C-U>") |
| 2323 | call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_3', {}) |
| 2324 | |
| 2325 | call StopVimInTerminal(buf) |
| 2326 | call delete('XtestInfoPopupNb') |
| 2327 | endfunc |
| 2328 | |
Bram Moolenaar | 331bafd | 2019-07-20 17:46:05 +0200 | [diff] [blame] | 2329 | " vim: shiftwidth=2 sts=2 |