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