Bram Moolenaar | 1b9645d | 2017-09-17 23:03:31 +0200 | [diff] [blame] | 1 | " Test WinBar |
| 2 | |
| 3 | if !has('menu') |
Bram Moolenaar | b0f94c1 | 2019-06-13 22:19:53 +0200 | [diff] [blame] | 4 | throw 'Skipped, menu feature missing' |
Bram Moolenaar | 1b9645d | 2017-09-17 23:03:31 +0200 | [diff] [blame] | 5 | endif |
| 6 | |
Bram Moolenaar | 8caef44 | 2019-05-04 17:30:04 +0200 | [diff] [blame] | 7 | source shared.vim |
| 8 | |
Bram Moolenaar | 1b9645d | 2017-09-17 23:03:31 +0200 | [diff] [blame] | 9 | func Test_add_remove_menu() |
| 10 | new |
| 11 | amenu 1.10 WinBar.Next :let g:did_next = 11<CR> |
| 12 | amenu 1.20 WinBar.Cont :let g:did_cont = 12<CR> |
Bram Moolenaar | 8caef44 | 2019-05-04 17:30:04 +0200 | [diff] [blame] | 13 | redraw |
| 14 | call assert_match('Next Cont', Screenline(1)) |
| 15 | |
Bram Moolenaar | 1b9645d | 2017-09-17 23:03:31 +0200 | [diff] [blame] | 16 | emenu WinBar.Next |
| 17 | call assert_equal(11, g:did_next) |
| 18 | emenu WinBar.Cont |
| 19 | call assert_equal(12, g:did_cont) |
| 20 | |
| 21 | wincmd w |
| 22 | call assert_fails('emenu WinBar.Next', 'E334') |
| 23 | wincmd p |
| 24 | |
| 25 | aunmenu WinBar.Next |
| 26 | aunmenu WinBar.Cont |
| 27 | close |
| 28 | endfunc |
Bram Moolenaar | 66f8311 | 2019-05-04 16:06:12 +0200 | [diff] [blame] | 29 | |
Bram Moolenaar | 711f02d | 2019-05-05 13:14:28 +0200 | [diff] [blame] | 30 | " Create a WinBar with three buttons. |
| 31 | " Columns of the button edges: |
| 32 | " _Next_ _Cont_ _Close_ |
| 33 | " 2 7 10 15 18 24 |
| 34 | func SetupWinbar() |
Bram Moolenaar | 66f8311 | 2019-05-04 16:06:12 +0200 | [diff] [blame] | 35 | amenu 1.10 WinBar.Next :let g:did_next = 11<CR> |
| 36 | amenu 1.20 WinBar.Cont :let g:did_cont = 12<CR> |
| 37 | amenu 1.30 WinBar.Close :close<CR> |
| 38 | redraw |
Bram Moolenaar | 8caef44 | 2019-05-04 17:30:04 +0200 | [diff] [blame] | 39 | call assert_match('Next Cont Close', Screenline(1)) |
Bram Moolenaar | 711f02d | 2019-05-05 13:14:28 +0200 | [diff] [blame] | 40 | endfunc |
Bram Moolenaar | 66f8311 | 2019-05-04 16:06:12 +0200 | [diff] [blame] | 41 | |
Bram Moolenaar | 711f02d | 2019-05-05 13:14:28 +0200 | [diff] [blame] | 42 | func Test_click_in_winbar() |
| 43 | new |
| 44 | call SetupWinbar() |
Bram Moolenaar | 66f8311 | 2019-05-04 16:06:12 +0200 | [diff] [blame] | 45 | let save_mouse = &mouse |
| 46 | set mouse=a |
| 47 | |
Bram Moolenaar | 66f8311 | 2019-05-04 16:06:12 +0200 | [diff] [blame] | 48 | let g:did_next = 0 |
| 49 | let g:did_cont = 0 |
| 50 | for col in [1, 8, 9, 16, 17, 25, 26] |
Bram Moolenaar | 8caef44 | 2019-05-04 17:30:04 +0200 | [diff] [blame] | 51 | call test_setmouse(1, col) |
Bram Moolenaar | 66f8311 | 2019-05-04 16:06:12 +0200 | [diff] [blame] | 52 | call feedkeys("\<LeftMouse>", "xt") |
| 53 | call assert_equal(0, g:did_next, 'col ' .. col) |
| 54 | call assert_equal(0, g:did_cont, 'col ' .. col) |
| 55 | endfor |
| 56 | |
| 57 | for col in range(2, 7) |
| 58 | let g:did_next = 0 |
| 59 | call test_setmouse(1, col) |
| 60 | call feedkeys("\<LeftMouse>", "xt") |
| 61 | call assert_equal(11, g:did_next, 'col ' .. col) |
| 62 | endfor |
| 63 | |
| 64 | for col in range(10, 15) |
| 65 | let g:did_cont = 0 |
| 66 | call test_setmouse(1, col) |
| 67 | call feedkeys("\<LeftMouse>", "xt") |
| 68 | call assert_equal(12, g:did_cont, 'col ' .. col) |
| 69 | endfor |
| 70 | |
| 71 | let wincount = winnr('$') |
| 72 | call test_setmouse(1, 20) |
| 73 | call feedkeys("\<LeftMouse>", "xt") |
| 74 | call assert_equal(wincount - 1, winnr('$')) |
| 75 | |
| 76 | let &mouse = save_mouse |
| 77 | endfunc |
Bram Moolenaar | 711f02d | 2019-05-05 13:14:28 +0200 | [diff] [blame] | 78 | |
| 79 | func Test_click_in_other_winbar() |
| 80 | new |
| 81 | call SetupWinbar() |
| 82 | let save_mouse = &mouse |
| 83 | set mouse=a |
| 84 | let winid = win_getid() |
| 85 | |
| 86 | split |
| 87 | let [row, col] = win_screenpos(winid) |
| 88 | |
| 89 | " Click on Next button in other window |
| 90 | let g:did_next = 0 |
| 91 | call test_setmouse(row, 5) |
| 92 | call feedkeys("\<LeftMouse>", "xt") |
| 93 | call assert_equal(11, g:did_next) |
| 94 | |
| 95 | " Click on Cont button in other window from Visual mode |
| 96 | let g:did_cont = 0 |
| 97 | call setline(1, 'select XYZ here') |
| 98 | call test_setmouse(row, 12) |
| 99 | call feedkeys("0fXvfZ\<LeftMouse>x", "xt") |
| 100 | call assert_equal(12, g:did_cont) |
| 101 | call assert_equal('select here', getline(1)) |
| 102 | |
| 103 | " Click on Close button in other window |
| 104 | let wincount = winnr('$') |
| 105 | let winid = win_getid() |
| 106 | call test_setmouse(row, 20) |
| 107 | call feedkeys("\<LeftMouse>", "xt") |
| 108 | call assert_equal(wincount - 1, winnr('$')) |
| 109 | call assert_equal(winid, win_getid()) |
| 110 | |
| 111 | bwipe! |
| 112 | endfunc |
Bram Moolenaar | 98fb65c | 2019-06-02 20:33:32 +0200 | [diff] [blame] | 113 | |
| 114 | func Test_redraw_after_scroll() |
| 115 | new |
| 116 | amenu 1.10 WinBar.Next :let g:did_next = 11<CR> |
| 117 | redraw |
| 118 | call assert_equal(" Next", Screenline(1)) |
| 119 | echo "some\nmore" |
| 120 | redraw |
| 121 | call assert_equal(" Next", Screenline(1)) |
| 122 | bwipe! |
| 123 | endfunc |
| 124 | |