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