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