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