Bram Moolenaar | 00672e1 | 2016-06-26 18:38:13 +0200 | [diff] [blame] | 1 | " Test for completion menu |
| 2 | |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 3 | source util/screendump.vim |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 4 | |
Bram Moolenaar | 00672e1 | 2016-06-26 18:38:13 +0200 | [diff] [blame] | 5 | let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] |
| 6 | let g:setting = '' |
| 7 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 8 | func ListMonths() |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 9 | if g:setting != '' |
| 10 | exe ":set" g:setting |
| 11 | endif |
Bram Moolenaar | aed6d0b | 2017-01-27 21:48:54 +0100 | [diff] [blame] | 12 | let mth = copy(g:months) |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 13 | let entered = strcharpart(getline('.'),0,col('.')) |
| 14 | if !empty(entered) |
Bram Moolenaar | aed6d0b | 2017-01-27 21:48:54 +0100 | [diff] [blame] | 15 | let mth = filter(mth, 'v:val=~"^".entered') |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 16 | endif |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 17 | call complete(1, mth) |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 18 | return '' |
Bram Moolenaar | 00672e1 | 2016-06-26 18:38:13 +0200 | [diff] [blame] | 19 | endfunc |
| 20 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 21 | func Test_popup_complete2() |
Bram Moolenaar | 9e02cfa | 2016-09-22 21:27:11 +0200 | [diff] [blame] | 22 | " Although the popupmenu is not visible, this does not mean completion mode |
| 23 | " has ended. After pressing <f5> to complete the currently typed char, Vim |
| 24 | " still stays in the first state of the completion (:h ins-completion-menu), |
| 25 | " although the popupmenu wasn't shown <c-e> will remove the inserted |
| 26 | " completed text (:h complete_CTRL-E), while the following <c-e> will behave |
| 27 | " like expected (:h i_CTRL-E) |
Bram Moolenaar | dac1947 | 2016-09-03 22:35:40 +0200 | [diff] [blame] | 28 | new |
| 29 | inoremap <f5> <c-r>=ListMonths()<cr> |
| 30 | call append(1, ["December2015"]) |
| 31 | :1 |
| 32 | call feedkeys("aD\<f5>\<C-E>\<C-E>\<C-E>\<C-E>\<enter>\<esc>", 'tx') |
Bram Moolenaar | 9e02cfa | 2016-09-22 21:27:11 +0200 | [diff] [blame] | 33 | call assert_equal(["Dece", "", "December2015"], getline(1,3)) |
Bram Moolenaar | dac1947 | 2016-09-03 22:35:40 +0200 | [diff] [blame] | 34 | %d |
| 35 | bw! |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 36 | endfunc |
Bram Moolenaar | dac1947 | 2016-09-03 22:35:40 +0200 | [diff] [blame] | 37 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 38 | func Test_popup_complete() |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 39 | new |
| 40 | inoremap <f5> <c-r>=ListMonths()<cr> |
| 41 | |
| 42 | " <C-E> - select original typed text before the completion started |
| 43 | call feedkeys("aJu\<f5>\<down>\<c-e>\<esc>", 'tx') |
| 44 | call assert_equal(["Ju"], getline(1,2)) |
| 45 | %d |
| 46 | |
| 47 | " <C-Y> - accept current match |
| 48 | call feedkeys("a\<f5>". repeat("\<down>",7). "\<c-y>\<esc>", 'tx') |
| 49 | call assert_equal(["August"], getline(1,2)) |
| 50 | %d |
| 51 | |
| 52 | " <BS> - Delete one character from the inserted text (state: 1) |
| 53 | " TODO: This should not end the completion, but it does. |
| 54 | " This should according to the documentation: |
| 55 | " January |
| 56 | " but instead, this does |
| 57 | " Januar |
| 58 | " (idea is, C-L inserts the match from the popup menu |
| 59 | " but if the menu is closed, it will insert the character <c-l> |
| 60 | call feedkeys("aJ\<f5>\<bs>\<c-l>\<esc>", 'tx') |
| 61 | call assert_equal(["Januar"], getline(1,2)) |
| 62 | %d |
| 63 | |
| 64 | " any-non special character: Stop completion without changing the match |
| 65 | " and insert the typed character |
| 66 | call feedkeys("a\<f5>20", 'tx') |
| 67 | call assert_equal(["January20"], getline(1,2)) |
| 68 | %d |
| 69 | |
| 70 | " any-non printable, non-white character: Add this character and |
| 71 | " reduce number of matches |
| 72 | call feedkeys("aJu\<f5>\<c-p>l\<c-y>", 'tx') |
| 73 | call assert_equal(["Jul"], getline(1,2)) |
| 74 | %d |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 75 | |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 76 | " any-non printable, non-white character: Add this character and |
| 77 | " reduce number of matches |
| 78 | call feedkeys("aJu\<f5>\<c-p>l\<c-n>\<c-y>", 'tx') |
| 79 | call assert_equal(["July"], getline(1,2)) |
| 80 | %d |
| 81 | |
| 82 | " any-non printable, non-white character: Add this character and |
| 83 | " reduce number of matches |
| 84 | call feedkeys("aJu\<f5>\<c-p>l\<c-e>", 'tx') |
| 85 | call assert_equal(["Jul"], getline(1,2)) |
| 86 | %d |
| 87 | |
| 88 | " <BS> - Delete one character from the inserted text (state: 2) |
| 89 | call feedkeys("a\<f5>\<c-n>\<bs>", 'tx') |
| 90 | call assert_equal(["Februar"], getline(1,2)) |
| 91 | %d |
| 92 | |
| 93 | " <c-l> - Insert one character from the current match |
| 94 | call feedkeys("aJ\<f5>".repeat("\<c-n>",3)."\<c-l>\<esc>", 'tx') |
| 95 | call assert_equal(["J"], getline(1,2)) |
| 96 | %d |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 97 | |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 98 | " <c-l> - Insert one character from the current match |
| 99 | call feedkeys("aJ\<f5>".repeat("\<c-n>",4)."\<c-l>\<esc>", 'tx') |
| 100 | call assert_equal(["January"], getline(1,2)) |
| 101 | %d |
| 102 | |
| 103 | " <c-y> - Accept current selected match |
| 104 | call feedkeys("aJ\<f5>\<c-y>\<esc>", 'tx') |
| 105 | call assert_equal(["January"], getline(1,2)) |
| 106 | %d |
| 107 | |
| 108 | " <c-e> - End completion, go back to what was there before selecting a match |
| 109 | call feedkeys("aJu\<f5>\<c-e>\<esc>", 'tx') |
| 110 | call assert_equal(["Ju"], getline(1,2)) |
| 111 | %d |
| 112 | |
| 113 | " <PageUp> - Select a match several entries back |
| 114 | call feedkeys("a\<f5>\<PageUp>\<c-y>\<esc>", 'tx') |
| 115 | call assert_equal([""], getline(1,2)) |
| 116 | %d |
| 117 | |
| 118 | " <PageUp><PageUp> - Select a match several entries back |
| 119 | call feedkeys("a\<f5>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx') |
| 120 | call assert_equal(["December"], getline(1,2)) |
| 121 | %d |
| 122 | |
| 123 | " <PageUp><PageUp><PageUp> - Select a match several entries back |
| 124 | call feedkeys("a\<f5>\<PageUp>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx') |
| 125 | call assert_equal(["February"], getline(1,2)) |
| 126 | %d |
| 127 | |
| 128 | " <PageDown> - Select a match several entries further |
| 129 | call feedkeys("a\<f5>\<PageDown>\<c-y>\<esc>", 'tx') |
| 130 | call assert_equal(["November"], getline(1,2)) |
| 131 | %d |
| 132 | |
| 133 | " <PageDown><PageDown> - Select a match several entries further |
| 134 | call feedkeys("a\<f5>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx') |
| 135 | call assert_equal(["December"], getline(1,2)) |
| 136 | %d |
| 137 | |
| 138 | " <PageDown><PageDown><PageDown> - Select a match several entries further |
| 139 | call feedkeys("a\<f5>\<PageDown>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx') |
| 140 | call assert_equal([""], getline(1,2)) |
| 141 | %d |
| 142 | |
| 143 | " <PageDown><PageDown><PageDown><PageDown> - Select a match several entries further |
| 144 | call feedkeys("a\<f5>".repeat("\<PageDown>",4)."\<c-y>\<esc>", 'tx') |
| 145 | call assert_equal(["October"], getline(1,2)) |
| 146 | %d |
| 147 | |
| 148 | " <Up> - Select a match don't insert yet |
| 149 | call feedkeys("a\<f5>\<Up>\<c-y>\<esc>", 'tx') |
| 150 | call assert_equal([""], getline(1,2)) |
| 151 | %d |
| 152 | |
| 153 | " <Up><Up> - Select a match don't insert yet |
| 154 | call feedkeys("a\<f5>\<Up>\<Up>\<c-y>\<esc>", 'tx') |
| 155 | call assert_equal(["December"], getline(1,2)) |
| 156 | %d |
| 157 | |
| 158 | " <Up><Up><Up> - Select a match don't insert yet |
| 159 | call feedkeys("a\<f5>\<Up>\<Up>\<Up>\<c-y>\<esc>", 'tx') |
| 160 | call assert_equal(["November"], getline(1,2)) |
| 161 | %d |
| 162 | |
| 163 | " <Tab> - Stop completion and insert the match |
| 164 | call feedkeys("a\<f5>\<Tab>\<c-y>\<esc>", 'tx') |
| 165 | call assert_equal(["January "], getline(1,2)) |
| 166 | %d |
| 167 | |
| 168 | " <Space> - Stop completion and insert the match |
| 169 | call feedkeys("a\<f5>".repeat("\<c-p>",5)." \<esc>", 'tx') |
| 170 | call assert_equal(["September "], getline(1,2)) |
| 171 | %d |
| 172 | |
| 173 | " <Enter> - Use the text and insert line break (state: 1) |
| 174 | call feedkeys("a\<f5>\<enter>\<esc>", 'tx') |
| 175 | call assert_equal(["January", ''], getline(1,2)) |
| 176 | %d |
| 177 | |
| 178 | " <Enter> - Insert the current selected text (state: 2) |
| 179 | call feedkeys("a\<f5>".repeat("\<Up>",5)."\<enter>\<esc>", 'tx') |
| 180 | call assert_equal(["September"], getline(1,2)) |
| 181 | %d |
| 182 | |
| 183 | " Insert match immediately, if there is only one match |
| 184 | " <c-y> selects a character from the line above |
| 185 | call append(0, ["December2015"]) |
| 186 | call feedkeys("aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>", 'tx') |
| 187 | call assert_equal(["December2015", "December2015", ""], getline(1,3)) |
| 188 | %d |
| 189 | |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 190 | " use menuone for 'completeopt' |
| 191 | " Since for the first <c-y> the menu is still shown, will only select |
| 192 | " three letters from the line above |
| 193 | set completeopt&vim |
| 194 | set completeopt+=menuone |
| 195 | call append(0, ["December2015"]) |
| 196 | call feedkeys("aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>", 'tx') |
| 197 | call assert_equal(["December2015", "December201", ""], getline(1,3)) |
| 198 | %d |
| 199 | |
| 200 | " use longest for 'completeopt' |
| 201 | set completeopt&vim |
| 202 | call feedkeys("aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>", 'tx') |
| 203 | set completeopt+=longest |
| 204 | call feedkeys("aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>", 'tx') |
| 205 | call assert_equal(["M", "Ma", ""], getline(1,3)) |
| 206 | %d |
| 207 | |
| 208 | " use noselect/noinsert for 'completeopt' |
| 209 | set completeopt&vim |
| 210 | call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') |
| 211 | set completeopt+=noselect |
| 212 | call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') |
| 213 | set completeopt-=noselect completeopt+=noinsert |
| 214 | call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') |
| 215 | call assert_equal(["March", "M", "March"], getline(1,4)) |
| 216 | %d |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 217 | endfunc |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 218 | |
| 219 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 220 | func Test_popup_completion_insertmode() |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 221 | new |
| 222 | inoremap <F5> <C-R>=ListMonths()<CR> |
| 223 | |
| 224 | call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx') |
| 225 | call assert_equal('February', getline(1)) |
| 226 | %d |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 227 | " Set noinsertmode |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 228 | let g:setting = 'noinsertmode' |
| 229 | call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx') |
| 230 | call assert_equal('February', getline(1)) |
| 231 | call assert_false(pumvisible()) |
| 232 | %d |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 233 | " Go through all matches, until none is selected |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 234 | let g:setting = '' |
| 235 | call feedkeys("a\<f5>". repeat("\<c-n>",12)."\<enter>\<esc>", 'tx') |
| 236 | call assert_equal('', getline(1)) |
| 237 | %d |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 238 | " select previous entry |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 239 | call feedkeys("a\<f5>\<c-p>\<enter>\<esc>", 'tx') |
| 240 | call assert_equal('', getline(1)) |
| 241 | %d |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 242 | " select last entry |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 243 | call feedkeys("a\<f5>\<c-p>\<c-p>\<enter>\<esc>", 'tx') |
| 244 | call assert_equal('December', getline(1)) |
| 245 | |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 246 | iunmap <F5> |
| 247 | endfunc |
| 248 | |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 249 | func Test_noinsert_complete() |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 250 | func! s:complTest1() abort |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 251 | eval ['source', 'soundfold']->complete(1) |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 252 | return '' |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 253 | endfunc |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 254 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 255 | func! s:complTest2() abort |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 256 | call complete(1, ['source', 'soundfold']) |
| 257 | return '' |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 258 | endfunc |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 259 | |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 260 | new |
| 261 | set completeopt+=noinsert |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 262 | inoremap <F5> <C-R>=s:complTest1()<CR> |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 263 | call feedkeys("i\<F5>soun\<CR>\<CR>\<ESC>.", 'tx') |
| 264 | call assert_equal('soundfold', getline(1)) |
| 265 | call assert_equal('soundfold', getline(2)) |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 266 | bwipe! |
Bram Moolenaar | 32b808a | 2016-07-09 21:57:20 +0200 | [diff] [blame] | 267 | |
| 268 | new |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 269 | inoremap <F5> <C-R>=s:complTest2()<CR> |
Bram Moolenaar | 32b808a | 2016-07-09 21:57:20 +0200 | [diff] [blame] | 270 | call feedkeys("i\<F5>\<CR>\<ESC>", 'tx') |
| 271 | call assert_equal('source', getline(1)) |
| 272 | bwipe! |
| 273 | |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 274 | set completeopt-=noinsert |
| 275 | iunmap <F5> |
Bram Moolenaar | 00672e1 | 2016-06-26 18:38:13 +0200 | [diff] [blame] | 276 | endfunc |
Bram Moolenaar | 32b808a | 2016-07-09 21:57:20 +0200 | [diff] [blame] | 277 | |
Bram Moolenaar | 73655cf | 2019-04-06 13:45:55 +0200 | [diff] [blame] | 278 | func Test_complete_no_filter() |
| 279 | func! s:complTest1() abort |
| 280 | call complete(1, [{'word': 'foobar'}]) |
| 281 | return '' |
| 282 | endfunc |
| 283 | func! s:complTest2() abort |
| 284 | call complete(1, [{'word': 'foobar', 'equal': 1}]) |
| 285 | return '' |
| 286 | endfunc |
| 287 | |
| 288 | let completeopt = &completeopt |
| 289 | |
| 290 | " without equal=1 |
| 291 | new |
| 292 | set completeopt=menuone,noinsert,menu |
| 293 | inoremap <F5> <C-R>=s:complTest1()<CR> |
| 294 | call feedkeys("i\<F5>z\<CR>\<CR>\<ESC>.", 'tx') |
| 295 | call assert_equal('z', getline(1)) |
| 296 | bwipe! |
| 297 | |
| 298 | " with equal=1 |
| 299 | new |
| 300 | set completeopt=menuone,noinsert,menu |
| 301 | inoremap <F5> <C-R>=s:complTest2()<CR> |
| 302 | call feedkeys("i\<F5>z\<CR>\<CR>\<ESC>.", 'tx') |
| 303 | call assert_equal('foobar', getline(1)) |
| 304 | bwipe! |
| 305 | |
| 306 | let &completeopt = completeopt |
| 307 | iunmap <F5> |
| 308 | endfunc |
| 309 | |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 310 | func Test_compl_vim_cmds_after_register_expr() |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 311 | func! s:test_func() |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 312 | return 'autocmd ' |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 313 | endfunc |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 314 | augroup AAAAA_Group |
| 315 | au! |
| 316 | augroup END |
Bram Moolenaar | 32b808a | 2016-07-09 21:57:20 +0200 | [diff] [blame] | 317 | |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 318 | new |
| 319 | call feedkeys("i\<c-r>=s:test_func()\<CR>\<C-x>\<C-v>\<Esc>", 'tx') |
| 320 | call assert_equal('autocmd AAAAA_Group', getline(1)) |
| 321 | autocmd! AAAAA_Group |
| 322 | augroup! AAAAA_Group |
| 323 | bwipe! |
| 324 | endfunc |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 325 | |
zeertzjq | ee44603 | 2022-04-30 15:02:22 +0100 | [diff] [blame] | 326 | func Test_compl_ignore_mappings() |
| 327 | call setline(1, ['foo', 'bar', 'baz', 'foobar']) |
| 328 | inoremap <C-P> (C-P) |
| 329 | inoremap <C-N> (C-N) |
| 330 | normal! G |
| 331 | call feedkeys("o\<C-X>\<C-N>\<C-N>\<C-N>\<C-P>\<C-N>\<C-Y>", 'tx') |
| 332 | call assert_equal('baz', getline('.')) |
| 333 | " Also test with unsimplified keys |
| 334 | call feedkeys("o\<C-X>\<*C-N>\<*C-N>\<*C-N>\<*C-P>\<*C-N>\<C-Y>", 'tx') |
| 335 | call assert_equal('baz', getline('.')) |
| 336 | iunmap <C-P> |
| 337 | iunmap <C-N> |
| 338 | bwipe! |
| 339 | endfunc |
| 340 | |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 341 | func DummyCompleteOne(findstart, base) |
| 342 | if a:findstart |
| 343 | return 0 |
| 344 | else |
| 345 | wincmd n |
| 346 | return ['onedef', 'oneDEF'] |
| 347 | endif |
| 348 | endfunc |
| 349 | |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 350 | " Test that nothing happens if the 'completefunc' tries to open |
| 351 | " a new window (fails to open window, continues) |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 352 | func Test_completefunc_opens_new_window_one() |
| 353 | new |
| 354 | let winid = win_getid() |
| 355 | setlocal completefunc=DummyCompleteOne |
| 356 | call setline(1, 'one') |
| 357 | /^one |
Bram Moolenaar | 28976e2 | 2021-01-29 21:07:07 +0100 | [diff] [blame] | 358 | call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E565:') |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 359 | call assert_equal(winid, win_getid()) |
Bram Moolenaar | 28ee892 | 2020-10-28 20:20:00 +0100 | [diff] [blame] | 360 | call assert_equal('onedef', getline(1)) |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 361 | q! |
| 362 | endfunc |
| 363 | |
| 364 | " Test that nothing happens if the 'completefunc' opens |
| 365 | " a new window (no completion, no crash) |
| 366 | func DummyCompleteTwo(findstart, base) |
| 367 | if a:findstart |
| 368 | wincmd n |
| 369 | return 0 |
| 370 | else |
| 371 | return ['twodef', 'twoDEF'] |
| 372 | endif |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 373 | endfunc |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 374 | |
| 375 | " Test that nothing happens if the 'completefunc' opens |
| 376 | " a new window (no completion, no crash) |
| 377 | func Test_completefunc_opens_new_window_two() |
| 378 | new |
| 379 | let winid = win_getid() |
| 380 | setlocal completefunc=DummyCompleteTwo |
| 381 | call setline(1, 'two') |
| 382 | /^two |
Bram Moolenaar | 3eb6bd9 | 2021-01-29 21:47:24 +0100 | [diff] [blame] | 383 | call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E565:') |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 384 | call assert_equal(winid, win_getid()) |
Bram Moolenaar | 3eb6bd9 | 2021-01-29 21:47:24 +0100 | [diff] [blame] | 385 | call assert_equal('twodef', getline(1)) |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 386 | q! |
| 387 | endfunc |
| 388 | |
| 389 | func DummyCompleteThree(findstart, base) |
| 390 | if a:findstart |
| 391 | return 0 |
| 392 | else |
| 393 | return ['threedef', 'threeDEF'] |
| 394 | endif |
| 395 | endfunc |
| 396 | |
| 397 | :"Test that 'completefunc' works when it's OK. |
| 398 | func Test_completefunc_works() |
| 399 | new |
| 400 | let winid = win_getid() |
| 401 | setlocal completefunc=DummyCompleteThree |
| 402 | call setline(1, 'three') |
| 403 | /^three |
| 404 | call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x") |
| 405 | call assert_equal(winid, win_getid()) |
| 406 | call assert_equal('threeDEF', getline(1)) |
| 407 | q! |
| 408 | endfunc |
| 409 | |
| 410 | func DummyCompleteFour(findstart, base) |
| 411 | if a:findstart |
| 412 | return 0 |
| 413 | else |
| 414 | call complete_add('four1') |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 415 | eval 'four2'->complete_add() |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 416 | call complete_check() |
| 417 | call complete_add('four3') |
| 418 | call complete_add('four4') |
| 419 | call complete_check() |
| 420 | call complete_add('four5') |
| 421 | call complete_add('four6') |
| 422 | return [] |
| 423 | endif |
| 424 | endfunc |
| 425 | |
Bram Moolenaar | 60ef3e8 | 2016-10-29 14:37:56 +0200 | [diff] [blame] | 426 | " Test that 'omnifunc' works when it's OK. |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 427 | func Test_omnifunc_with_check() |
| 428 | new |
| 429 | setlocal omnifunc=DummyCompleteFour |
| 430 | call setline(1, 'four') |
| 431 | /^four |
| 432 | call feedkeys("A\<C-X>\<C-O>\<C-N>\<Esc>", "x") |
| 433 | call assert_equal('four2', getline(1)) |
| 434 | |
| 435 | call setline(1, 'four') |
| 436 | /^four |
| 437 | call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<Esc>", "x") |
| 438 | call assert_equal('four3', getline(1)) |
| 439 | |
| 440 | call setline(1, 'four') |
| 441 | /^four |
| 442 | call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<C-N>\<Esc>", "x") |
| 443 | call assert_equal('four5', getline(1)) |
| 444 | |
| 445 | q! |
| 446 | endfunc |
| 447 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 448 | func UndoComplete() |
Bram Moolenaar | 869e352 | 2016-10-16 15:35:47 +0200 | [diff] [blame] | 449 | call complete(1, ['January', 'February', 'March', |
| 450 | \ 'April', 'May', 'June', 'July', 'August', 'September', |
| 451 | \ 'October', 'November', 'December']) |
| 452 | return '' |
| 453 | endfunc |
| 454 | |
| 455 | " Test that no undo item is created when no completion is inserted |
| 456 | func Test_complete_no_undo() |
| 457 | set completeopt=menu,preview,noinsert,noselect |
| 458 | inoremap <Right> <C-R>=UndoComplete()<CR> |
| 459 | new |
| 460 | call feedkeys("ixxx\<CR>\<CR>yyy\<Esc>k", 'xt') |
| 461 | call feedkeys("iaaa\<Esc>0", 'xt') |
| 462 | call assert_equal('aaa', getline(2)) |
| 463 | call feedkeys("i\<Right>\<Esc>", 'xt') |
| 464 | call assert_equal('aaa', getline(2)) |
| 465 | call feedkeys("u", 'xt') |
| 466 | call assert_equal('', getline(2)) |
| 467 | |
Bram Moolenaar | cbd3bd6 | 2016-10-17 20:47:02 +0200 | [diff] [blame] | 468 | call feedkeys("ibbb\<Esc>0", 'xt') |
| 469 | call assert_equal('bbb', getline(2)) |
| 470 | call feedkeys("A\<Right>\<Down>\<CR>\<Esc>", 'xt') |
| 471 | call assert_equal('January', getline(2)) |
| 472 | call feedkeys("u", 'xt') |
| 473 | call assert_equal('bbb', getline(2)) |
| 474 | |
Bram Moolenaar | 9ec7fa8 | 2016-10-18 13:06:41 +0200 | [diff] [blame] | 475 | call feedkeys("A\<Right>\<C-N>\<Esc>", 'xt') |
| 476 | call assert_equal('January', getline(2)) |
| 477 | call feedkeys("u", 'xt') |
| 478 | call assert_equal('bbb', getline(2)) |
| 479 | |
Bram Moolenaar | 869e352 | 2016-10-16 15:35:47 +0200 | [diff] [blame] | 480 | iunmap <Right> |
| 481 | set completeopt& |
| 482 | q! |
| 483 | endfunc |
| 484 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 485 | func DummyCompleteFive(findstart, base) |
Bram Moolenaar | 60ef3e8 | 2016-10-29 14:37:56 +0200 | [diff] [blame] | 486 | if a:findstart |
| 487 | return 0 |
| 488 | else |
| 489 | return [ |
| 490 | \ { 'word': 'January', 'info': "info1-1\n1-2\n1-3" }, |
| 491 | \ { 'word': 'February', 'info': "info2-1\n2-2\n2-3" }, |
| 492 | \ { 'word': 'March', 'info': "info3-1\n3-2\n3-3" }, |
| 493 | \ { 'word': 'April', 'info': "info4-1\n4-2\n4-3" }, |
| 494 | \ { 'word': 'May', 'info': "info5-1\n5-2\n5-3" }, |
| 495 | \ ] |
| 496 | endif |
| 497 | endfunc |
| 498 | |
| 499 | " Test that 'completefunc' on Scratch buffer with preview window works when |
| 500 | " it's OK. |
| 501 | func Test_completefunc_with_scratch_buffer() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 502 | CheckFeature quickfix |
| 503 | |
Bram Moolenaar | 60ef3e8 | 2016-10-29 14:37:56 +0200 | [diff] [blame] | 504 | new +setlocal\ buftype=nofile\ bufhidden=wipe\ noswapfile |
| 505 | set completeopt+=preview |
| 506 | setlocal completefunc=DummyCompleteFive |
| 507 | call feedkeys("A\<C-X>\<C-U>\<C-N>\<C-N>\<C-N>\<Esc>", "x") |
| 508 | call assert_equal(['April'], getline(1, '$')) |
| 509 | pclose |
| 510 | q! |
| 511 | set completeopt& |
| 512 | endfunc |
Bram Moolenaar | 869e352 | 2016-10-16 15:35:47 +0200 | [diff] [blame] | 513 | |
Bram Moolenaar | 73fd498 | 2016-12-09 19:36:56 +0100 | [diff] [blame] | 514 | " <C-E> - select original typed text before the completion started without |
| 515 | " auto-wrap text. |
| 516 | func Test_completion_ctrl_e_without_autowrap() |
| 517 | new |
Bram Moolenaar | aed6d0b | 2017-01-27 21:48:54 +0100 | [diff] [blame] | 518 | let tw_save = &tw |
Bram Moolenaar | 73fd498 | 2016-12-09 19:36:56 +0100 | [diff] [blame] | 519 | set tw=78 |
| 520 | let li = [ |
| 521 | \ '" zzz', |
| 522 | \ '" zzzyyyyyyyyyyyyyyyyyyy'] |
| 523 | call setline(1, li) |
| 524 | 0 |
| 525 | call feedkeys("A\<C-X>\<C-N>\<C-E>\<Esc>", "tx") |
| 526 | call assert_equal(li, getline(1, '$')) |
| 527 | |
Bram Moolenaar | aed6d0b | 2017-01-27 21:48:54 +0100 | [diff] [blame] | 528 | let &tw = tw_save |
Bram Moolenaar | 73fd498 | 2016-12-09 19:36:56 +0100 | [diff] [blame] | 529 | q! |
| 530 | endfunc |
| 531 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 532 | func DummyCompleteSix() |
Bram Moolenaar | aed6d0b | 2017-01-27 21:48:54 +0100 | [diff] [blame] | 533 | call complete(1, ['Hello', 'World']) |
| 534 | return '' |
| 535 | endfunction |
| 536 | |
| 537 | " complete() correctly clears the list of autocomplete candidates |
| 538 | " See #1411 |
| 539 | func Test_completion_clear_candidate_list() |
| 540 | new |
| 541 | %d |
| 542 | " select first entry from the completion popup |
| 543 | call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>", "tx") |
| 544 | call assert_equal('Hello', getline(1)) |
| 545 | %d |
| 546 | " select second entry from the completion popup |
| 547 | call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>", "tx") |
| 548 | call assert_equal('World', getline(1)) |
| 549 | %d |
| 550 | " select original text |
| 551 | call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>", "tx") |
| 552 | call assert_equal(' xxx', getline(1)) |
| 553 | %d |
| 554 | " back at first entry from completion list |
| 555 | call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>\<C-N>", "tx") |
| 556 | call assert_equal('Hello', getline(1)) |
| 557 | |
| 558 | bw! |
| 559 | endfunc |
| 560 | |
Bram Moolenaar | 190b04c | 2017-02-09 17:37:03 +0100 | [diff] [blame] | 561 | func Test_completion_respect_bs_option() |
| 562 | new |
| 563 | let li = ["aaa", "aaa12345", "aaaabcdef", "aaaABC"] |
| 564 | |
| 565 | set bs=indent,eol |
| 566 | call setline(1, li) |
| 567 | 1 |
| 568 | call feedkeys("A\<C-X>\<C-N>\<C-P>\<BS>\<BS>\<BS>\<Esc>", "tx") |
| 569 | call assert_equal('aaa', getline(1)) |
| 570 | |
| 571 | %d |
| 572 | set bs=indent,eol,start |
| 573 | call setline(1, li) |
| 574 | 1 |
| 575 | call feedkeys("A\<C-X>\<C-N>\<C-P>\<BS>\<BS>\<BS>\<Esc>", "tx") |
| 576 | call assert_equal('', getline(1)) |
| 577 | |
| 578 | bw! |
| 579 | endfunc |
| 580 | |
Bram Moolenaar | d56a79d | 2017-02-19 15:26:18 +0100 | [diff] [blame] | 581 | func CompleteUndo() abort |
| 582 | call complete(1, g:months) |
| 583 | return '' |
| 584 | endfunc |
| 585 | |
| 586 | func Test_completion_can_undo() |
| 587 | inoremap <Right> <c-r>=CompleteUndo()<cr> |
| 588 | set completeopt+=noinsert,noselect |
| 589 | |
| 590 | new |
| 591 | call feedkeys("a\<Right>a\<Esc>", 'xt') |
| 592 | call assert_equal('a', getline(1)) |
| 593 | undo |
| 594 | call assert_equal('', getline(1)) |
| 595 | |
| 596 | bwipe! |
| 597 | set completeopt& |
| 598 | iunmap <Right> |
| 599 | endfunc |
| 600 | |
Bram Moolenaar | d099e03 | 2017-02-21 23:00:36 +0100 | [diff] [blame] | 601 | func Test_completion_comment_formatting() |
| 602 | new |
| 603 | setl formatoptions=tcqro |
| 604 | call feedkeys("o/*\<cr>\<cr>/\<esc>", 'tx') |
| 605 | call assert_equal(['', '/*', ' *', ' */'], getline(1,4)) |
| 606 | %d |
| 607 | call feedkeys("o/*\<cr>foobar\<cr>/\<esc>", 'tx') |
| 608 | call assert_equal(['', '/*', ' * foobar', ' */'], getline(1,4)) |
| 609 | %d |
| 610 | try |
| 611 | call feedkeys("o/*\<cr>\<cr>\<c-x>\<c-u>/\<esc>", 'tx') |
Bram Moolenaar | 3717540 | 2017-03-18 20:18:45 +0100 | [diff] [blame] | 612 | call assert_report('completefunc not set, should have failed') |
Bram Moolenaar | d099e03 | 2017-02-21 23:00:36 +0100 | [diff] [blame] | 613 | catch |
| 614 | call assert_exception('E764:') |
| 615 | endtry |
| 616 | call assert_equal(['', '/*', ' *', ' */'], getline(1,4)) |
| 617 | bwipe! |
| 618 | endfunc |
| 619 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 620 | func MessCompleteMonths() |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 621 | for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep") |
| 622 | call complete_add(m) |
| 623 | if complete_check() |
| 624 | break |
| 625 | endif |
| 626 | endfor |
| 627 | return [] |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 628 | endfunc |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 629 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 630 | func MessCompleteMore() |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 631 | call complete(1, split("Oct Nov Dec")) |
| 632 | return [] |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 633 | endfunc |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 634 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 635 | func MessComplete(findstart, base) |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 636 | if a:findstart |
| 637 | let line = getline('.') |
| 638 | let start = col('.') - 1 |
| 639 | while start > 0 && line[start - 1] =~ '\a' |
| 640 | let start -= 1 |
| 641 | endwhile |
| 642 | return start |
| 643 | else |
| 644 | call MessCompleteMonths() |
| 645 | call MessCompleteMore() |
| 646 | return [] |
| 647 | endif |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 648 | endfunc |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 649 | |
| 650 | func Test_complete_func_mess() |
| 651 | " Calling complete() after complete_add() in 'completefunc' is wrong, but it |
| 652 | " should not crash. |
| 653 | set completefunc=MessComplete |
| 654 | new |
| 655 | call setline(1, 'Ju') |
zeertzjq | cfe4565 | 2022-05-27 17:26:55 +0100 | [diff] [blame] | 656 | call assert_fails('call feedkeys("A\<c-x>\<c-u>/\<esc>", "tx")', 'E565:') |
Bram Moolenaar | 28976e2 | 2021-01-29 21:07:07 +0100 | [diff] [blame] | 657 | call assert_equal('Jan/', getline(1)) |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 658 | bwipe! |
| 659 | set completefunc= |
| 660 | endfunc |
| 661 | |
Bram Moolenaar | 24a9e34 | 2017-06-24 15:39:07 +0200 | [diff] [blame] | 662 | func Test_complete_CTRLN_startofbuffer() |
| 663 | new |
| 664 | call setline(1, [ 'organize(cupboard, 3, 2);', |
| 665 | \ 'prioritize(bureau, 8, 7);', |
| 666 | \ 'realize(bannister, 4, 4);', |
| 667 | \ 'moralize(railing, 3,9);']) |
| 668 | let expected=['cupboard.organize(3, 2);', |
| 669 | \ 'bureau.prioritize(8, 7);', |
| 670 | \ 'bannister.realize(4, 4);', |
| 671 | \ 'railing.moralize(3,9);'] |
| 672 | call feedkeys("qai\<c-n>\<c-n>.\<esc>3wdW\<cr>q3@a", 'tx') |
| 673 | call assert_equal(expected, getline(1,'$')) |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 674 | bwipe! |
| 675 | endfunc |
| 676 | |
| 677 | func Test_popup_and_window_resize() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 678 | CheckFeature terminal |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 679 | CheckFeature quickfix |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 680 | CheckNotGui |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 681 | let g:test_is_flaky = 1 |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 682 | |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 683 | let h = winheight(0) |
| 684 | if h < 15 |
| 685 | return |
| 686 | endif |
Bram Moolenaar | b315876 | 2017-11-02 17:50:14 +0100 | [diff] [blame] | 687 | let rows = h / 3 |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 688 | let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': rows}) |
| 689 | call term_sendkeys(buf, (h / 3 - 1) . "o\<esc>") |
Bram Moolenaar | b315876 | 2017-11-02 17:50:14 +0100 | [diff] [blame] | 690 | " Wait for the nested Vim to exit insert mode, where it will show the ruler. |
| 691 | " Need to trigger a redraw. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 692 | call WaitFor({-> execute("redraw") == "" && term_getline(buf, rows) =~ '\<' . rows . ',.*Bot'}) |
Bram Moolenaar | b315876 | 2017-11-02 17:50:14 +0100 | [diff] [blame] | 693 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 694 | call term_sendkeys(buf, "Gi\<c-x>") |
| 695 | call term_sendkeys(buf, "\<c-v>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 696 | call TermWait(buf, 50) |
Bram Moolenaar | f52c383 | 2017-09-30 16:49:19 +0200 | [diff] [blame] | 697 | " popup first entry "!" must be at the top |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 698 | call WaitForAssert({-> assert_match('^!\s*$', term_getline(buf, 1))}) |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 699 | exe 'resize +' . (h - 1) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 700 | call TermWait(buf, 50) |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 701 | redraw! |
Bram Moolenaar | f52c383 | 2017-09-30 16:49:19 +0200 | [diff] [blame] | 702 | " popup shifted down, first line is now empty |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 703 | call WaitForAssert({-> assert_equal('', term_getline(buf, 1))}) |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 704 | sleep 100m |
Bram Moolenaar | f52c383 | 2017-09-30 16:49:19 +0200 | [diff] [blame] | 705 | " popup is below cursor line and shows first match "!" |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 706 | call WaitForAssert({-> assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0] + 1))}) |
Bram Moolenaar | f52c383 | 2017-09-30 16:49:19 +0200 | [diff] [blame] | 707 | " cursor line also shows ! |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 708 | call assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0])) |
Bram Moolenaar | 24a9e34 | 2017-06-24 15:39:07 +0200 | [diff] [blame] | 709 | bwipe! |
| 710 | endfunc |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 711 | |
Bram Moolenaar | 9ad89c6 | 2017-10-26 22:04:04 +0200 | [diff] [blame] | 712 | func Test_popup_and_preview_autocommand() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 713 | CheckFeature python |
| 714 | CheckFeature quickfix |
| 715 | if winheight(0) < 15 |
| 716 | throw 'Skipped: window height insufficient' |
| 717 | endif |
| 718 | |
Bram Moolenaar | 9ad89c6 | 2017-10-26 22:04:04 +0200 | [diff] [blame] | 719 | " This used to crash Vim |
Bram Moolenaar | 9ad89c6 | 2017-10-26 22:04:04 +0200 | [diff] [blame] | 720 | new |
| 721 | augroup MyBufAdd |
| 722 | au! |
| 723 | au BufAdd * nested tab sball |
| 724 | augroup END |
| 725 | set omnifunc=pythoncomplete#Complete |
| 726 | call setline(1, 'import os') |
| 727 | " make the line long |
| 728 | call setline(2, ' os.') |
| 729 | $ |
| 730 | call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<enter>\<esc>", 'tx') |
Bram Moolenaar | 2a45d64 | 2017-10-27 01:35:00 +0200 | [diff] [blame] | 731 | call assert_equal("import os", getline(1)) |
| 732 | call assert_match(' os.\(EX_IOERR\|O_CREAT\)$', getline(2)) |
Bram Moolenaar | 9ad89c6 | 2017-10-26 22:04:04 +0200 | [diff] [blame] | 733 | call assert_equal(1, winnr('$')) |
| 734 | " previewwindow option is not set |
| 735 | call assert_equal(0, &previewwindow) |
| 736 | norm! gt |
| 737 | call assert_equal(0, &previewwindow) |
| 738 | norm! gT |
Bram Moolenaar | 02ae9b4 | 2018-02-09 15:06:02 +0100 | [diff] [blame] | 739 | call assert_equal(10, tabpagenr('$')) |
Bram Moolenaar | 9ad89c6 | 2017-10-26 22:04:04 +0200 | [diff] [blame] | 740 | tabonly |
| 741 | pclose |
| 742 | augroup MyBufAdd |
| 743 | au! |
| 744 | augroup END |
| 745 | augroup! MyBufAdd |
| 746 | bw! |
| 747 | endfunc |
| 748 | |
Yinzuo Jiang | a2a2fe8 | 2024-12-16 21:22:09 +0100 | [diff] [blame] | 749 | func s:run_popup_and_previewwindow_dump(lines, dumpfile) |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 750 | CheckScreendump |
| 751 | CheckFeature quickfix |
| 752 | |
Yinzuo Jiang | a2a2fe8 | 2024-12-16 21:22:09 +0100 | [diff] [blame] | 753 | call writefile(a:lines, 'Xscript', 'D') |
Bram Moolenaar | 614ab8a | 2018-12-01 11:59:00 +0100 | [diff] [blame] | 754 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 755 | |
Bram Moolenaar | 37bb030 | 2020-03-27 20:24:14 +0100 | [diff] [blame] | 756 | " wait for the script to finish |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 757 | call TermWait(buf) |
Bram Moolenaar | 37bb030 | 2020-03-27 20:24:14 +0100 | [diff] [blame] | 758 | |
Bram Moolenaar | 614ab8a | 2018-12-01 11:59:00 +0100 | [diff] [blame] | 759 | " Test that popup and previewwindow do not overlap. |
Bram Moolenaar | 37bb030 | 2020-03-27 20:24:14 +0100 | [diff] [blame] | 760 | call term_sendkeys(buf, "o") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 761 | call TermWait(buf, 50) |
Bram Moolenaar | 37bb030 | 2020-03-27 20:24:14 +0100 | [diff] [blame] | 762 | call term_sendkeys(buf, "\<C-X>\<C-N>") |
Yinzuo Jiang | a2a2fe8 | 2024-12-16 21:22:09 +0100 | [diff] [blame] | 763 | call VerifyScreenDump(buf, a:dumpfile, {}) |
Bram Moolenaar | 614ab8a | 2018-12-01 11:59:00 +0100 | [diff] [blame] | 764 | |
| 765 | call term_sendkeys(buf, "\<Esc>u") |
| 766 | call StopVimInTerminal(buf) |
Bram Moolenaar | 614ab8a | 2018-12-01 11:59:00 +0100 | [diff] [blame] | 767 | endfunc |
| 768 | |
Yinzuo Jiang | a2a2fe8 | 2024-12-16 21:22:09 +0100 | [diff] [blame] | 769 | func Test_popup_and_previewwindow_dump_pedit() |
| 770 | let lines =<< trim END |
| 771 | set previewheight=9 |
| 772 | silent! pedit |
| 773 | call setline(1, map(repeat(["ab"], 10), "v:val .. v:key")) |
| 774 | exec "norm! G\<C-E>\<C-E>" |
| 775 | END |
| 776 | call s:run_popup_and_previewwindow_dump(lines, 'Test_popup_and_previewwindow_pedit') |
| 777 | endfunc |
| 778 | |
| 779 | func Test_popup_and_previewwindow_dump_pbuffer() |
| 780 | let lines =<< trim END |
| 781 | set previewheight=9 |
| 782 | silent! pbuffer |
| 783 | call setline(1, map(repeat(["ab"], 10), "v:val .. v:key")) |
| 784 | exec "norm! G\<C-E>\<C-E>\<C-E>" |
| 785 | END |
| 786 | call s:run_popup_and_previewwindow_dump(lines, 'Test_popup_and_previewwindow_pbuffer') |
| 787 | endfunc |
| 788 | |
Bram Moolenaar | 246fe03 | 2017-11-19 19:56:27 +0100 | [diff] [blame] | 789 | func Test_balloon_split() |
Bram Moolenaar | 073e4b9 | 2019-08-18 23:01:56 +0200 | [diff] [blame] | 790 | CheckFunction balloon_split |
| 791 | |
Bram Moolenaar | 246fe03 | 2017-11-19 19:56:27 +0100 | [diff] [blame] | 792 | call assert_equal([ |
Bram Moolenaar | a3571eb | 2017-11-26 16:53:16 +0100 | [diff] [blame] | 793 | \ 'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"', |
| 794 | \ ], balloon_split( |
| 795 | \ 'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"')) |
| 796 | call assert_equal([ |
Bram Moolenaar | 246fe03 | 2017-11-19 19:56:27 +0100 | [diff] [blame] | 797 | \ 'one two three four one two three four one two thre', |
| 798 | \ 'e four', |
| 799 | \ ], balloon_split( |
| 800 | \ 'one two three four one two three four one two three four')) |
| 801 | |
Bram Moolenaar | 073e4b9 | 2019-08-18 23:01:56 +0200 | [diff] [blame] | 802 | eval 'struct = {one = 1, two = 2, three = 3}' |
| 803 | \ ->balloon_split() |
| 804 | \ ->assert_equal([ |
| 805 | \ 'struct = {', |
| 806 | \ ' one = 1,', |
| 807 | \ ' two = 2,', |
| 808 | \ ' three = 3}', |
| 809 | \ ]) |
Bram Moolenaar | 246fe03 | 2017-11-19 19:56:27 +0100 | [diff] [blame] | 810 | |
| 811 | call assert_equal([ |
| 812 | \ 'struct = {', |
| 813 | \ ' one = 1,', |
| 814 | \ ' nested = {', |
| 815 | \ ' n1 = "yes",', |
| 816 | \ ' n2 = "no"}', |
| 817 | \ ' two = 2}', |
| 818 | \ ], balloon_split( |
| 819 | \ 'struct = {one = 1, nested = {n1 = "yes", n2 = "no"} two = 2}')) |
| 820 | call assert_equal([ |
| 821 | \ 'struct = 0x234 {', |
| 822 | \ ' long = 2343 "\\"some long string that will be wr', |
| 823 | \ 'apped in two\\"",', |
| 824 | \ ' next = 123}', |
| 825 | \ ], balloon_split( |
| 826 | \ 'struct = 0x234 {long = 2343 "\\"some long string that will be wrapped in two\\"", next = 123}')) |
Bram Moolenaar | 9ae862e | 2019-11-21 13:27:06 +0100 | [diff] [blame] | 827 | call assert_equal([ |
| 828 | \ 'Some comment', |
| 829 | \ '', |
| 830 | \ 'typedef this that;', |
| 831 | \ ], balloon_split( |
| 832 | \ "Some comment\n\ntypedef this that;")) |
Bram Moolenaar | 246fe03 | 2017-11-19 19:56:27 +0100 | [diff] [blame] | 833 | endfunc |
| 834 | |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 835 | func Test_popup_position() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 836 | CheckScreendump |
| 837 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 838 | let lines =<< trim END |
| 839 | 123456789_123456789_123456789_a |
| 840 | 123456789_123456789_123456789_b |
| 841 | 123 |
| 842 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 843 | call writefile(lines, 'Xtest', 'D') |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 844 | let buf = RunVimInTerminal('Xtest', {}) |
| 845 | call term_sendkeys(buf, ":vsplit\<CR>") |
| 846 | |
| 847 | " default pumwidth in left window: overlap in right window |
| 848 | call term_sendkeys(buf, "GA\<C-N>") |
| 849 | call VerifyScreenDump(buf, 'Test_popup_position_01', {'rows': 8}) |
| 850 | call term_sendkeys(buf, "\<Esc>u") |
| 851 | |
| 852 | " default pumwidth: fill until right of window |
| 853 | call term_sendkeys(buf, "\<C-W>l") |
| 854 | call term_sendkeys(buf, "GA\<C-N>") |
| 855 | call VerifyScreenDump(buf, 'Test_popup_position_02', {'rows': 8}) |
| 856 | |
| 857 | " larger pumwidth: used as minimum width |
| 858 | call term_sendkeys(buf, "\<Esc>u") |
| 859 | call term_sendkeys(buf, ":set pumwidth=30\<CR>") |
| 860 | call term_sendkeys(buf, "GA\<C-N>") |
| 861 | call VerifyScreenDump(buf, 'Test_popup_position_03', {'rows': 8}) |
| 862 | |
Bram Moolenaar | 2b10bcb | 2018-02-24 21:25:44 +0100 | [diff] [blame] | 863 | " completed text wider than the window and 'pumwidth' smaller than available |
| 864 | " space |
| 865 | call term_sendkeys(buf, "\<Esc>u") |
| 866 | call term_sendkeys(buf, ":set pumwidth=20\<CR>") |
| 867 | call term_sendkeys(buf, "ggI123456789_\<Esc>") |
| 868 | call term_sendkeys(buf, "jI123456789_\<Esc>") |
| 869 | call term_sendkeys(buf, "GA\<C-N>") |
| 870 | call VerifyScreenDump(buf, 'Test_popup_position_04', {'rows': 10}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 871 | |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 872 | call term_sendkeys(buf, "\<Esc>u") |
| 873 | call StopVimInTerminal(buf) |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 874 | endfunc |
| 875 | |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 876 | func Test_popup_command() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 877 | CheckFeature menu |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 878 | |
Bram Moolenaar | 0eabd4d | 2020-03-15 16:13:53 +0100 | [diff] [blame] | 879 | menu Test.Foo Foo |
| 880 | call assert_fails('popup Test.Foo', 'E336:') |
| 881 | call assert_fails('popup Test.Foo.X', 'E327:') |
| 882 | call assert_fails('popup Foo', 'E337:') |
| 883 | unmenu Test.Foo |
zeertzjq | f7570f2 | 2022-11-12 17:30:25 +0000 | [diff] [blame] | 884 | endfunc |
| 885 | |
| 886 | func Test_popup_command_dump() |
| 887 | CheckFeature menu |
| 888 | CheckScreendump |
Bram Moolenaar | 0eabd4d | 2020-03-15 16:13:53 +0100 | [diff] [blame] | 889 | |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 890 | let script =<< trim END |
| 891 | func StartTimer() |
| 892 | call timer_start(100, {-> ChangeMenu()}) |
| 893 | endfunc |
| 894 | func ChangeMenu() |
zeertzjq | f7570f2 | 2022-11-12 17:30:25 +0000 | [diff] [blame] | 895 | aunmenu PopUp.&Paste |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 896 | nnoremenu 1.40 PopUp.&Paste :echomsg "pasted"<CR> |
| 897 | echomsg 'changed' |
| 898 | endfunc |
| 899 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 900 | call writefile(script, 'XtimerScript', 'D') |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 901 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 902 | let lines =<< trim END |
| 903 | one two three four five |
| 904 | and one two Xthree four five |
| 905 | one more two three four five |
| 906 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 907 | call writefile(lines, 'Xtest', 'D') |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 908 | let buf = RunVimInTerminal('-S XtimerScript Xtest', {}) |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 909 | call term_sendkeys(buf, ":source $VIMRUNTIME/menu.vim\<CR>") |
| 910 | call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>") |
| 911 | call VerifyScreenDump(buf, 'Test_popup_command_01', {}) |
| 912 | |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 913 | " go to the Paste entry in the menu |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 914 | call term_sendkeys(buf, "jj") |
| 915 | call VerifyScreenDump(buf, 'Test_popup_command_02', {}) |
| 916 | |
| 917 | " Select a word |
| 918 | call term_sendkeys(buf, "j\<CR>") |
| 919 | call VerifyScreenDump(buf, 'Test_popup_command_03', {}) |
| 920 | |
| 921 | call term_sendkeys(buf, "\<Esc>") |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 922 | |
zeertzjq | 883018f | 2024-06-15 15:37:11 +0200 | [diff] [blame] | 923 | if has('rightleft') |
| 924 | call term_sendkeys(buf, ":set rightleft\<CR>") |
| 925 | call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>") |
| 926 | call VerifyScreenDump(buf, 'Test_popup_command_rl', {}) |
| 927 | call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>") |
| 928 | endif |
| 929 | |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 930 | " Set a timer to change a menu entry while it's displayed. The text should |
| 931 | " not change but the command does. Making the screendump also verifies that |
zeertzjq | 4e1ca0d | 2023-04-27 19:36:55 +0100 | [diff] [blame] | 932 | " "changed" shows up, which means the timer triggered. |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 933 | call term_sendkeys(buf, "/X\<CR>:call StartTimer() | popup PopUp\<CR>") |
| 934 | call VerifyScreenDump(buf, 'Test_popup_command_04', {}) |
| 935 | |
| 936 | " Select the Paste entry, executes the changed menu item. |
| 937 | call term_sendkeys(buf, "jj\<CR>") |
| 938 | call VerifyScreenDump(buf, 'Test_popup_command_05', {}) |
| 939 | |
zeertzjq | 4e1ca0d | 2023-04-27 19:36:55 +0100 | [diff] [blame] | 940 | call term_sendkeys(buf, "\<Esc>") |
| 941 | |
| 942 | " Add a window toolbar to the window and check the :popup menu position. |
| 943 | call term_sendkeys(buf, ":nnoremenu WinBar.TEST :\<CR>") |
| 944 | call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>") |
| 945 | call VerifyScreenDump(buf, 'Test_popup_command_06', {}) |
| 946 | |
| 947 | call term_sendkeys(buf, "\<Esc>") |
| 948 | |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 949 | call StopVimInTerminal(buf) |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 950 | endfunc |
| 951 | |
zeertzjq | 883018f | 2024-06-15 15:37:11 +0200 | [diff] [blame] | 952 | " Test position of right-click menu when clicking near window edge. |
| 953 | func Test_mouse_popup_position() |
| 954 | CheckFeature menu |
| 955 | CheckScreendump |
| 956 | |
| 957 | let script =<< trim END |
| 958 | set mousemodel=popup_setpos |
| 959 | source $VIMRUNTIME/menu.vim |
| 960 | call setline(1, join(range(20))) |
| 961 | func Trigger(col) |
| 962 | call test_setmouse(1, a:col) |
| 963 | call feedkeys("\<RightMouse>", 't') |
| 964 | endfunc |
| 965 | END |
| 966 | call writefile(script, 'XmousePopupPosition', 'D') |
| 967 | let buf = RunVimInTerminal('-S XmousePopupPosition', #{rows: 20, cols: 50}) |
| 968 | |
| 969 | call term_sendkeys(buf, ":call Trigger(45)\<CR>") |
| 970 | call VerifyScreenDump(buf, 'Test_mouse_popup_position_01', {}) |
| 971 | call term_sendkeys(buf, "\<Esc>") |
| 972 | |
| 973 | if has('rightleft') |
| 974 | call term_sendkeys(buf, ":set rightleft\<CR>") |
| 975 | call term_sendkeys(buf, ":call Trigger(50 + 1 - 45)\<CR>") |
| 976 | call VerifyScreenDump(buf, 'Test_mouse_popup_position_02', {}) |
| 977 | call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>") |
| 978 | endif |
| 979 | |
| 980 | call StopVimInTerminal(buf) |
| 981 | endfunc |
| 982 | |
Bram Moolenaar | e87edf3 | 2018-04-17 22:14:32 +0200 | [diff] [blame] | 983 | func Test_popup_complete_backwards() |
| 984 | new |
| 985 | call setline(1, ['Post', 'Port', 'Po']) |
| 986 | let expected=['Post', 'Port', 'Port'] |
| 987 | call cursor(3,2) |
glepnir | 07f0dbe | 2025-02-18 20:27:30 +0100 | [diff] [blame] | 988 | call feedkeys("A\<C-X>". repeat("\<C-P>", 3). "rt\<C-Y>", 'tx') |
Bram Moolenaar | e87edf3 | 2018-04-17 22:14:32 +0200 | [diff] [blame] | 989 | call assert_equal(expected, getline(1,'$')) |
| 990 | bwipe! |
| 991 | endfunc |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 992 | |
Bram Moolenaar | bad0ce7 | 2018-04-17 23:31:05 +0200 | [diff] [blame] | 993 | func Test_popup_complete_backwards_ctrl_p() |
| 994 | new |
| 995 | call setline(1, ['Post', 'Port', 'Po']) |
| 996 | let expected=['Post', 'Port', 'Port'] |
| 997 | call cursor(3,2) |
glepnir | 07f0dbe | 2025-02-18 20:27:30 +0100 | [diff] [blame] | 998 | call feedkeys("A\<C-P>\<C-N>rt\<C-Y>", 'tx') |
Bram Moolenaar | bad0ce7 | 2018-04-17 23:31:05 +0200 | [diff] [blame] | 999 | call assert_equal(expected, getline(1,'$')) |
| 1000 | bwipe! |
| 1001 | endfunc |
| 1002 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 1003 | func Test_complete_o_tab() |
Bram Moolenaar | 39de952 | 2018-05-08 22:48:00 +0200 | [diff] [blame] | 1004 | let s:o_char_pressed = 0 |
| 1005 | |
| 1006 | fun! s:act_on_text_changed() |
| 1007 | if s:o_char_pressed |
| 1008 | let s:o_char_pressed = 0 |
| 1009 | call feedkeys("\<c-x>\<c-n>", 'i') |
| 1010 | endif |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 1011 | endfunc |
Bram Moolenaar | 39de952 | 2018-05-08 22:48:00 +0200 | [diff] [blame] | 1012 | |
| 1013 | set completeopt=menu,noselect |
| 1014 | new |
| 1015 | imap <expr> <buffer> <tab> pumvisible() ? "\<c-p>" : "X" |
| 1016 | autocmd! InsertCharPre <buffer> let s:o_char_pressed = (v:char ==# 'o') |
| 1017 | autocmd! TextChangedI <buffer> call <sid>act_on_text_changed() |
| 1018 | call setline(1, ['hoard', 'hoax', 'hoarse', '']) |
| 1019 | let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax', 'hoax'] |
| 1020 | call cursor(4,1) |
| 1021 | call test_override("char_avail", 1) |
| 1022 | call feedkeys("Ahoa\<tab>\<tab>\<c-y>\<esc>", 'tx') |
| 1023 | call feedkeys("oho\<tab>\<tab>\<c-y>\<esc>", 'tx') |
| 1024 | call assert_equal(l:expected, getline(1,'$')) |
| 1025 | |
| 1026 | call test_override("char_avail", 0) |
| 1027 | bwipe! |
| 1028 | set completeopt& |
| 1029 | delfunc s:act_on_text_changed |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 1030 | endfunc |
Bram Moolenaar | 39de952 | 2018-05-08 22:48:00 +0200 | [diff] [blame] | 1031 | |
Bram Moolenaar | f42b45d | 2019-01-06 13:11:05 +0100 | [diff] [blame] | 1032 | func Test_menu_only_exists_in_terminal() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 1033 | CheckCommand tlmenu |
| 1034 | CheckNotGui |
| 1035 | |
Bram Moolenaar | f42b45d | 2019-01-06 13:11:05 +0100 | [diff] [blame] | 1036 | tlnoremenu &Edit.&Paste<Tab>"+gP <C-W>"+ |
| 1037 | aunmenu * |
| 1038 | try |
| 1039 | popup Edit |
| 1040 | call assert_false(1, 'command should have failed') |
| 1041 | catch |
| 1042 | call assert_exception('E328:') |
| 1043 | endtry |
| 1044 | endfunc |
Bram Moolenaar | 39de952 | 2018-05-08 22:48:00 +0200 | [diff] [blame] | 1045 | |
zeertzjq | 92a1678 | 2022-07-26 12:24:41 +0100 | [diff] [blame] | 1046 | " This used to crash before patch 8.1.1424 |
| 1047 | func Test_popup_delete_when_shown() |
| 1048 | CheckFeature menu |
| 1049 | CheckNotGui |
| 1050 | |
| 1051 | func Func() |
| 1052 | popup Foo |
| 1053 | return "\<Ignore>" |
| 1054 | endfunc |
| 1055 | |
| 1056 | nmenu Foo.Bar : |
| 1057 | nnoremap <expr> <F2> Func() |
| 1058 | call feedkeys("\<F2>\<F2>\<Esc>", 'xt') |
| 1059 | |
| 1060 | delfunc Func |
| 1061 | nunmenu Foo.Bar |
| 1062 | nunmap <F2> |
| 1063 | endfunc |
| 1064 | |
Bram Moolenaar | fd13332 | 2019-03-29 12:20:27 +0100 | [diff] [blame] | 1065 | func Test_popup_complete_info_01() |
| 1066 | new |
| 1067 | inoremap <buffer><F5> <C-R>=complete_info().mode<CR> |
| 1068 | func s:complTestEval() abort |
| 1069 | call complete(1, ['aa', 'ab']) |
| 1070 | return '' |
| 1071 | endfunc |
| 1072 | inoremap <buffer><F6> <C-R>=s:complTestEval()<CR> |
| 1073 | call writefile([ |
| 1074 | \ 'dummy dummy.txt 1', |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 1075 | \], 'Xdummy.txt', 'D') |
Bram Moolenaar | fd13332 | 2019-03-29 12:20:27 +0100 | [diff] [blame] | 1076 | setlocal tags=Xdummy.txt |
| 1077 | setlocal dictionary=Xdummy.txt |
| 1078 | setlocal thesaurus=Xdummy.txt |
| 1079 | setlocal omnifunc=syntaxcomplete#Complete |
| 1080 | setlocal completefunc=syntaxcomplete#Complete |
| 1081 | setlocal spell |
| 1082 | for [keys, mode_name] in [ |
| 1083 | \ ["", ''], |
| 1084 | \ ["\<C-X>", 'ctrl_x'], |
| 1085 | \ ["\<C-X>\<C-N>", 'keyword'], |
| 1086 | \ ["\<C-X>\<C-P>", 'keyword'], |
zeertzjq | 27fef59 | 2021-10-03 12:01:27 +0100 | [diff] [blame] | 1087 | \ ["\<C-X>\<C-E>", 'scroll'], |
| 1088 | \ ["\<C-X>\<C-Y>", 'scroll'], |
| 1089 | \ ["\<C-X>\<C-E>\<C-E>\<C-Y>", 'scroll'], |
| 1090 | \ ["\<C-X>\<C-Y>\<C-E>\<C-Y>", 'scroll'], |
Bram Moolenaar | fd13332 | 2019-03-29 12:20:27 +0100 | [diff] [blame] | 1091 | \ ["\<C-X>\<C-L>", 'whole_line'], |
| 1092 | \ ["\<C-X>\<C-F>", 'files'], |
| 1093 | \ ["\<C-X>\<C-]>", 'tags'], |
| 1094 | \ ["\<C-X>\<C-D>", 'path_defines'], |
| 1095 | \ ["\<C-X>\<C-I>", 'path_patterns'], |
| 1096 | \ ["\<C-X>\<C-K>", 'dictionary'], |
| 1097 | \ ["\<C-X>\<C-T>", 'thesaurus'], |
| 1098 | \ ["\<C-X>\<C-V>", 'cmdline'], |
| 1099 | \ ["\<C-X>\<C-U>", 'function'], |
| 1100 | \ ["\<C-X>\<C-O>", 'omni'], |
| 1101 | \ ["\<C-X>s", 'spell'], |
| 1102 | \ ["\<F6>", 'eval'], |
| 1103 | \] |
| 1104 | call feedkeys("i" . keys . "\<F5>\<Esc>", 'tx') |
| 1105 | call assert_equal(mode_name, getline('.')) |
| 1106 | %d |
| 1107 | endfor |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 1108 | |
Bram Moolenaar | fd13332 | 2019-03-29 12:20:27 +0100 | [diff] [blame] | 1109 | bwipe! |
| 1110 | endfunc |
| 1111 | |
| 1112 | func UserDefinedComplete(findstart, base) |
| 1113 | if a:findstart |
| 1114 | return 0 |
| 1115 | else |
| 1116 | return [ |
| 1117 | \ { 'word': 'Jan', 'menu': 'January' }, |
| 1118 | \ { 'word': 'Feb', 'menu': 'February' }, |
| 1119 | \ { 'word': 'Mar', 'menu': 'March' }, |
| 1120 | \ { 'word': 'Apr', 'menu': 'April' }, |
| 1121 | \ { 'word': 'May', 'menu': 'May' }, |
| 1122 | \ ] |
| 1123 | endif |
| 1124 | endfunc |
| 1125 | |
| 1126 | func GetCompleteInfo() |
| 1127 | if empty(g:compl_what) |
| 1128 | let g:compl_info = complete_info() |
| 1129 | else |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 1130 | let g:compl_info = g:compl_what->complete_info() |
Bram Moolenaar | fd13332 | 2019-03-29 12:20:27 +0100 | [diff] [blame] | 1131 | endif |
| 1132 | return '' |
| 1133 | endfunc |
| 1134 | |
| 1135 | func Test_popup_complete_info_02() |
| 1136 | new |
| 1137 | inoremap <buffer><F5> <C-R>=GetCompleteInfo()<CR> |
| 1138 | setlocal completefunc=UserDefinedComplete |
| 1139 | |
| 1140 | let d = { |
| 1141 | \ 'mode': 'function', |
| 1142 | \ 'pum_visible': 1, |
| 1143 | \ 'items': [ |
| 1144 | \ {'word': 'Jan', 'menu': 'January', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, |
| 1145 | \ {'word': 'Feb', 'menu': 'February', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, |
| 1146 | \ {'word': 'Mar', 'menu': 'March', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, |
| 1147 | \ {'word': 'Apr', 'menu': 'April', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, |
| 1148 | \ {'word': 'May', 'menu': 'May', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''} |
| 1149 | \ ], |
| 1150 | \ 'selected': 0, |
| 1151 | \ } |
| 1152 | |
| 1153 | let g:compl_what = [] |
| 1154 | call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx') |
| 1155 | call assert_equal(d, g:compl_info) |
| 1156 | |
| 1157 | let g:compl_what = ['mode', 'pum_visible', 'selected'] |
| 1158 | call remove(d, 'items') |
| 1159 | call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx') |
| 1160 | call assert_equal(d, g:compl_info) |
| 1161 | |
| 1162 | let g:compl_what = ['mode'] |
| 1163 | call remove(d, 'selected') |
| 1164 | call remove(d, 'pum_visible') |
| 1165 | call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx') |
| 1166 | call assert_equal(d, g:compl_info) |
| 1167 | bwipe! |
| 1168 | endfunc |
| 1169 | |
Bram Moolenaar | e9bd572 | 2019-08-17 19:36:06 +0200 | [diff] [blame] | 1170 | func Test_popup_complete_info_no_pum() |
| 1171 | new |
| 1172 | call assert_false( pumvisible() ) |
| 1173 | let no_pum_info = complete_info() |
| 1174 | let d = { |
| 1175 | \ 'mode': '', |
| 1176 | \ 'pum_visible': 0, |
| 1177 | \ 'items': [], |
| 1178 | \ 'selected': -1, |
| 1179 | \ } |
| 1180 | call assert_equal( d, complete_info() ) |
| 1181 | bwipe! |
| 1182 | endfunc |
| 1183 | |
Bram Moolenaar | d7f246c | 2019-04-08 18:15:41 +0200 | [diff] [blame] | 1184 | func Test_CompleteChanged() |
| 1185 | new |
| 1186 | call setline(1, ['foo', 'bar', 'foobar', '']) |
| 1187 | set complete=. completeopt=noinsert,noselect,menuone |
| 1188 | function! OnPumChange() |
| 1189 | let g:event = copy(v:event) |
| 1190 | let g:item = get(v:event, 'completed_item', {}) |
| 1191 | let g:word = get(g:item, 'word', v:null) |
glepnir | 0d3c0a6 | 2024-02-11 17:52:40 +0100 | [diff] [blame] | 1192 | let l:line = getline('.') |
| 1193 | if g:word == v:null && l:line == "bc" |
| 1194 | let g:word = l:line |
| 1195 | endif |
Bram Moolenaar | d7f246c | 2019-04-08 18:15:41 +0200 | [diff] [blame] | 1196 | endfunction |
| 1197 | augroup AAAAA_Group |
| 1198 | au! |
| 1199 | autocmd CompleteChanged * :call OnPumChange() |
| 1200 | augroup END |
| 1201 | call cursor(4, 1) |
| 1202 | |
| 1203 | call feedkeys("Sf\<C-N>", 'tx') |
| 1204 | call assert_equal({'completed_item': {}, 'width': 15, |
| 1205 | \ 'height': 2, 'size': 2, |
| 1206 | \ 'col': 0, 'row': 4, 'scrollbar': v:false}, g:event) |
| 1207 | call feedkeys("a\<C-N>\<C-N>\<C-E>", 'tx') |
| 1208 | call assert_equal('foo', g:word) |
| 1209 | call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-E>", 'tx') |
| 1210 | call assert_equal('foobar', g:word) |
| 1211 | call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-N>\<C-E>", 'tx') |
| 1212 | call assert_equal(v:null, g:word) |
| 1213 | call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-N>\<C-P>", 'tx') |
| 1214 | call assert_equal('foobar', g:word) |
glepnir | 0d3c0a6 | 2024-02-11 17:52:40 +0100 | [diff] [blame] | 1215 | call feedkeys("S\<C-N>bc", 'tx') |
| 1216 | call assert_equal("bc", g:word) |
Bram Moolenaar | d7f246c | 2019-04-08 18:15:41 +0200 | [diff] [blame] | 1217 | |
glepnir | cbb46b4 | 2024-02-03 18:11:13 +0100 | [diff] [blame] | 1218 | func Omni_test(findstart, base) |
| 1219 | if a:findstart |
| 1220 | return col(".") |
| 1221 | endif |
| 1222 | return [#{word: "one"}, #{word: "two"}, #{word: "five"}] |
| 1223 | endfunc |
| 1224 | set omnifunc=Omni_test |
| 1225 | set completeopt=menu,menuone |
| 1226 | call feedkeys("i\<C-X>\<C-O>\<BS>\<BS>\<BS>f", 'tx') |
| 1227 | call assert_equal('five', g:word) |
glepnir | 53387c5 | 2024-05-27 15:11:01 +0200 | [diff] [blame] | 1228 | call feedkeys("i\<C-X>\<C-O>\<BS>\<BS>\<BS>f\<BS>", 'tx') |
| 1229 | call assert_equal('one', g:word) |
glepnir | cbb46b4 | 2024-02-03 18:11:13 +0100 | [diff] [blame] | 1230 | |
Bram Moolenaar | d7f246c | 2019-04-08 18:15:41 +0200 | [diff] [blame] | 1231 | autocmd! AAAAA_Group |
| 1232 | set complete& completeopt& |
Bram Moolenaar | e9bd572 | 2019-08-17 19:36:06 +0200 | [diff] [blame] | 1233 | delfunc! OnPumChange |
glepnir | cbb46b4 | 2024-02-03 18:11:13 +0100 | [diff] [blame] | 1234 | delfunc! Omni_test |
Bram Moolenaar | d7f246c | 2019-04-08 18:15:41 +0200 | [diff] [blame] | 1235 | bw! |
| 1236 | endfunc |
| 1237 | |
Bram Moolenaar | 97f0eb1 | 2022-10-06 19:49:13 +0100 | [diff] [blame] | 1238 | func GetPumPosition() |
Bram Moolenaar | e9bd572 | 2019-08-17 19:36:06 +0200 | [diff] [blame] | 1239 | call assert_true( pumvisible() ) |
| 1240 | let g:pum_pos = pum_getpos() |
| 1241 | return '' |
Bram Moolenaar | 97f0eb1 | 2022-10-06 19:49:13 +0100 | [diff] [blame] | 1242 | endfunc |
Bram Moolenaar | e9bd572 | 2019-08-17 19:36:06 +0200 | [diff] [blame] | 1243 | |
| 1244 | func Test_pum_getpos() |
| 1245 | new |
| 1246 | inoremap <buffer><F5> <C-R>=GetPumPosition()<CR> |
| 1247 | setlocal completefunc=UserDefinedComplete |
| 1248 | |
| 1249 | let d = { |
| 1250 | \ 'height': 5, |
| 1251 | \ 'width': 15, |
| 1252 | \ 'row': 1, |
| 1253 | \ 'col': 0, |
| 1254 | \ 'size': 5, |
| 1255 | \ 'scrollbar': v:false, |
| 1256 | \ } |
| 1257 | call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx') |
| 1258 | call assert_equal(d, g:pum_pos) |
| 1259 | |
| 1260 | call assert_false( pumvisible() ) |
| 1261 | call assert_equal( {}, pum_getpos() ) |
| 1262 | bw! |
| 1263 | unlet g:pum_pos |
| 1264 | endfunc |
| 1265 | |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1266 | " Test for the popup menu with the 'rightleft' option set |
| 1267 | func Test_pum_rightleft() |
Dominique Pelle | 56cddb3 | 2021-06-04 21:09:55 +0200 | [diff] [blame] | 1268 | CheckFeature rightleft |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1269 | CheckScreendump |
Dominique Pelle | 56cddb3 | 2021-06-04 21:09:55 +0200 | [diff] [blame] | 1270 | |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1271 | let lines =<< trim END |
| 1272 | abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz |
| 1273 | vim |
| 1274 | victory |
| 1275 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 1276 | call writefile(lines, 'Xtest1', 'D') |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1277 | let buf = RunVimInTerminal('--cmd "set rightleft" Xtest1', {}) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1278 | call term_sendkeys(buf, "Go\<C-P>") |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1279 | call VerifyScreenDump(buf, 'Test_pum_rightleft_01', {'rows': 8}) |
| 1280 | call term_sendkeys(buf, "\<C-P>\<C-Y>") |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1281 | call TermWait(buf, 30) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1282 | redraw! |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1283 | call WaitForAssert({-> assert_match('\s*miv', Screenline(5))}) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1284 | |
| 1285 | " Test for expanding tabs to spaces in the popup menu |
| 1286 | let lines =<< trim END |
| 1287 | one two |
| 1288 | one three |
| 1289 | four |
| 1290 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 1291 | call writefile(lines, 'Xtest2', 'D') |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1292 | call term_sendkeys(buf, "\<Esc>:e! Xtest2\<CR>") |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1293 | call TermWait(buf, 30) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1294 | call term_sendkeys(buf, "Goone\<C-X>\<C-L>") |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1295 | call TermWait(buf, 30) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1296 | redraw! |
| 1297 | call VerifyScreenDump(buf, 'Test_pum_rightleft_02', {'rows': 7}) |
| 1298 | call term_sendkeys(buf, "\<C-Y>") |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1299 | call TermWait(buf, 30) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1300 | redraw! |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1301 | call WaitForAssert({-> assert_match('\s*eerht eno', Screenline(4))}) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1302 | |
| 1303 | call StopVimInTerminal(buf) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1304 | endfunc |
| 1305 | |
| 1306 | " Test for a popup menu with a scrollbar |
| 1307 | func Test_pum_scrollbar() |
| 1308 | CheckScreendump |
| 1309 | let lines =<< trim END |
| 1310 | one |
| 1311 | two |
| 1312 | three |
| 1313 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 1314 | call writefile(lines, 'Xtest1', 'D') |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1315 | let buf = RunVimInTerminal('--cmd "set pumheight=2" Xtest1', {}) |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1316 | call TermWait(buf) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1317 | call term_sendkeys(buf, "Go\<C-P>\<C-P>\<C-P>") |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1318 | call VerifyScreenDump(buf, 'Test_pum_scrollbar_01', {'rows': 7}) |
| 1319 | call term_sendkeys(buf, "\<C-E>\<Esc>dd") |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1320 | call TermWait(buf) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1321 | |
Dominique Pelle | 56cddb3 | 2021-06-04 21:09:55 +0200 | [diff] [blame] | 1322 | if has('rightleft') |
| 1323 | call term_sendkeys(buf, ":set rightleft\<CR>") |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1324 | call TermWait(buf) |
Dominique Pelle | 56cddb3 | 2021-06-04 21:09:55 +0200 | [diff] [blame] | 1325 | call term_sendkeys(buf, "Go\<C-P>\<C-P>\<C-P>") |
Dominique Pelle | 56cddb3 | 2021-06-04 21:09:55 +0200 | [diff] [blame] | 1326 | call VerifyScreenDump(buf, 'Test_pum_scrollbar_02', {'rows': 7}) |
| 1327 | endif |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1328 | |
| 1329 | call StopVimInTerminal(buf) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1330 | endfunc |
| 1331 | |
Gianmaria Bajo | 6a7c774 | 2023-03-10 16:35:53 +0000 | [diff] [blame] | 1332 | " Test default highlight groups for popup menu |
| 1333 | func Test_pum_highlights_default() |
| 1334 | CheckScreendump |
| 1335 | let lines =<< trim END |
| 1336 | func CompleteFunc( findstart, base ) |
| 1337 | if a:findstart |
| 1338 | return 0 |
| 1339 | endif |
| 1340 | return { |
| 1341 | \ 'words': [ |
| 1342 | \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', }, |
| 1343 | \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', }, |
| 1344 | \ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', }, |
| 1345 | \]} |
| 1346 | endfunc |
| 1347 | set completeopt=menu |
| 1348 | set completefunc=CompleteFunc |
| 1349 | END |
| 1350 | call writefile(lines, 'Xscript', 'D') |
| 1351 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1352 | call TermWait(buf) |
| 1353 | call term_sendkeys(buf, "iaw\<C-X>\<C-u>") |
| 1354 | call TermWait(buf, 50) |
| 1355 | call VerifyScreenDump(buf, 'Test_pum_highlights_01', {}) |
| 1356 | call term_sendkeys(buf, "\<C-E>\<Esc>u") |
| 1357 | call TermWait(buf) |
| 1358 | call StopVimInTerminal(buf) |
| 1359 | endfunc |
| 1360 | |
| 1361 | " Test custom highlight groups for popup menu |
| 1362 | func Test_pum_highlights_custom() |
| 1363 | CheckScreendump |
| 1364 | let lines =<< trim END |
| 1365 | func CompleteFunc( findstart, base ) |
| 1366 | if a:findstart |
| 1367 | return 0 |
| 1368 | endif |
| 1369 | return { |
| 1370 | \ 'words': [ |
| 1371 | \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', }, |
| 1372 | \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', }, |
| 1373 | \ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', }, |
| 1374 | \]} |
| 1375 | endfunc |
| 1376 | set completeopt=menu |
| 1377 | set completefunc=CompleteFunc |
| 1378 | hi PmenuKind ctermfg=1 ctermbg=225 |
| 1379 | hi PmenuKindSel ctermfg=1 ctermbg=7 |
| 1380 | hi PmenuExtra ctermfg=243 ctermbg=225 |
| 1381 | hi PmenuExtraSel ctermfg=0 ctermbg=7 |
| 1382 | END |
| 1383 | call writefile(lines, 'Xscript', 'D') |
| 1384 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1385 | call TermWait(buf) |
| 1386 | call term_sendkeys(buf, "iaw\<C-X>\<C-u>") |
| 1387 | call TermWait(buf, 50) |
| 1388 | call VerifyScreenDump(buf, 'Test_pum_highlights_02', {}) |
| 1389 | call term_sendkeys(buf, "\<C-E>\<Esc>u") |
| 1390 | call TermWait(buf) |
| 1391 | call StopVimInTerminal(buf) |
| 1392 | endfunc |
| 1393 | |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1394 | " Test match relate highlight group in pmenu |
| 1395 | func Test_pum_highlights_match() |
| 1396 | CheckScreendump |
| 1397 | let lines =<< trim END |
| 1398 | func Omni_test(findstart, base) |
| 1399 | if a:findstart |
| 1400 | return col(".") |
| 1401 | endif |
| 1402 | return { |
| 1403 | \ 'words': [ |
zeertzjq | afbe535 | 2024-06-14 20:24:22 +0200 | [diff] [blame] | 1404 | \ { 'word': 'foo', 'kind': 'fookind' }, |
zeertzjq | 63901e8 | 2024-06-16 16:51:25 +0200 | [diff] [blame] | 1405 | \ { 'word': 'foofoo', 'kind': 'fookind' }, |
zeertzjq | afbe535 | 2024-06-14 20:24:22 +0200 | [diff] [blame] | 1406 | \ { 'word': 'foobar', 'kind': 'fookind' }, |
| 1407 | \ { 'word': 'fooBaz', 'kind': 'fookind' }, |
| 1408 | \ { 'word': 'foobala', 'kind': 'fookind' }, |
| 1409 | \ { 'word': '你好' }, |
| 1410 | \ { 'word': '你好吗' }, |
| 1411 | \ { 'word': '你不好吗' }, |
| 1412 | \ { 'word': '你可好吗' }, |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1413 | \]} |
| 1414 | endfunc |
glepnir | f189138 | 2024-06-17 18:35:25 +0200 | [diff] [blame] | 1415 | |
| 1416 | func Comp() |
| 1417 | let col = col('.') |
| 1418 | if getline('.') == 'f' |
| 1419 | let col -= 1 |
| 1420 | endif |
| 1421 | call complete(col, [ |
| 1422 | \ #{word: "foo", icase: 1}, |
| 1423 | \ #{word: "Foobar", icase: 1}, |
| 1424 | \ #{word: "fooBaz", icase: 1}, |
| 1425 | \]) |
| 1426 | return '' |
| 1427 | endfunc |
| 1428 | |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1429 | set omnifunc=Omni_test |
| 1430 | set completeopt=menu,noinsert,fuzzy |
zeertzjq | 63901e8 | 2024-06-16 16:51:25 +0200 | [diff] [blame] | 1431 | hi PmenuMatchSel ctermfg=6 ctermbg=7 |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1432 | hi PmenuMatch ctermfg=4 ctermbg=225 |
| 1433 | END |
| 1434 | call writefile(lines, 'Xscript', 'D') |
| 1435 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1436 | call TermWait(buf) |
| 1437 | call term_sendkeys(buf, "i\<C-X>\<C-O>") |
| 1438 | call TermWait(buf, 50) |
| 1439 | call term_sendkeys(buf, "fo") |
| 1440 | call TermWait(buf, 50) |
| 1441 | call VerifyScreenDump(buf, 'Test_pum_highlights_03', {}) |
zeertzjq | 63901e8 | 2024-06-16 16:51:25 +0200 | [diff] [blame] | 1442 | call term_sendkeys(buf, "\<Esc>S\<C-X>\<C-O>") |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1443 | call TermWait(buf, 50) |
| 1444 | call term_sendkeys(buf, "你") |
| 1445 | call TermWait(buf, 50) |
| 1446 | call VerifyScreenDump(buf, 'Test_pum_highlights_04', {}) |
| 1447 | call term_sendkeys(buf, "吗") |
| 1448 | call TermWait(buf, 50) |
| 1449 | call VerifyScreenDump(buf, 'Test_pum_highlights_05', {}) |
zeertzjq | 63901e8 | 2024-06-16 16:51:25 +0200 | [diff] [blame] | 1450 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1451 | |
| 1452 | if has('rightleft') |
zeertzjq | 63901e8 | 2024-06-16 16:51:25 +0200 | [diff] [blame] | 1453 | call term_sendkeys(buf, ":set rightleft\<CR>") |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1454 | call TermWait(buf, 50) |
zeertzjq | 63901e8 | 2024-06-16 16:51:25 +0200 | [diff] [blame] | 1455 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1456 | call TermWait(buf, 50) |
| 1457 | call term_sendkeys(buf, "fo") |
| 1458 | call TermWait(buf, 50) |
| 1459 | call VerifyScreenDump(buf, 'Test_pum_highlights_06', {}) |
zeertzjq | 63901e8 | 2024-06-16 16:51:25 +0200 | [diff] [blame] | 1460 | call term_sendkeys(buf, "\<Esc>S\<C-X>\<C-O>") |
| 1461 | call TermWait(buf, 50) |
| 1462 | call term_sendkeys(buf, "你") |
| 1463 | call VerifyScreenDump(buf, 'Test_pum_highlights_06a', {}) |
| 1464 | call term_sendkeys(buf, "吗") |
| 1465 | call VerifyScreenDump(buf, 'Test_pum_highlights_06b', {}) |
| 1466 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1467 | call term_sendkeys(buf, ":set norightleft\<CR>") |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1468 | call TermWait(buf) |
| 1469 | endif |
| 1470 | |
| 1471 | call term_sendkeys(buf, ":set completeopt-=fuzzy\<CR>") |
| 1472 | call TermWait(buf) |
zeertzjq | 63901e8 | 2024-06-16 16:51:25 +0200 | [diff] [blame] | 1473 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1474 | call TermWait(buf, 50) |
| 1475 | call term_sendkeys(buf, "fo") |
| 1476 | call TermWait(buf, 50) |
| 1477 | call VerifyScreenDump(buf, 'Test_pum_highlights_07', {}) |
zeertzjq | 63901e8 | 2024-06-16 16:51:25 +0200 | [diff] [blame] | 1478 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1479 | |
zeertzjq | 63901e8 | 2024-06-16 16:51:25 +0200 | [diff] [blame] | 1480 | if has('rightleft') |
| 1481 | call term_sendkeys(buf, ":set rightleft\<CR>") |
| 1482 | call TermWait(buf, 50) |
| 1483 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 1484 | call TermWait(buf, 50) |
| 1485 | call term_sendkeys(buf, "fo") |
| 1486 | call TermWait(buf, 50) |
| 1487 | call VerifyScreenDump(buf, 'Test_pum_highlights_08', {}) |
| 1488 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1489 | call term_sendkeys(buf, ":set norightleft\<CR>") |
| 1490 | endif |
| 1491 | |
glepnir | f189138 | 2024-06-17 18:35:25 +0200 | [diff] [blame] | 1492 | call term_sendkeys(buf, "S\<C-R>=Comp()\<CR>f") |
| 1493 | call VerifyScreenDump(buf, 'Test_pum_highlights_09', {}) |
| 1494 | call term_sendkeys(buf, "o\<BS>\<C-R>=Comp()\<CR>") |
| 1495 | call VerifyScreenDump(buf, 'Test_pum_highlights_09', {}) |
glepnir | 9eff3ee | 2025-01-11 16:47:34 +0100 | [diff] [blame] | 1496 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1497 | |
zeertzjq | faf250c | 2025-01-12 09:32:27 +0100 | [diff] [blame] | 1498 | call term_sendkeys(buf, ":hi PmenuMatchSel ctermfg=14 ctermbg=NONE\<CR>") |
glepnir | 9eff3ee | 2025-01-11 16:47:34 +0100 | [diff] [blame] | 1499 | call TermWait(buf, 50) |
zeertzjq | faf250c | 2025-01-12 09:32:27 +0100 | [diff] [blame] | 1500 | call term_sendkeys(buf, ":hi PmenuMatch ctermfg=12 ctermbg=NONE\<CR>") |
glepnir | 9eff3ee | 2025-01-11 16:47:34 +0100 | [diff] [blame] | 1501 | call term_sendkeys(buf, ":set cot=menu,noinsert,fuzzy\<CR>") |
| 1502 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 1503 | call TermWait(buf, 50) |
| 1504 | call term_sendkeys(buf, "fb") |
| 1505 | call VerifyScreenDump(buf, 'Test_pum_highlights_18', {}) |
glepnir | 6b6280c | 2024-07-27 16:25:45 +0200 | [diff] [blame] | 1506 | |
glepnir | f189138 | 2024-06-17 18:35:25 +0200 | [diff] [blame] | 1507 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1508 | call TermWait(buf) |
glepnir | f31cfa2 | 2025-03-06 21:59:13 +0100 | [diff] [blame] | 1509 | call StopVimInTerminal(buf) |
| 1510 | endfunc |
glepnir | f189138 | 2024-06-17 18:35:25 +0200 | [diff] [blame] | 1511 | |
glepnir | f31cfa2 | 2025-03-06 21:59:13 +0100 | [diff] [blame] | 1512 | func Test_pum_completefuzzycollect() |
| 1513 | CheckScreendump |
| 1514 | let lines =<< trim END |
| 1515 | set completefuzzycollect=keyword,files |
| 1516 | set completeopt=menu,menuone |
| 1517 | END |
| 1518 | call writefile(lines, 'Xscript', 'D') |
| 1519 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1520 | |
| 1521 | " issue #15095 wrong select |
| 1522 | call term_sendkeys(buf, "S hello helio hero h\<C-X>\<C-P>") |
| 1523 | call TermWait(buf, 50) |
| 1524 | call VerifyScreenDump(buf, 'Test_pum_completefuzzycollect_01', {}) |
| 1525 | |
| 1526 | call term_sendkeys(buf, "\<ESC>S hello helio hero h\<C-X>\<C-P>\<C-P>") |
| 1527 | call TermWait(buf, 50) |
| 1528 | call VerifyScreenDump(buf, 'Test_pum_completefuzzycollect_02', {}) |
| 1529 | |
| 1530 | " issue #15357 |
| 1531 | call term_sendkeys(buf, "\<ESC>S/non_existing_folder\<C-X>\<C-F>") |
| 1532 | call TermWait(buf, 50) |
| 1533 | call VerifyScreenDump(buf, 'Test_pum_completefuzzycollect_03', {}) |
| 1534 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1535 | |
| 1536 | call TermWait(buf) |
glepnir | 40c1c33 | 2024-06-11 19:37:04 +0200 | [diff] [blame] | 1537 | call StopVimInTerminal(buf) |
| 1538 | endfunc |
| 1539 | |
zeertzjq | 3a0cc36 | 2025-01-13 07:27:43 +0100 | [diff] [blame] | 1540 | func Test_pum_highlights_match_with_abbr() |
| 1541 | CheckScreendump |
| 1542 | let lines =<< trim END |
| 1543 | func Omni_test(findstart, base) |
| 1544 | if a:findstart |
| 1545 | return col(".") |
| 1546 | endif |
| 1547 | return { |
| 1548 | \ 'words': [ |
| 1549 | \ { 'word': 'foobar', 'abbr': "foobar\t\t!" }, |
| 1550 | \ { 'word': 'foobaz', 'abbr': "foobaz\t\t!" }, |
| 1551 | \]} |
| 1552 | endfunc |
| 1553 | |
| 1554 | set omnifunc=Omni_test |
| 1555 | set completeopt=menuone,noinsert |
| 1556 | hi PmenuMatchSel ctermfg=6 ctermbg=7 |
| 1557 | hi PmenuMatch ctermfg=4 ctermbg=225 |
| 1558 | END |
| 1559 | call writefile(lines, 'Xscript', 'D') |
| 1560 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1561 | call TermWait(buf) |
| 1562 | call term_sendkeys(buf, "i\<C-X>\<C-O>") |
| 1563 | call TermWait(buf, 50) |
| 1564 | call term_sendkeys(buf, "foo") |
| 1565 | call VerifyScreenDump(buf, 'Test_pum_highlights_19', {}) |
| 1566 | |
| 1567 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1568 | call TermWait(buf) |
| 1569 | |
| 1570 | call StopVimInTerminal(buf) |
| 1571 | endfunc |
| 1572 | |
glepnir | 0fe17f8 | 2024-10-08 22:26:44 +0200 | [diff] [blame] | 1573 | func Test_pum_user_abbr_hlgroup() |
glepnir | 508e785 | 2024-07-25 21:39:08 +0200 | [diff] [blame] | 1574 | CheckScreendump |
| 1575 | let lines =<< trim END |
glepnir | bc10be7 | 2024-11-02 16:45:01 +0100 | [diff] [blame] | 1576 | let s:var = 0 |
| 1577 | func CompleteFunc(findstart, base) |
glepnir | 508e785 | 2024-07-25 21:39:08 +0200 | [diff] [blame] | 1578 | if a:findstart |
| 1579 | return 0 |
| 1580 | endif |
glepnir | bc10be7 | 2024-11-02 16:45:01 +0100 | [diff] [blame] | 1581 | if s:var == 1 |
| 1582 | return { |
| 1583 | \ 'words': [ |
| 1584 | \ { 'word': 'aword1', 'abbr_hlgroup': 'StrikeFake' }, |
| 1585 | \ { 'word': '你好', 'abbr_hlgroup': 'StrikeFake' }, |
| 1586 | \]} |
| 1587 | endif |
glepnir | 508e785 | 2024-07-25 21:39:08 +0200 | [diff] [blame] | 1588 | return { |
| 1589 | \ 'words': [ |
glepnir | 0fe17f8 | 2024-10-08 22:26:44 +0200 | [diff] [blame] | 1590 | \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' }, |
glepnir | 508e785 | 2024-07-25 21:39:08 +0200 | [diff] [blame] | 1591 | \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', }, |
glepnir | 0fe17f8 | 2024-10-08 22:26:44 +0200 | [diff] [blame] | 1592 | \ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' }, |
glepnir | 508e785 | 2024-07-25 21:39:08 +0200 | [diff] [blame] | 1593 | \]} |
| 1594 | endfunc |
glepnir | bc10be7 | 2024-11-02 16:45:01 +0100 | [diff] [blame] | 1595 | func ChangeVar() |
| 1596 | let s:var = 1 |
| 1597 | endfunc |
glepnir | 508e785 | 2024-07-25 21:39:08 +0200 | [diff] [blame] | 1598 | set completeopt=menu |
| 1599 | set completefunc=CompleteFunc |
zeertzjq | 4100852 | 2024-07-27 13:21:49 +0200 | [diff] [blame] | 1600 | |
| 1601 | hi StrikeFake ctermfg=9 |
| 1602 | func HlMatch() |
| 1603 | hi PmenuMatchSel ctermfg=6 ctermbg=7 cterm=underline |
| 1604 | hi PmenuMatch ctermfg=4 ctermbg=225 cterm=underline |
| 1605 | endfunc |
glepnir | 508e785 | 2024-07-25 21:39:08 +0200 | [diff] [blame] | 1606 | END |
| 1607 | call writefile(lines, 'Xscript', 'D') |
| 1608 | let buf = RunVimInTerminal('-S Xscript', {}) |
zeertzjq | 4100852 | 2024-07-27 13:21:49 +0200 | [diff] [blame] | 1609 | |
glepnir | 508e785 | 2024-07-25 21:39:08 +0200 | [diff] [blame] | 1610 | call TermWait(buf) |
zeertzjq | 4100852 | 2024-07-27 13:21:49 +0200 | [diff] [blame] | 1611 | call term_sendkeys(buf, "Saw\<C-X>\<C-U>") |
glepnir | 508e785 | 2024-07-25 21:39:08 +0200 | [diff] [blame] | 1612 | call VerifyScreenDump(buf, 'Test_pum_highlights_12', {}) |
zeertzjq | 4100852 | 2024-07-27 13:21:49 +0200 | [diff] [blame] | 1613 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1614 | |
glepnir | 508e785 | 2024-07-25 21:39:08 +0200 | [diff] [blame] | 1615 | call TermWait(buf) |
zeertzjq | 4100852 | 2024-07-27 13:21:49 +0200 | [diff] [blame] | 1616 | call term_sendkeys(buf, ":call HlMatch()\<CR>") |
| 1617 | |
| 1618 | call TermWait(buf) |
| 1619 | call term_sendkeys(buf, "Saw\<C-X>\<C-U>") |
| 1620 | call VerifyScreenDump(buf, 'Test_pum_highlights_13', {}) |
| 1621 | call term_sendkeys(buf, "\<C-N>") |
| 1622 | call VerifyScreenDump(buf, 'Test_pum_highlights_14', {}) |
| 1623 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1624 | |
glepnir | bc10be7 | 2024-11-02 16:45:01 +0100 | [diff] [blame] | 1625 | call TermWait(buf) |
| 1626 | call term_sendkeys(buf, ":call ChangeVar()\<CR>") |
| 1627 | call TermWait(buf) |
| 1628 | call term_sendkeys(buf, "S\<C-X>\<C-U>") |
| 1629 | call VerifyScreenDump(buf, 'Test_pum_highlights_17', {}) |
| 1630 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1631 | |
glepnir | 508e785 | 2024-07-25 21:39:08 +0200 | [diff] [blame] | 1632 | call StopVimInTerminal(buf) |
| 1633 | endfunc |
| 1634 | |
glepnir | 38f99a1 | 2024-08-23 18:31:06 +0200 | [diff] [blame] | 1635 | func Test_pum_user_kind_hlgroup() |
| 1636 | CheckScreendump |
| 1637 | let lines =<< trim END |
glepnir | bc10be7 | 2024-11-02 16:45:01 +0100 | [diff] [blame] | 1638 | func CompleteFunc(findstart, base) |
glepnir | 38f99a1 | 2024-08-23 18:31:06 +0200 | [diff] [blame] | 1639 | if a:findstart |
| 1640 | return 0 |
| 1641 | endif |
| 1642 | return { |
| 1643 | \ 'words': [ |
glepnir | 0fe17f8 | 2024-10-08 22:26:44 +0200 | [diff] [blame] | 1644 | \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'variable', 'kind_hlgroup': 'KindVar', 'abbr_hlgroup': 'StrikeFake' }, |
glepnir | 38f99a1 | 2024-08-23 18:31:06 +0200 | [diff] [blame] | 1645 | \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'function', 'kind_hlgroup': 'KindFunc' }, |
| 1646 | \ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'class', 'kind_hlgroup': 'KindClass' }, |
| 1647 | \]} |
| 1648 | endfunc |
| 1649 | set completeopt=menu |
| 1650 | set completefunc=CompleteFunc |
| 1651 | |
| 1652 | hi StrikeFake ctermfg=9 |
| 1653 | hi KindVar ctermfg=yellow |
| 1654 | hi KindFunc ctermfg=blue |
| 1655 | hi KindClass ctermfg=green |
| 1656 | END |
| 1657 | call writefile(lines, 'Xscript', 'D') |
| 1658 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1659 | |
| 1660 | call TermWait(buf) |
| 1661 | call term_sendkeys(buf, "S\<C-X>\<C-U>") |
| 1662 | call VerifyScreenDump(buf, 'Test_pum_highlights_16', {}) |
| 1663 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1664 | |
| 1665 | call StopVimInTerminal(buf) |
| 1666 | endfunc |
| 1667 | |
glepnir | 6a89c94 | 2024-10-01 20:32:12 +0200 | [diff] [blame] | 1668 | func Test_pum_completeitemalign() |
| 1669 | CheckScreendump |
| 1670 | let lines =<< trim END |
| 1671 | func Omni_test(findstart, base) |
| 1672 | if a:findstart |
| 1673 | return col(".") |
| 1674 | endif |
| 1675 | return { |
| 1676 | \ 'words': [ |
| 1677 | \ { 'word': 'foo', 'kind': 'S', 'menu': 'menu' }, |
| 1678 | \ { 'word': 'bar', 'kind': 'T', 'menu': 'menu' }, |
| 1679 | \ { 'word': '你好', 'kind': 'C', 'menu': '中文' }, |
| 1680 | \]} |
| 1681 | endfunc |
glepnir | a6d9e3c | 2024-10-03 11:01:19 +0200 | [diff] [blame] | 1682 | |
| 1683 | func Omni_long(findstart, base) |
| 1684 | if a:findstart |
| 1685 | return col(".") |
| 1686 | endif |
| 1687 | return { |
| 1688 | \ 'words': [ |
| 1689 | \ { 'word': 'loooong_foo', 'kind': 'S', 'menu': 'menu' }, |
| 1690 | \ { 'word': 'loooong_bar', 'kind': 'T', 'menu': 'menu' }, |
| 1691 | \]} |
| 1692 | endfunc |
glepnir | 6a89c94 | 2024-10-01 20:32:12 +0200 | [diff] [blame] | 1693 | set omnifunc=Omni_test |
| 1694 | command! -nargs=0 T1 set cia=abbr,kind,menu |
| 1695 | command! -nargs=0 T2 set cia=abbr,menu,kind |
| 1696 | command! -nargs=0 T3 set cia=kind,abbr,menu |
| 1697 | command! -nargs=0 T4 set cia=kind,menu,abbr |
| 1698 | command! -nargs=0 T5 set cia=menu,abbr,kind |
| 1699 | command! -nargs=0 T6 set cia=menu,kind,abbr |
| 1700 | command! -nargs=0 T7 set cia& |
| 1701 | END |
| 1702 | call writefile(lines, 'Xscript', 'D') |
| 1703 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1704 | call TermWait(buf) |
| 1705 | |
| 1706 | " T1 is default |
| 1707 | call term_sendkeys(buf, ":T1\<CR>S\<C-X>\<C-O>") |
| 1708 | call VerifyScreenDump(buf, 'Test_pum_completeitemalign_01', {}) |
| 1709 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1710 | |
| 1711 | " T2 |
| 1712 | call term_sendkeys(buf, ":T2\<CR>S\<C-X>\<C-O>") |
| 1713 | call VerifyScreenDump(buf, 'Test_pum_completeitemalign_02', {}) |
| 1714 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1715 | |
| 1716 | " T3 |
| 1717 | call term_sendkeys(buf, ":T3\<CR>S\<C-X>\<C-O>") |
| 1718 | call VerifyScreenDump(buf, 'Test_pum_completeitemalign_03', {}) |
| 1719 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1720 | |
| 1721 | " T4 |
| 1722 | call term_sendkeys(buf, ":T4\<CR>S\<C-X>\<C-O>") |
| 1723 | call VerifyScreenDump(buf, 'Test_pum_completeitemalign_04', {}) |
| 1724 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1725 | |
| 1726 | " T5 |
| 1727 | call term_sendkeys(buf, ":T5\<CR>S\<C-X>\<C-O>") |
| 1728 | call VerifyScreenDump(buf, 'Test_pum_completeitemalign_05', {}) |
| 1729 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1730 | |
| 1731 | " T6 |
| 1732 | call term_sendkeys(buf, ":T6\<CR>S\<C-X>\<C-O>") |
| 1733 | call VerifyScreenDump(buf, 'Test_pum_completeitemalign_06', {}) |
glepnir | a6d9e3c | 2024-10-03 11:01:19 +0200 | [diff] [blame] | 1734 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
glepnir | 6a89c94 | 2024-10-01 20:32:12 +0200 | [diff] [blame] | 1735 | |
glepnir | a6d9e3c | 2024-10-03 11:01:19 +0200 | [diff] [blame] | 1736 | call term_sendkeys(buf, ":set columns=12 cmdheight=2 omnifunc=Omni_long\<CR>S\<C-X>\<C-O>") |
| 1737 | call VerifyScreenDump(buf, 'Test_pum_completeitemalign_07', {}) |
| 1738 | call term_sendkeys(buf, "\<C-E>\<Esc>:T7\<CR>") |
glepnir | 6a89c94 | 2024-10-01 20:32:12 +0200 | [diff] [blame] | 1739 | call StopVimInTerminal(buf) |
| 1740 | endfunc |
| 1741 | |
glepnir | a49c077 | 2024-11-30 10:56:30 +0100 | [diff] [blame] | 1742 | func Test_pum_keep_select() |
| 1743 | CheckScreendump |
| 1744 | let lines =<< trim END |
| 1745 | set completeopt=menu,menuone,noinsert |
| 1746 | END |
| 1747 | call writefile(lines, 'Xscript', 'D') |
| 1748 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1749 | call TermWait(buf) |
| 1750 | |
| 1751 | call term_sendkeys(buf, "ggSFab\<CR>Five\<CR>find\<CR>film\<CR>\<C-X>\<C-P>") |
| 1752 | call TermWait(buf, 50) |
| 1753 | call VerifyScreenDump(buf, 'Test_pum_keep_select_01', {}) |
| 1754 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1755 | call TermWait(buf, 50) |
| 1756 | |
| 1757 | call term_sendkeys(buf, "S\<C-X>\<C-P>") |
| 1758 | call TermWait(buf, 50) |
| 1759 | call term_sendkeys(buf, "F") |
| 1760 | call VerifyScreenDump(buf, 'Test_pum_keep_select_02', {}) |
| 1761 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1762 | |
| 1763 | call TermWait(buf, 50) |
| 1764 | call StopVimInTerminal(buf) |
| 1765 | endfunc |
| 1766 | |
zeertzjq | d32bf0a | 2024-12-17 20:55:13 +0100 | [diff] [blame] | 1767 | func Test_pum_matchins_highlight() |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1768 | CheckScreendump |
| 1769 | let lines =<< trim END |
glepnir | 8d0bb6d | 2024-12-24 09:44:35 +0100 | [diff] [blame] | 1770 | let g:change = 0 |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1771 | func Omni_test(findstart, base) |
| 1772 | if a:findstart |
| 1773 | return col(".") |
| 1774 | endif |
glepnir | 8d0bb6d | 2024-12-24 09:44:35 +0100 | [diff] [blame] | 1775 | if g:change == 0 |
| 1776 | return [#{word: "foo"}, #{word: "bar"}, #{word: "你好"}] |
| 1777 | endif |
| 1778 | return [#{word: "foo", info: "info"}, #{word: "bar"}, #{word: "你好"}] |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1779 | endfunc |
| 1780 | set omnifunc=Omni_test |
| 1781 | hi ComplMatchIns ctermfg=red |
| 1782 | END |
| 1783 | call writefile(lines, 'Xscript', 'D') |
| 1784 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1785 | |
| 1786 | call TermWait(buf) |
zeertzjq | f4ccada | 2024-12-17 20:50:19 +0100 | [diff] [blame] | 1787 | call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>") |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1788 | call VerifyScreenDump(buf, 'Test_pum_matchins_01', {}) |
| 1789 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1790 | |
| 1791 | call TermWait(buf) |
zeertzjq | f4ccada | 2024-12-17 20:50:19 +0100 | [diff] [blame] | 1792 | call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<C-N>") |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1793 | call VerifyScreenDump(buf, 'Test_pum_matchins_02', {}) |
| 1794 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1795 | |
| 1796 | call TermWait(buf) |
zeertzjq | f4ccada | 2024-12-17 20:50:19 +0100 | [diff] [blame] | 1797 | call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<C-N>\<C-N>") |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1798 | call VerifyScreenDump(buf, 'Test_pum_matchins_03', {}) |
| 1799 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1800 | |
| 1801 | " restore after accept |
| 1802 | call TermWait(buf) |
zeertzjq | f4ccada | 2024-12-17 20:50:19 +0100 | [diff] [blame] | 1803 | call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<C-Y>") |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1804 | call VerifyScreenDump(buf, 'Test_pum_matchins_04', {}) |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 1805 | call term_sendkeys(buf, "\<Esc>") |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1806 | |
| 1807 | " restore after cancel completion |
| 1808 | call TermWait(buf) |
zeertzjq | f4ccada | 2024-12-17 20:50:19 +0100 | [diff] [blame] | 1809 | call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<Space>") |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1810 | call VerifyScreenDump(buf, 'Test_pum_matchins_05', {}) |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 1811 | call term_sendkeys(buf, "\<Esc>") |
| 1812 | |
| 1813 | " text after the inserted text shouldn't be highlighted |
| 1814 | call TermWait(buf) |
| 1815 | call term_sendkeys(buf, "0ea \<C-X>\<C-O>") |
| 1816 | call VerifyScreenDump(buf, 'Test_pum_matchins_07', {}) |
| 1817 | call term_sendkeys(buf, "\<C-P>") |
| 1818 | call VerifyScreenDump(buf, 'Test_pum_matchins_08', {}) |
| 1819 | call term_sendkeys(buf, "\<C-P>") |
| 1820 | call VerifyScreenDump(buf, 'Test_pum_matchins_09', {}) |
| 1821 | call term_sendkeys(buf, "\<C-Y>") |
| 1822 | call VerifyScreenDump(buf, 'Test_pum_matchins_10', {}) |
| 1823 | call term_sendkeys(buf, "\<Esc>") |
| 1824 | |
glepnir | 8d0bb6d | 2024-12-24 09:44:35 +0100 | [diff] [blame] | 1825 | call term_sendkeys(buf, ":let g:change=1\<CR>S\<C-X>\<C-O>") |
| 1826 | call VerifyScreenDump(buf, 'Test_pum_matchins_11', {}) |
| 1827 | call term_sendkeys(buf, "\<Esc>") |
| 1828 | |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 1829 | call StopVimInTerminal(buf) |
| 1830 | endfunc |
| 1831 | |
| 1832 | func Test_pum_matchins_highlight_combine() |
| 1833 | CheckScreendump |
| 1834 | let lines =<< trim END |
| 1835 | func Omni_test(findstart, base) |
| 1836 | if a:findstart |
| 1837 | return col(".") |
| 1838 | endif |
| 1839 | return [#{word: "foo"}, #{word: "bar"}, #{word: "你好"}] |
| 1840 | endfunc |
| 1841 | set omnifunc=Omni_test |
| 1842 | hi Normal ctermbg=blue |
| 1843 | hi CursorLine cterm=underline ctermbg=green |
| 1844 | set cursorline |
| 1845 | call setline(1, 'aaa bbb') |
| 1846 | END |
| 1847 | call writefile(lines, 'Xscript', 'D') |
| 1848 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1849 | |
| 1850 | " when ComplMatchIns is not set, CursorLine applies normally |
| 1851 | call term_sendkeys(buf, "0ea \<C-X>\<C-O>") |
| 1852 | call VerifyScreenDump(buf, 'Test_pum_matchins_combine_01', {}) |
| 1853 | call term_sendkeys(buf, "\<C-E>") |
| 1854 | call VerifyScreenDump(buf, 'Test_pum_matchins_combine_02', {}) |
| 1855 | call term_sendkeys(buf, "\<BS>\<Esc>") |
| 1856 | |
| 1857 | " when ComplMatchIns is set, it is applied over CursorLine |
| 1858 | call TermWait(buf) |
| 1859 | call term_sendkeys(buf, ":hi ComplMatchIns ctermbg=red ctermfg=yellow\<CR>") |
| 1860 | call TermWait(buf) |
| 1861 | call term_sendkeys(buf, "0ea \<C-X>\<C-O>") |
| 1862 | call VerifyScreenDump(buf, 'Test_pum_matchins_combine_03', {}) |
| 1863 | call term_sendkeys(buf, "\<C-P>") |
| 1864 | call VerifyScreenDump(buf, 'Test_pum_matchins_combine_04', {}) |
| 1865 | call term_sendkeys(buf, "\<C-P>") |
| 1866 | call VerifyScreenDump(buf, 'Test_pum_matchins_combine_05', {}) |
| 1867 | call term_sendkeys(buf, "\<C-E>") |
| 1868 | call VerifyScreenDump(buf, 'Test_pum_matchins_combine_06', {}) |
| 1869 | call term_sendkeys(buf, "\<Esc>") |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1870 | |
glepnir | e890887 | 2025-01-08 18:30:45 +0100 | [diff] [blame] | 1871 | " Does not highlight the compl leader |
| 1872 | call TermWait(buf) |
| 1873 | call term_sendkeys(buf, ":set cot+=menuone,noselect\<CR>") |
| 1874 | call TermWait(buf) |
| 1875 | call term_sendkeys(buf, "S\<C-X>\<C-O>f\<C-N>") |
| 1876 | call VerifyScreenDump(buf, 'Test_pum_matchins_combine_07', {}) |
| 1877 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1878 | |
| 1879 | call term_sendkeys(buf, ":set cot+=fuzzy\<CR>") |
| 1880 | call TermWait(buf) |
| 1881 | call term_sendkeys(buf, "S\<C-X>\<C-O>f\<C-N>") |
| 1882 | call VerifyScreenDump(buf, 'Test_pum_matchins_combine_08', {}) |
| 1883 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
glepnir | 9fddb8a | 2025-01-11 16:42:50 +0100 | [diff] [blame] | 1884 | call TermWait(buf) |
| 1885 | |
| 1886 | call term_sendkeys(buf, ":set cot-=fuzzy\<CR>") |
| 1887 | call TermWait(buf) |
| 1888 | call term_sendkeys(buf, "Sf\<C-N>") |
| 1889 | call VerifyScreenDump(buf, 'Test_pum_matchins_combine_09', {}) |
| 1890 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
glepnir | e890887 | 2025-01-08 18:30:45 +0100 | [diff] [blame] | 1891 | |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1892 | call StopVimInTerminal(buf) |
| 1893 | endfunc |
| 1894 | |
glepnir | 8d0bb6d | 2024-12-24 09:44:35 +0100 | [diff] [blame] | 1895 | " this used to crash |
| 1896 | func Test_popup_completion_many_ctrlp() |
| 1897 | new |
| 1898 | let candidates=repeat(['a0'], 99) |
| 1899 | call setline(1, candidates) |
| 1900 | exe ":norm! VGg\<C-A>" |
| 1901 | norm! G |
| 1902 | call feedkeys("o" .. repeat("\<c-p>", 100), 'tx') |
| 1903 | bw! |
| 1904 | endfunc |
| 1905 | |
glepnir | 76bdb82 | 2025-02-08 19:04:51 +0100 | [diff] [blame] | 1906 | func Test_pum_complete_with_special_characters() |
| 1907 | CheckScreendump |
| 1908 | |
| 1909 | let lines =<< trim END |
| 1910 | func Omni_test(findstart, base) |
| 1911 | if a:findstart |
| 1912 | return col(".") |
| 1913 | endif |
| 1914 | return [#{word: "func ()\n\t\nend", abbr: "function ()",}, #{word: "foobar"}, #{word: "你好\n\t\n我好"}] |
| 1915 | endfunc |
| 1916 | set omnifunc=Omni_test |
glepnir | 34a7d82 | 2025-03-05 21:18:20 +0100 | [diff] [blame] | 1917 | inoremap <F5> <Cmd>call complete(col('.'), [ "my\n\tmulti\nline", "my\n\t\tmulti\nline" ])<CR> |
glepnir | 76bdb82 | 2025-02-08 19:04:51 +0100 | [diff] [blame] | 1918 | END |
| 1919 | |
| 1920 | call writefile(lines, 'Xpreviewscript', 'D') |
| 1921 | let buf = RunVimInTerminal('-S Xpreviewscript', #{rows: 12}) |
| 1922 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 1923 | call TermWait(buf, 50) |
| 1924 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_01', {}) |
| 1925 | |
| 1926 | call term_sendkeys(buf, "\<C-N>") |
| 1927 | call TermWait(buf, 50) |
| 1928 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_02', {}) |
| 1929 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1930 | |
| 1931 | call term_sendkeys(buf, "Shello hero\<ESC>hhhhha\<C-X>\<C-O>") |
| 1932 | call TermWait(buf, 50) |
| 1933 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_03', {}) |
| 1934 | |
| 1935 | call term_sendkeys(buf, "\<C-N>") |
| 1936 | call TermWait(buf, 50) |
| 1937 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_04', {}) |
| 1938 | |
| 1939 | call term_sendkeys(buf, "\<C-N>") |
| 1940 | call TermWait(buf, 50) |
| 1941 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_05', {}) |
| 1942 | |
| 1943 | call term_sendkeys(buf, "\<C-N>") |
| 1944 | call TermWait(buf, 50) |
| 1945 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_06', {}) |
| 1946 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1947 | |
| 1948 | call term_sendkeys(buf, ":hi ComplMatchIns ctermfg=red\<CR>") |
| 1949 | call TermWait(buf, 50) |
| 1950 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 1951 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_07', {}) |
| 1952 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1953 | |
| 1954 | call term_sendkeys(buf, "Shello hero\<ESC>hhhhha\<C-X>\<C-O>") |
| 1955 | call TermWait(buf, 50) |
| 1956 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_08', {}) |
| 1957 | call term_sendkeys(buf, "\<C-E>\<Esc>") |
| 1958 | |
glepnir | 5090a1f | 2025-02-24 19:10:37 +0100 | [diff] [blame] | 1959 | call term_sendkeys(buf, ":setlocal autoindent tabstop=2 shiftwidth=2\<CR>") |
| 1960 | call term_sendkeys(buf, "Slocal a = \<C-X>\<C-O>") |
| 1961 | call TermWait(buf, 50) |
| 1962 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_09', {}) |
| 1963 | |
| 1964 | call term_sendkeys(buf, "\<C-Y>") |
| 1965 | call TermWait(buf, 50) |
| 1966 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_10', {}) |
| 1967 | |
| 1968 | call term_sendkeys(buf, "\<ESC>kAlocal b = \<C-X>\<C-O>") |
| 1969 | call TermWait(buf, 50) |
| 1970 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_11', {}) |
| 1971 | |
| 1972 | call term_sendkeys(buf, "\<C-Y>") |
| 1973 | call TermWait(buf, 50) |
| 1974 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_12', {}) |
| 1975 | |
glepnir | 34a7d82 | 2025-03-05 21:18:20 +0100 | [diff] [blame] | 1976 | call term_sendkeys(buf, "\<ESC>ggVGd") |
| 1977 | call term_sendkeys(buf, ":filetype indent on\<CR>") |
| 1978 | call term_sendkeys(buf, ":set nocompatible autoindent& shiftwidth& tabstop&\<CR>") |
| 1979 | call term_sendkeys(buf, ":setlocal ft=lua\<CR>") |
| 1980 | call term_sendkeys(buf, "S\<F5>") |
| 1981 | call TermWait(buf, 50) |
| 1982 | call VerifyScreenDump(buf, 'Test_pum_with_special_characters_13', {}) |
| 1983 | |
glepnir | 76bdb82 | 2025-02-08 19:04:51 +0100 | [diff] [blame] | 1984 | call StopVimInTerminal(buf) |
| 1985 | endfunc |
| 1986 | |
glepnir | 88d7593 | 2025-03-27 20:09:07 +0100 | [diff] [blame] | 1987 | func Test_pum_maxwidth() |
| 1988 | CheckScreendump |
| 1989 | |
| 1990 | let lines =<< trim END |
| 1991 | 123456789_123456789_123456789_a |
| 1992 | 123456789_123456789_123456789_b |
| 1993 | 123 |
| 1994 | END |
| 1995 | call writefile(lines, 'Xtest', 'D') |
| 1996 | let buf = RunVimInTerminal('Xtest', {}) |
| 1997 | |
| 1998 | call term_sendkeys(buf, "G\"zyy") |
| 1999 | call term_sendkeys(buf, "A\<C-N>") |
| 2000 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_01', {'rows': 8}) |
| 2001 | call term_sendkeys(buf, "\<Esc>3Gdd\"zp") |
| 2002 | |
| 2003 | call term_sendkeys(buf, ":set pummaxwidth=10\<CR>") |
| 2004 | call term_sendkeys(buf, "GA\<C-N>") |
| 2005 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_02', {'rows': 8}) |
| 2006 | call term_sendkeys(buf, "\<Esc>3Gdd\"zp") |
| 2007 | |
| 2008 | call term_sendkeys(buf, ":set pummaxwidth=20\<CR>") |
| 2009 | call term_sendkeys(buf, "GA\<C-N>") |
| 2010 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_03', {'rows': 8}) |
| 2011 | call term_sendkeys(buf, "\<Esc>3Gdd\"zp") |
| 2012 | |
| 2013 | call term_sendkeys(buf, ":set pumwidth=20 pummaxwidth=8\<CR>") |
| 2014 | call term_sendkeys(buf, "GA\<C-N>") |
| 2015 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_04', {'rows': 8}) |
| 2016 | call term_sendkeys(buf, "\<Esc>3Gdd\"zp") |
| 2017 | |
glepnir | 532c5ae | 2025-03-28 19:21:59 +0100 | [diff] [blame] | 2018 | call term_sendkeys(buf, ":set lines=10 columns=32\<CR>") |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2019 | call TermWait(buf, 50) |
glepnir | 532c5ae | 2025-03-28 19:21:59 +0100 | [diff] [blame] | 2020 | call term_sendkeys(buf, "GA\<C-N>") |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2021 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_05', {'rows': 10, 'cols': 32}) |
glepnir | 532c5ae | 2025-03-28 19:21:59 +0100 | [diff] [blame] | 2022 | call term_sendkeys(buf, "\<Esc>3Gdd\"zp") |
| 2023 | |
glepnir | 88d7593 | 2025-03-27 20:09:07 +0100 | [diff] [blame] | 2024 | call StopVimInTerminal(buf) |
| 2025 | endfunc |
| 2026 | |
| 2027 | func Test_pum_maxwidth_multibyte() |
| 2028 | CheckScreendump |
| 2029 | |
| 2030 | let lines =<< trim END |
glepnir | 0816f17 | 2025-05-18 20:14:53 +0200 | [diff] [blame] | 2031 | hi StrikeFake ctermfg=9 |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2032 | let g:change = 0 |
glepnir | 88d7593 | 2025-03-27 20:09:07 +0100 | [diff] [blame] | 2033 | func Omni_test(findstart, base) |
| 2034 | if a:findstart |
| 2035 | return col(".") |
| 2036 | endif |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2037 | if g:change == 0 |
| 2038 | return [ |
| 2039 | \ #{word: "123456789_123456789_123456789_"}, |
| 2040 | \ #{word: "一二三四五六七八九十"}, |
| 2041 | \ #{word: "abcdefghij"}, |
| 2042 | \ #{word: "上下左右"}, |
| 2043 | \ ] |
| 2044 | elseif g:change == 1 |
| 2045 | return [ |
| 2046 | \ #{word: "foo", menu: "fooMenu", kind: "fooKind"}, |
| 2047 | \ #{word: "bar", menu: "barMenu", kind: "barKind"}, |
| 2048 | \ #{word: "baz", menu: "bazMenu", kind: "bazKind"}, |
| 2049 | \ ] |
| 2050 | elseif g:change == 2 |
| 2051 | return [ |
| 2052 | \ #{word: "foo", menu: "fooMenu", kind: "fooKind"}, |
| 2053 | \ #{word: "bar", menu: "fooMenu", kind: "一二三四"}, |
| 2054 | \ #{word: "一二三四五", kind: "multi"}, |
| 2055 | \ ] |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2056 | return [#{word: "bar", menu: "fooMenu", kind: "一二三"}] |
glepnir | 0816f17 | 2025-05-18 20:14:53 +0200 | [diff] [blame] | 2057 | elseif g:change == 3 |
| 2058 | return [#{word: "bar", menu: "fooMenu", kind: "一二三"}] |
| 2059 | else |
| 2060 | return [ |
| 2061 | \ #{word: "一二三四五六七八九十", abbr_hlgroup: "StrikeFake"}, |
| 2062 | \ #{word: "123456789_123456789_123456789_", abbr_hlgroup: "StrikeFake"}, |
| 2063 | \ ] |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2064 | endif |
glepnir | 88d7593 | 2025-03-27 20:09:07 +0100 | [diff] [blame] | 2065 | endfunc |
| 2066 | set omnifunc=Omni_test |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2067 | set cot+=menuone |
glepnir | 88d7593 | 2025-03-27 20:09:07 +0100 | [diff] [blame] | 2068 | END |
| 2069 | call writefile(lines, 'Xtest', 'D') |
| 2070 | let buf = RunVimInTerminal('-S Xtest', {}) |
| 2071 | call TermWait(buf) |
| 2072 | |
| 2073 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2074 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_06', {'rows': 8}) |
glepnir | 88d7593 | 2025-03-27 20:09:07 +0100 | [diff] [blame] | 2075 | call term_sendkeys(buf, "\<ESC>") |
| 2076 | |
| 2077 | call term_sendkeys(buf, ":set pummaxwidth=10\<CR>") |
| 2078 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2079 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_07', {'rows': 8}) |
glepnir | 88d7593 | 2025-03-27 20:09:07 +0100 | [diff] [blame] | 2080 | call term_sendkeys(buf, "\<ESC>") |
| 2081 | |
| 2082 | if has('rightleft') |
| 2083 | call term_sendkeys(buf, ":set rightleft\<CR>") |
| 2084 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2085 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_08', {'rows': 8}) |
glepnir | 88d7593 | 2025-03-27 20:09:07 +0100 | [diff] [blame] | 2086 | call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>") |
| 2087 | endif |
| 2088 | |
| 2089 | call term_sendkeys(buf, ":set pummaxwidth=2\<CR>") |
| 2090 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2091 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_09', {'rows': 8}) |
glepnir | 88d7593 | 2025-03-27 20:09:07 +0100 | [diff] [blame] | 2092 | call term_sendkeys(buf, "\<ESC>") |
| 2093 | |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2094 | call term_sendkeys(buf, ":set pummaxwidth=14\<CR>") |
| 2095 | call term_sendkeys(buf, ":let g:change=1\<CR>S\<C-X>\<C-O>") |
| 2096 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_10', {'rows': 8}) |
| 2097 | call term_sendkeys(buf, "\<ESC>") |
glepnir | 88d7593 | 2025-03-27 20:09:07 +0100 | [diff] [blame] | 2098 | |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2099 | " Unicode Character U+2026 but one cell |
| 2100 | call term_sendkeys(buf, ":set fcs+=trunc:…\<CR>") |
Hirohito Higashi | f13c856 | 2025-03-30 15:19:05 +0200 | [diff] [blame] | 2101 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2102 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_11', {'rows': 8}) |
Hirohito Higashi | f13c856 | 2025-03-30 15:19:05 +0200 | [diff] [blame] | 2103 | call term_sendkeys(buf, "\<ESC>") |
| 2104 | |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2105 | call term_sendkeys(buf, ":let g:change=2\<CR>S\<C-X>\<C-O>") |
| 2106 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_12', {'rows': 8}) |
Hirohito Higashi | f13c856 | 2025-03-30 15:19:05 +0200 | [diff] [blame] | 2107 | call term_sendkeys(buf, "\<ESC>") |
| 2108 | |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2109 | call term_sendkeys(buf, ":set fcs&\<CR>") |
Hirohito Higashi | f13c856 | 2025-03-30 15:19:05 +0200 | [diff] [blame] | 2110 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2111 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_13', {'rows': 8}) |
Hirohito Higashi | f13c856 | 2025-03-30 15:19:05 +0200 | [diff] [blame] | 2112 | call term_sendkeys(buf, "\<ESC>") |
| 2113 | |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2114 | call term_sendkeys(buf, ":set fcs=trunc:_\<CR>") |
| 2115 | call term_sendkeys(buf, ":let g:change=1\<CR>") |
| 2116 | call TermWait(buf, 50) |
Hirohito Higashi | f13c856 | 2025-03-30 15:19:05 +0200 | [diff] [blame] | 2117 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2118 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_14', {'rows': 8}) |
| 2119 | call term_sendkeys(buf, "\<ESC>") |
| 2120 | call term_sendkeys(buf, ":set fcs&\<CR>") |
| 2121 | |
| 2122 | if has('rightleft') |
| 2123 | call term_sendkeys(buf, ":set rightleft\<CR>") |
| 2124 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 2125 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_15', {'rows': 8}) |
| 2126 | call term_sendkeys(buf, "\<ESC>") |
| 2127 | |
| 2128 | call term_sendkeys(buf, ":let g:change=2\<CR>") |
| 2129 | call TermWait(buf, 50) |
| 2130 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 2131 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_16', {'rows': 8}) |
| 2132 | call term_sendkeys(buf, "\<ESC>") |
| 2133 | |
glepnir | d4dbf82 | 2025-04-12 18:35:34 +0200 | [diff] [blame] | 2134 | call term_sendkeys(buf, ":set fcs+=truncrl:…\<CR>") |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2135 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 2136 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_17', {'rows': 8}) |
| 2137 | call term_sendkeys(buf, "\<ESC>") |
| 2138 | |
| 2139 | call term_sendkeys(buf, ":set fcs&\<CR>") |
| 2140 | call term_sendkeys(buf, ":let g:change=3\<CR>") |
| 2141 | call TermWait(buf, 50) |
| 2142 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 2143 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_18', {'rows': 8}) |
| 2144 | call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>") |
| 2145 | endif |
| 2146 | |
| 2147 | call term_sendkeys(buf, ":set pummaxwidth=4\<CR>") |
| 2148 | call term_sendkeys(buf, ":let g:change=2\<CR>") |
| 2149 | call TermWait(buf, 50) |
| 2150 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 2151 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_19', {'rows': 8}) |
Hirohito Higashi | f13c856 | 2025-03-30 15:19:05 +0200 | [diff] [blame] | 2152 | call term_sendkeys(buf, "\<ESC>") |
| 2153 | |
glepnir | b876204 | 2025-04-07 20:57:14 +0200 | [diff] [blame] | 2154 | if has('rightleft') |
| 2155 | call term_sendkeys(buf, ":set rightleft\<CR>") |
| 2156 | call TermWait(buf, 50) |
| 2157 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 2158 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_20', {'rows': 8}) |
| 2159 | call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>") |
| 2160 | endif |
Hirohito Higashi | f13c856 | 2025-03-30 15:19:05 +0200 | [diff] [blame] | 2161 | |
zeertzjq | 031919c | 2025-04-16 18:23:23 +0200 | [diff] [blame] | 2162 | call term_sendkeys(buf, ":set pummaxwidth=16\<CR>") |
| 2163 | call TermWait(buf, 50) |
| 2164 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 2165 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_21', {'rows': 8}) |
| 2166 | call term_sendkeys(buf, "\<ESC>") |
| 2167 | |
| 2168 | if has('rightleft') |
| 2169 | call term_sendkeys(buf, ":set rightleft\<CR>") |
| 2170 | call TermWait(buf, 50) |
| 2171 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 2172 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_22', {'rows': 8}) |
| 2173 | call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>") |
| 2174 | endif |
| 2175 | |
glepnir | 0816f17 | 2025-05-18 20:14:53 +0200 | [diff] [blame] | 2176 | call term_sendkeys(buf, ":let g:change=4\<CR>") |
| 2177 | call TermWait(buf, 50) |
| 2178 | call term_sendkeys(buf, "S\<C-X>\<C-O>") |
| 2179 | call VerifyScreenDump(buf, 'Test_pum_maxwidth_23', {'rows': 8}) |
| 2180 | call term_sendkeys(buf, "\<ESC>") |
| 2181 | |
Hirohito Higashi | f13c856 | 2025-03-30 15:19:05 +0200 | [diff] [blame] | 2182 | call StopVimInTerminal(buf) |
| 2183 | endfunc |
| 2184 | |
glepnir | cf7f012 | 2025-04-15 19:02:00 +0200 | [diff] [blame] | 2185 | func Test_pum_clear_when_switch_tab_or_win() |
| 2186 | CheckScreendump |
| 2187 | |
| 2188 | let lines =<< trim END |
| 2189 | inoremap <F4> <Cmd>wincmd w<CR> |
| 2190 | inoremap <F5> <Cmd>tabnext<CR> |
| 2191 | END |
| 2192 | |
| 2193 | call writefile(lines, 'Xtest', 'D') |
| 2194 | let buf = RunVimInTerminal('-S Xtest', {}) |
| 2195 | |
| 2196 | call term_sendkeys(buf, ":tabe\<CR>") |
| 2197 | call TermWait(buf, 50) |
| 2198 | call term_sendkeys(buf, "Aaa aaa \<C-N>") |
| 2199 | call VerifyScreenDump(buf, 'Test_tabnext_clear_pum_01', {}) |
| 2200 | call term_sendkeys(buf, "\<F5>") |
| 2201 | call TermWait(buf, 50) |
| 2202 | call VerifyScreenDump(buf, 'Test_tabnext_clear_pum_02', {}) |
| 2203 | call term_sendkeys(buf, "\<ESC>:tabclose!\<CR>") |
| 2204 | |
| 2205 | call term_sendkeys(buf, ":vnew win_b\<CR>") |
| 2206 | call TermWait(buf, 50) |
| 2207 | call term_sendkeys(buf, "Abb bbb \<C-N>") |
| 2208 | call VerifyScreenDump(buf, 'Test_switchwin_clear_pum_01', {}) |
| 2209 | call term_sendkeys(buf, "\<F4>") |
| 2210 | call TermWait(buf, 50) |
| 2211 | call VerifyScreenDump(buf, 'Test_switchwin_clear_pum_02', {}) |
| 2212 | |
| 2213 | call StopVimInTerminal(buf) |
| 2214 | endfunc |
| 2215 | |
glepnir | 6cc9bd4 | 2025-06-11 21:14:02 +0200 | [diff] [blame] | 2216 | func Test_pum_position_when_wrap() |
| 2217 | CheckScreendump |
| 2218 | let lines =<< trim END |
| 2219 | func Omni_test(findstart, base) |
| 2220 | if a:findstart |
| 2221 | return col(".") |
| 2222 | endif |
| 2223 | return ['foo', 'bar', 'foobar'] |
| 2224 | endfunc |
| 2225 | set omnifunc=Omni_test |
| 2226 | set wrap |
| 2227 | set cot+=noinsert |
| 2228 | END |
| 2229 | call writefile(lines, 'Xtest', 'D') |
| 2230 | let buf = RunVimInTerminal('-S Xtest', #{rows: 15, cols: 25}) |
| 2231 | |
| 2232 | let long_text = repeat('abcde ', 20) |
| 2233 | call term_sendkeys(buf, "i" .. long_text) |
| 2234 | call TermWait(buf, 50) |
| 2235 | call term_sendkeys(buf, "\<ESC>") |
| 2236 | call TermWait(buf, 50) |
| 2237 | |
| 2238 | call term_sendkeys(buf, "5|") |
| 2239 | call TermWait(buf, 50) |
| 2240 | call term_sendkeys(buf, "a\<C-X>\<C-O>") |
| 2241 | call TermWait(buf, 100) |
| 2242 | call VerifyScreenDump(buf, 'Test_pum_wrap_line1', {}) |
| 2243 | call term_sendkeys(buf, "\<ESC>") |
| 2244 | call TermWait(buf, 50) |
| 2245 | |
| 2246 | call term_sendkeys(buf, "30|") |
| 2247 | call TermWait(buf, 50) |
| 2248 | call term_sendkeys(buf, "a\<C-X>\<C-O>") |
| 2249 | call TermWait(buf, 100) |
| 2250 | call VerifyScreenDump(buf, 'Test_pum_wrap_line2', {}) |
| 2251 | call term_sendkeys(buf, "\<ESC>") |
| 2252 | call TermWait(buf, 50) |
| 2253 | |
| 2254 | call term_sendkeys(buf, "55|") |
| 2255 | call TermWait(buf, 50) |
| 2256 | call term_sendkeys(buf, "a\<C-X>\<C-O>") |
| 2257 | call TermWait(buf, 100) |
| 2258 | call VerifyScreenDump(buf, 'Test_pum_wrap_line3', {}) |
| 2259 | call term_sendkeys(buf, "\<C-E>\<ESC>") |
| 2260 | call TermWait(buf, 50) |
| 2261 | |
| 2262 | call term_sendkeys(buf, "85|") |
| 2263 | call TermWait(buf, 50) |
| 2264 | call term_sendkeys(buf, "a\<C-X>\<C-O>") |
| 2265 | call TermWait(buf, 100) |
| 2266 | call VerifyScreenDump(buf, 'Test_pum_wrap_line4', {}) |
| 2267 | call term_sendkeys(buf, "\<C-E>\<ESC>") |
| 2268 | call TermWait(buf, 100) |
| 2269 | |
| 2270 | call term_sendkeys(buf, "108|") |
| 2271 | call TermWait(buf, 50) |
| 2272 | call term_sendkeys(buf, "a\<C-X>\<C-O>") |
| 2273 | call TermWait(buf, 100) |
| 2274 | call VerifyScreenDump(buf, 'Test_pum_wrap_line5', {}) |
| 2275 | call term_sendkeys(buf, "\<C-E>\<ESC>") |
| 2276 | call TermWait(buf, 100) |
| 2277 | |
| 2278 | call StopVimInTerminal(buf) |
| 2279 | endfunc |
| 2280 | |
glepnir | cf7f012 | 2025-04-15 19:02:00 +0200 | [diff] [blame] | 2281 | |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 2282 | " vim: shiftwidth=2 sts=2 expandtab |