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