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