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