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