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