blob: 59241746b972c8ae2f418fdb1cc9710aca61c81c [file] [log] [blame]
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02001" Test WinBar
2
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02003CheckFeature menu
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02004
Christian Brabandteb380b92025-07-07 20:53:55 +02005source util/screendump.vim
Bram Moolenaar8caef442019-05-04 17:30:04 +02006
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02007func Test_add_remove_menu()
8 new
9 amenu 1.10 WinBar.Next :let g:did_next = 11<CR>
10 amenu 1.20 WinBar.Cont :let g:did_cont = 12<CR>
Bram Moolenaar8caef442019-05-04 17:30:04 +020011 redraw
12 call assert_match('Next Cont', Screenline(1))
13
Bram Moolenaar1b9645d2017-09-17 23:03:31 +020014 emenu WinBar.Next
15 call assert_equal(11, g:did_next)
16 emenu WinBar.Cont
17 call assert_equal(12, g:did_cont)
18
19 wincmd w
Bram Moolenaare2e40752020-09-04 21:18:46 +020020 call assert_fails('emenu WinBar.Next', 'E334:')
Bram Moolenaar1b9645d2017-09-17 23:03:31 +020021 wincmd p
22
23 aunmenu WinBar.Next
24 aunmenu WinBar.Cont
25 close
26endfunc
Bram Moolenaar66f83112019-05-04 16:06:12 +020027
Bram Moolenaar711f02d2019-05-05 13:14:28 +020028" Create a WinBar with three buttons.
29" Columns of the button edges:
30" _Next_ _Cont_ _Close_
31" 2 7 10 15 18 24
32func SetupWinbar()
Bram Moolenaar66f83112019-05-04 16:06:12 +020033 amenu 1.10 WinBar.Next :let g:did_next = 11<CR>
34 amenu 1.20 WinBar.Cont :let g:did_cont = 12<CR>
35 amenu 1.30 WinBar.Close :close<CR>
36 redraw
Bram Moolenaar8caef442019-05-04 17:30:04 +020037 call assert_match('Next Cont Close', Screenline(1))
Bram Moolenaar711f02d2019-05-05 13:14:28 +020038endfunc
Bram Moolenaar66f83112019-05-04 16:06:12 +020039
Bram Moolenaar711f02d2019-05-05 13:14:28 +020040func Test_click_in_winbar()
41 new
42 call SetupWinbar()
Bram Moolenaar66f83112019-05-04 16:06:12 +020043 let save_mouse = &mouse
44 set mouse=a
45
Bram Moolenaar66f83112019-05-04 16:06:12 +020046 let g:did_next = 0
47 let g:did_cont = 0
48 for col in [1, 8, 9, 16, 17, 25, 26]
Bram Moolenaar8caef442019-05-04 17:30:04 +020049 call test_setmouse(1, col)
Bram Moolenaar66f83112019-05-04 16:06:12 +020050 call feedkeys("\<LeftMouse>", "xt")
51 call assert_equal(0, g:did_next, 'col ' .. col)
52 call assert_equal(0, g:did_cont, 'col ' .. col)
53 endfor
54
55 for col in range(2, 7)
56 let g:did_next = 0
57 call test_setmouse(1, col)
58 call feedkeys("\<LeftMouse>", "xt")
59 call assert_equal(11, g:did_next, 'col ' .. col)
60 endfor
61
62 for col in range(10, 15)
63 let g:did_cont = 0
64 call test_setmouse(1, col)
65 call feedkeys("\<LeftMouse>", "xt")
66 call assert_equal(12, g:did_cont, 'col ' .. col)
67 endfor
68
69 let wincount = winnr('$')
70 call test_setmouse(1, 20)
71 call feedkeys("\<LeftMouse>", "xt")
72 call assert_equal(wincount - 1, winnr('$'))
73
74 let &mouse = save_mouse
75endfunc
Bram Moolenaar711f02d2019-05-05 13:14:28 +020076
77func Test_click_in_other_winbar()
78 new
79 call SetupWinbar()
80 let save_mouse = &mouse
81 set mouse=a
82 let winid = win_getid()
83
84 split
85 let [row, col] = win_screenpos(winid)
86
87 " Click on Next button in other window
88 let g:did_next = 0
89 call test_setmouse(row, 5)
90 call feedkeys("\<LeftMouse>", "xt")
91 call assert_equal(11, g:did_next)
92
93 " Click on Cont button in other window from Visual mode
94 let g:did_cont = 0
95 call setline(1, 'select XYZ here')
96 call test_setmouse(row, 12)
97 call feedkeys("0fXvfZ\<LeftMouse>x", "xt")
98 call assert_equal(12, g:did_cont)
99 call assert_equal('select here', getline(1))
100
101 " Click on Close button in other window
102 let wincount = winnr('$')
103 let winid = win_getid()
104 call test_setmouse(row, 20)
105 call feedkeys("\<LeftMouse>", "xt")
106 call assert_equal(wincount - 1, winnr('$'))
107 call assert_equal(winid, win_getid())
108
109 bwipe!
110endfunc
Bram Moolenaar98fb65c2019-06-02 20:33:32 +0200111
112func Test_redraw_after_scroll()
113 new
114 amenu 1.10 WinBar.Next :let g:did_next = 11<CR>
115 redraw
116 call assert_equal(" Next", Screenline(1))
117 echo "some\nmore"
118 redraw
119 call assert_equal(" Next", Screenline(1))
120 bwipe!
121endfunc
122
Bram Moolenaarae0f1512021-03-30 22:12:12 +0200123func Test_winbar_not_visible()
124 CheckScreendump
125
126 let lines =<< trim END
127 split
128 nnoremenu WinBar.Test :test
129 set winminheight=0
130 wincmd j
131 wincmd _
132 END
dundargocc57b5bc2022-11-02 13:30:51 +0000133 call writefile(lines, 'XtestWinbarNotVisible', 'D')
134 let buf = RunVimInTerminal('-S XtestWinbarNotVisible', #{rows: 10})
Bram Moolenaarae0f1512021-03-30 22:12:12 +0200135 call VerifyScreenDump(buf, 'Test_winbar_not_visible', {})
136
137 " clean up
138 call StopVimInTerminal(buf)
Bram Moolenaarae0f1512021-03-30 22:12:12 +0200139endfunction
140
Bram Moolenaar49c51b82021-04-01 16:16:18 +0200141func Test_winbar_not_visible_custom_statusline()
142 CheckScreendump
143
144 let lines =<< trim END
145 split
146 nnoremenu WinBar.Test :test
147 set winminheight=0
148 set statusline=abcde
149 wincmd j
150 wincmd _
151 END
dundargocc57b5bc2022-11-02 13:30:51 +0000152 call writefile(lines, 'XtestWinbarNotVisible', 'D')
153 let buf = RunVimInTerminal('-S XtestWinbarNotVisible', #{rows: 10})
Bram Moolenaar49c51b82021-04-01 16:16:18 +0200154 call VerifyScreenDump(buf, 'Test_winbar_not_visible_custom_statusline', {})
155
156 " clean up
157 call StopVimInTerminal(buf)
Bram Moolenaar49c51b82021-04-01 16:16:18 +0200158endfunction
159
zeertzjq6dab00a2022-05-20 13:45:59 +0100160func Test_drag_statusline_with_winbar()
161 call SetupWinbar()
162 let save_mouse = &mouse
163 set mouse=a
164 set laststatus=2
165
166 call test_setmouse(&lines - 1, 1)
167 call feedkeys("\<LeftMouse>", 'xt')
168 call test_setmouse(&lines - 2, 1)
169 call feedkeys("\<LeftDrag>", 'xt')
170 call assert_equal(2, &cmdheight)
171
172 call test_setmouse(&lines - 2, 1)
173 call feedkeys("\<LeftMouse>", 'xt')
174 call test_setmouse(&lines - 3, 1)
175 call feedkeys("\<LeftDrag>", 'xt')
176 call assert_equal(3, &cmdheight)
177
178 call test_setmouse(&lines - 3, 1)
179 call feedkeys("\<LeftMouse>", 'xt')
180 call test_setmouse(&lines - 1, 1)
181 call feedkeys("\<LeftDrag>", 'xt')
182 call assert_equal(1, &cmdheight)
183
184 let &mouse = save_mouse
185 set laststatus&
186endfunc
187
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200188" vim: shiftwidth=2 sts=2 expandtab