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