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