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