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