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