Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 1 | " Test for reset 'scroll' and 'smoothscroll' |
| 2 | |
| 3 | source check.vim |
| 4 | source screendump.vim |
Yee Cheng Chin | e6392b1 | 2022-11-19 14:31:08 +0000 | [diff] [blame] | 5 | source mouse.vim |
Bram Moolenaar | af2d20c | 2017-10-29 15:26:57 +0100 | [diff] [blame] | 6 | |
| 7 | func Test_reset_scroll() |
| 8 | let scr = &l:scroll |
| 9 | |
| 10 | setlocal scroll=1 |
| 11 | setlocal scroll& |
| 12 | call assert_equal(scr, &l:scroll) |
| 13 | |
| 14 | setlocal scroll=1 |
| 15 | setlocal scroll=0 |
| 16 | call assert_equal(scr, &l:scroll) |
| 17 | |
| 18 | try |
| 19 | execute 'setlocal scroll=' . (winheight(0) + 1) |
| 20 | " not reached |
| 21 | call assert_false(1) |
| 22 | catch |
| 23 | call assert_exception('E49:') |
| 24 | endtry |
| 25 | |
| 26 | split |
| 27 | |
| 28 | let scr = &l:scroll |
| 29 | |
| 30 | setlocal scroll=1 |
| 31 | setlocal scroll& |
| 32 | call assert_equal(scr, &l:scroll) |
| 33 | |
| 34 | setlocal scroll=1 |
| 35 | setlocal scroll=0 |
| 36 | call assert_equal(scr, &l:scroll) |
| 37 | |
| 38 | quit! |
| 39 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 40 | |
Bram Moolenaar | 1d6539c | 2023-02-14 17:41:20 +0000 | [diff] [blame] | 41 | func Test_scolloff_even_line_count() |
| 42 | new |
| 43 | resize 6 |
| 44 | setlocal scrolloff=3 |
| 45 | call setline(1, range(20)) |
| 46 | normal 2j |
| 47 | call assert_equal(1, getwininfo(win_getid())[0].topline) |
| 48 | normal j |
| 49 | call assert_equal(1, getwininfo(win_getid())[0].topline) |
| 50 | normal j |
| 51 | call assert_equal(2, getwininfo(win_getid())[0].topline) |
| 52 | normal j |
| 53 | call assert_equal(3, getwininfo(win_getid())[0].topline) |
| 54 | |
| 55 | bwipe! |
| 56 | endfunc |
| 57 | |
Bram Moolenaar | 8df9748 | 2022-10-03 12:11:13 +0100 | [diff] [blame] | 58 | func Test_CtrlE_CtrlY_stop_at_end() |
| 59 | enew |
| 60 | call setline(1, ['one', 'two']) |
| 61 | set number |
| 62 | exe "normal \<C-Y>" |
| 63 | call assert_equal([" 1 one "], ScreenLines(1, 10)) |
| 64 | exe "normal \<C-E>\<C-E>\<C-E>" |
| 65 | call assert_equal([" 2 two "], ScreenLines(1, 10)) |
| 66 | |
| 67 | bwipe! |
| 68 | set nonumber |
| 69 | endfunc |
| 70 | |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 71 | func Test_smoothscroll_CtrlE_CtrlY() |
| 72 | CheckScreendump |
| 73 | |
| 74 | let lines =<< trim END |
| 75 | vim9script |
| 76 | setline(1, [ |
| 77 | 'line one', |
| 78 | 'word '->repeat(20), |
| 79 | 'line three', |
| 80 | 'long word '->repeat(7), |
| 81 | 'line', |
| 82 | 'line', |
| 83 | 'line', |
| 84 | ]) |
| 85 | set smoothscroll |
| 86 | :5 |
| 87 | END |
| 88 | call writefile(lines, 'XSmoothScroll', 'D') |
| 89 | let buf = RunVimInTerminal('-S XSmoothScroll', #{rows: 12, cols: 40}) |
| 90 | |
| 91 | call term_sendkeys(buf, "\<C-E>") |
| 92 | call VerifyScreenDump(buf, 'Test_smoothscroll_1', {}) |
| 93 | call term_sendkeys(buf, "\<C-E>") |
| 94 | call VerifyScreenDump(buf, 'Test_smoothscroll_2', {}) |
| 95 | call term_sendkeys(buf, "\<C-E>") |
| 96 | call VerifyScreenDump(buf, 'Test_smoothscroll_3', {}) |
| 97 | call term_sendkeys(buf, "\<C-E>") |
| 98 | call VerifyScreenDump(buf, 'Test_smoothscroll_4', {}) |
| 99 | |
| 100 | call term_sendkeys(buf, "\<C-Y>") |
| 101 | call VerifyScreenDump(buf, 'Test_smoothscroll_5', {}) |
| 102 | call term_sendkeys(buf, "\<C-Y>") |
| 103 | call VerifyScreenDump(buf, 'Test_smoothscroll_6', {}) |
| 104 | call term_sendkeys(buf, "\<C-Y>") |
| 105 | call VerifyScreenDump(buf, 'Test_smoothscroll_7', {}) |
| 106 | call term_sendkeys(buf, "\<C-Y>") |
| 107 | call VerifyScreenDump(buf, 'Test_smoothscroll_8', {}) |
| 108 | |
Bram Moolenaar | 6b2d4ff | 2022-10-03 14:06:02 +0100 | [diff] [blame] | 109 | if has('folding') |
| 110 | call term_sendkeys(buf, ":set foldmethod=indent\<CR>") |
| 111 | " move the cursor so we can reuse the same dumps |
| 112 | call term_sendkeys(buf, "5G") |
| 113 | call term_sendkeys(buf, "\<C-E>") |
| 114 | call VerifyScreenDump(buf, 'Test_smoothscroll_1', {}) |
| 115 | call term_sendkeys(buf, "\<C-E>") |
| 116 | call VerifyScreenDump(buf, 'Test_smoothscroll_2', {}) |
| 117 | call term_sendkeys(buf, "7G") |
| 118 | call term_sendkeys(buf, "\<C-Y>") |
| 119 | call VerifyScreenDump(buf, 'Test_smoothscroll_7', {}) |
| 120 | call term_sendkeys(buf, "\<C-Y>") |
| 121 | call VerifyScreenDump(buf, 'Test_smoothscroll_8', {}) |
| 122 | endif |
| 123 | |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 124 | call StopVimInTerminal(buf) |
| 125 | endfunc |
| 126 | |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 127 | func Test_smoothscroll_number() |
| 128 | CheckScreendump |
| 129 | |
| 130 | let lines =<< trim END |
| 131 | vim9script |
| 132 | setline(1, [ |
| 133 | 'one ' .. 'word '->repeat(20), |
| 134 | 'two ' .. 'long word '->repeat(7), |
| 135 | 'line', |
| 136 | 'line', |
| 137 | 'line', |
| 138 | ]) |
| 139 | set smoothscroll |
zeertzjq | 88bb3e0 | 2023-05-02 20:52:59 +0100 | [diff] [blame] | 140 | set splitkeep=topline |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 141 | set number cpo+=n |
| 142 | :3 |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 143 | |
| 144 | def g:DoRel() |
| 145 | set number relativenumber scrolloff=0 |
| 146 | :%del |
| 147 | setline(1, [ |
| 148 | 'one', |
| 149 | 'very long text '->repeat(12), |
| 150 | 'three', |
| 151 | ]) |
| 152 | exe "normal 2Gzt\<C-E>" |
| 153 | enddef |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 154 | END |
| 155 | call writefile(lines, 'XSmoothNumber', 'D') |
| 156 | let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40}) |
| 157 | |
| 158 | call VerifyScreenDump(buf, 'Test_smooth_number_1', {}) |
| 159 | call term_sendkeys(buf, "\<C-E>") |
| 160 | call VerifyScreenDump(buf, 'Test_smooth_number_2', {}) |
| 161 | call term_sendkeys(buf, "\<C-E>") |
| 162 | call VerifyScreenDump(buf, 'Test_smooth_number_3', {}) |
| 163 | |
| 164 | call term_sendkeys(buf, ":set cpo-=n\<CR>") |
| 165 | call VerifyScreenDump(buf, 'Test_smooth_number_4', {}) |
| 166 | call term_sendkeys(buf, "\<C-Y>") |
| 167 | call VerifyScreenDump(buf, 'Test_smooth_number_5', {}) |
| 168 | call term_sendkeys(buf, "\<C-Y>") |
| 169 | call VerifyScreenDump(buf, 'Test_smooth_number_6', {}) |
| 170 | |
zeertzjq | 88bb3e0 | 2023-05-02 20:52:59 +0100 | [diff] [blame] | 171 | call term_sendkeys(buf, ":botright split\<CR>gg") |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 172 | call VerifyScreenDump(buf, 'Test_smooth_number_7', {}) |
zeertzjq | 88bb3e0 | 2023-05-02 20:52:59 +0100 | [diff] [blame] | 173 | call term_sendkeys(buf, "\<C-E>") |
| 174 | call VerifyScreenDump(buf, 'Test_smooth_number_8', {}) |
| 175 | call term_sendkeys(buf, "\<C-E>") |
| 176 | call VerifyScreenDump(buf, 'Test_smooth_number_9', {}) |
| 177 | call term_sendkeys(buf, ":close\<CR>") |
| 178 | |
| 179 | call term_sendkeys(buf, ":call DoRel()\<CR>") |
| 180 | call VerifyScreenDump(buf, 'Test_smooth_number_10', {}) |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 181 | |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 182 | call StopVimInTerminal(buf) |
| 183 | endfunc |
| 184 | |
Bram Moolenaar | 13cdde3 | 2022-10-15 14:07:48 +0100 | [diff] [blame] | 185 | func Test_smoothscroll_list() |
| 186 | CheckScreendump |
| 187 | |
| 188 | let lines =<< trim END |
| 189 | vim9script |
| 190 | set smoothscroll scrolloff=0 |
| 191 | set list |
| 192 | setline(1, [ |
| 193 | 'one', |
| 194 | 'very long text '->repeat(12), |
| 195 | 'three', |
| 196 | ]) |
| 197 | exe "normal 2Gzt\<C-E>" |
| 198 | END |
| 199 | call writefile(lines, 'XSmoothList', 'D') |
| 200 | let buf = RunVimInTerminal('-S XSmoothList', #{rows: 8, cols: 40}) |
| 201 | |
| 202 | call VerifyScreenDump(buf, 'Test_smooth_list_1', {}) |
| 203 | |
| 204 | call term_sendkeys(buf, ":set listchars+=precedes:#\<CR>") |
| 205 | call VerifyScreenDump(buf, 'Test_smooth_list_2', {}) |
| 206 | |
| 207 | call StopVimInTerminal(buf) |
| 208 | endfunc |
| 209 | |
Bram Moolenaar | 1a58e1d | 2022-10-06 13:09:17 +0100 | [diff] [blame] | 210 | func Test_smoothscroll_diff_mode() |
| 211 | CheckScreendump |
| 212 | |
| 213 | let lines =<< trim END |
| 214 | vim9script |
| 215 | var text = 'just some text here' |
| 216 | setline(1, text) |
| 217 | set smoothscroll |
| 218 | diffthis |
| 219 | new |
| 220 | setline(1, text) |
| 221 | set smoothscroll |
| 222 | diffthis |
| 223 | END |
| 224 | call writefile(lines, 'XSmoothDiff', 'D') |
| 225 | let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8}) |
| 226 | |
| 227 | call VerifyScreenDump(buf, 'Test_smooth_diff_1', {}) |
| 228 | call term_sendkeys(buf, "\<C-Y>") |
| 229 | call VerifyScreenDump(buf, 'Test_smooth_diff_1', {}) |
| 230 | call term_sendkeys(buf, "\<C-E>") |
| 231 | call VerifyScreenDump(buf, 'Test_smooth_diff_1', {}) |
| 232 | |
| 233 | call StopVimInTerminal(buf) |
| 234 | endfunc |
| 235 | |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 236 | func Test_smoothscroll_wrap_scrolloff_zero() |
| 237 | CheckScreendump |
| 238 | |
| 239 | let lines =<< trim END |
| 240 | vim9script |
| 241 | setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7)) |
| 242 | set smoothscroll scrolloff=0 |
| 243 | :3 |
| 244 | END |
| 245 | call writefile(lines, 'XSmoothWrap', 'D') |
| 246 | let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40}) |
| 247 | |
| 248 | call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {}) |
| 249 | |
Bram Moolenaar | 46b5474 | 2022-10-06 15:46:49 +0100 | [diff] [blame] | 250 | " moving cursor down - whole bottom line shows |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 251 | call term_sendkeys(buf, "j") |
| 252 | call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {}) |
| 253 | |
| 254 | call term_sendkeys(buf, "\<C-E>j") |
| 255 | call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {}) |
| 256 | |
| 257 | call term_sendkeys(buf, "G") |
| 258 | call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {}) |
| 259 | |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 260 | " moving cursor up right after the >>> marker - no need to show whole line |
| 261 | call term_sendkeys(buf, "2gj3l2k") |
Bram Moolenaar | 46b5474 | 2022-10-06 15:46:49 +0100 | [diff] [blame] | 262 | call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {}) |
| 263 | |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 264 | " moving cursor up where the >>> marker is - whole top line shows |
| 265 | call term_sendkeys(buf, "2j02k") |
| 266 | call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {}) |
| 267 | |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 268 | call StopVimInTerminal(buf) |
| 269 | endfunc |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 270 | |
Bram Moolenaar | 8cf3459 | 2022-10-08 21:13:40 +0100 | [diff] [blame] | 271 | func Test_smoothscroll_wrap_long_line() |
| 272 | CheckScreendump |
| 273 | |
| 274 | let lines =<< trim END |
| 275 | vim9script |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 276 | setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four']) |
Bram Moolenaar | 8cf3459 | 2022-10-08 21:13:40 +0100 | [diff] [blame] | 277 | set smoothscroll scrolloff=0 |
| 278 | normal 3G10|zt |
| 279 | END |
| 280 | call writefile(lines, 'XSmoothWrap', 'D') |
| 281 | let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40}) |
| 282 | call VerifyScreenDump(buf, 'Test_smooth_long_1', {}) |
| 283 | |
| 284 | " scrolling up, cursor moves screen line down |
| 285 | call term_sendkeys(buf, "\<C-E>") |
| 286 | call VerifyScreenDump(buf, 'Test_smooth_long_2', {}) |
| 287 | call term_sendkeys(buf, "5\<C-E>") |
| 288 | call VerifyScreenDump(buf, 'Test_smooth_long_3', {}) |
| 289 | |
| 290 | " scrolling down, cursor moves screen line up |
| 291 | call term_sendkeys(buf, "5\<C-Y>") |
| 292 | call VerifyScreenDump(buf, 'Test_smooth_long_4', {}) |
| 293 | call term_sendkeys(buf, "\<C-Y>") |
| 294 | call VerifyScreenDump(buf, 'Test_smooth_long_5', {}) |
| 295 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 296 | " 'scrolloff' set to 1, scrolling up, cursor moves screen line down |
| 297 | call term_sendkeys(buf, ":set scrolloff=1\<CR>") |
| 298 | call term_sendkeys(buf, "10|\<C-E>") |
| 299 | call VerifyScreenDump(buf, 'Test_smooth_long_6', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 300 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 301 | " 'scrolloff' set to 1, scrolling down, cursor moves screen line up |
| 302 | call term_sendkeys(buf, "\<C-E>") |
| 303 | call term_sendkeys(buf, "gjgj") |
| 304 | call term_sendkeys(buf, "\<C-Y>") |
| 305 | call VerifyScreenDump(buf, 'Test_smooth_long_7', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 306 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 307 | " 'scrolloff' set to 2, scrolling up, cursor moves screen line down |
| 308 | call term_sendkeys(buf, ":set scrolloff=2\<CR>") |
| 309 | call term_sendkeys(buf, "10|\<C-E>") |
| 310 | call VerifyScreenDump(buf, 'Test_smooth_long_8', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 311 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 312 | " 'scrolloff' set to 2, scrolling down, cursor moves screen line up |
| 313 | call term_sendkeys(buf, "\<C-E>") |
| 314 | call term_sendkeys(buf, "gj") |
| 315 | call term_sendkeys(buf, "\<C-Y>") |
| 316 | call VerifyScreenDump(buf, 'Test_smooth_long_9', {}) |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 317 | |
| 318 | " 'scrolloff' set to 0, move cursor down one line. |
| 319 | " Cursor should move properly, and since this is a really long line, it will |
| 320 | " be put on top of the screen. |
| 321 | call term_sendkeys(buf, ":set scrolloff=0\<CR>") |
| 322 | call term_sendkeys(buf, "0j") |
| 323 | call VerifyScreenDump(buf, 'Test_smooth_long_10', {}) |
| 324 | |
Bram Moolenaar | db4d88c | 2022-12-31 15:13:22 +0000 | [diff] [blame] | 325 | " Test zt/zz/zb that they work properly when a long line is above it |
| 326 | call term_sendkeys(buf, "zb") |
| 327 | call VerifyScreenDump(buf, 'Test_smooth_long_11', {}) |
| 328 | call term_sendkeys(buf, "zz") |
| 329 | call VerifyScreenDump(buf, 'Test_smooth_long_12', {}) |
| 330 | call term_sendkeys(buf, "zt") |
| 331 | call VerifyScreenDump(buf, 'Test_smooth_long_13', {}) |
| 332 | |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 333 | " Repeat the step and move the cursor down again. |
| 334 | " This time, use a shorter long line that is barely long enough to span more |
| 335 | " than one window. Note that the cursor is at the bottom this time because |
| 336 | " Vim prefers to do so if we are scrolling a few lines only. |
| 337 | call term_sendkeys(buf, ":call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(10)) .. ' end', 'four'])\<CR>") |
| 338 | call term_sendkeys(buf, "3Gzt") |
| 339 | call term_sendkeys(buf, "j") |
Bram Moolenaar | db4d88c | 2022-12-31 15:13:22 +0000 | [diff] [blame] | 340 | call VerifyScreenDump(buf, 'Test_smooth_long_14', {}) |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 341 | |
| 342 | " Repeat the step but this time start it when the line is smooth-scrolled by |
| 343 | " one line. This tests that the offset calculation is still correct and |
| 344 | " still end up scrolling down to the next line with cursor at bottom of |
| 345 | " screen. |
| 346 | call term_sendkeys(buf, "3Gzt") |
| 347 | call term_sendkeys(buf, "\<C-E>j") |
Bram Moolenaar | db4d88c | 2022-12-31 15:13:22 +0000 | [diff] [blame] | 348 | call VerifyScreenDump(buf, 'Test_smooth_long_15', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 349 | |
Bram Moolenaar | 8cf3459 | 2022-10-08 21:13:40 +0100 | [diff] [blame] | 350 | call StopVimInTerminal(buf) |
| 351 | endfunc |
| 352 | |
Bram Moolenaar | 2fbabd2 | 2022-10-12 19:53:38 +0100 | [diff] [blame] | 353 | func Test_smoothscroll_one_long_line() |
| 354 | CheckScreendump |
| 355 | |
| 356 | let lines =<< trim END |
| 357 | vim9script |
| 358 | setline(1, 'with lots of text '->repeat(7)) |
| 359 | set smoothscroll scrolloff=0 |
| 360 | END |
| 361 | call writefile(lines, 'XSmoothOneLong', 'D') |
| 362 | let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40}) |
| 363 | call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 364 | |
Bram Moolenaar | 2fbabd2 | 2022-10-12 19:53:38 +0100 | [diff] [blame] | 365 | call term_sendkeys(buf, "\<C-E>") |
| 366 | call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {}) |
| 367 | |
| 368 | call term_sendkeys(buf, "0") |
| 369 | call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {}) |
| 370 | |
| 371 | call StopVimInTerminal(buf) |
| 372 | endfunc |
| 373 | |
Bram Moolenaar | 75ac25b | 2022-11-17 19:00:14 +0000 | [diff] [blame] | 374 | func Test_smoothscroll_long_line_showbreak() |
| 375 | CheckScreendump |
| 376 | |
| 377 | let lines =<< trim END |
| 378 | vim9script |
| 379 | # a line that spans four screen lines |
| 380 | setline(1, 'with lots of text in one line '->repeat(6)) |
| 381 | set smoothscroll scrolloff=0 showbreak=+++\ |
| 382 | END |
| 383 | call writefile(lines, 'XSmoothLongShowbreak', 'D') |
| 384 | let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40}) |
| 385 | call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 386 | |
Bram Moolenaar | 75ac25b | 2022-11-17 19:00:14 +0000 | [diff] [blame] | 387 | call term_sendkeys(buf, "\<C-E>") |
| 388 | call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {}) |
| 389 | |
| 390 | call term_sendkeys(buf, "0") |
| 391 | call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {}) |
| 392 | |
| 393 | call StopVimInTerminal(buf) |
| 394 | endfunc |
| 395 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 396 | func s:check_col_calc(win_col, win_line, buf_col) |
| 397 | call assert_equal(a:win_col, wincol()) |
| 398 | call assert_equal(a:win_line, winline()) |
| 399 | call assert_equal(a:buf_col, col('.')) |
| 400 | endfunc |
| 401 | |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 402 | " Test that if the current cursor is on a smooth scrolled line, we correctly |
| 403 | " reposition it. Also check that we don't miscalculate the values by checking |
| 404 | " the consistency between wincol() and col('.') as they are calculated |
| 405 | " separately in code. |
| 406 | func Test_smoothscroll_cursor_position() |
| 407 | call NewWindow(10, 20) |
| 408 | setl smoothscroll wrap |
| 409 | call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") |
| 410 | |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 411 | call s:check_col_calc(1, 1, 1) |
| 412 | exe "normal \<C-E>" |
| 413 | |
| 414 | " Move down another line to avoid blocking the <<< display |
| 415 | call s:check_col_calc(1, 2, 41) |
| 416 | exe "normal \<C-Y>" |
| 417 | call s:check_col_calc(1, 3, 41) |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 418 | |
| 419 | normal gg3l |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 420 | exe "normal \<C-E>" |
| 421 | |
| 422 | " Move down only 1 line when we are out of the range of the <<< display |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 423 | call s:check_col_calc(4, 1, 24) |
| 424 | exe "normal \<C-Y>" |
| 425 | call s:check_col_calc(4, 2, 24) |
| 426 | normal ggg$ |
| 427 | exe "normal \<C-E>" |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 428 | call s:check_col_calc(20, 1, 40) |
| 429 | exe "normal \<C-Y>" |
| 430 | call s:check_col_calc(20, 2, 40) |
| 431 | normal gg |
| 432 | |
| 433 | " Test number, where we have indented lines |
| 434 | setl number |
| 435 | call s:check_col_calc(5, 1, 1) |
| 436 | exe "normal \<C-E>" |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 437 | |
| 438 | " Move down only 1 line when the <<< display is on the number column |
| 439 | call s:check_col_calc(5, 1, 17) |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 440 | exe "normal \<C-Y>" |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 441 | call s:check_col_calc(5, 2, 17) |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 442 | normal ggg$ |
| 443 | exe "normal \<C-E>" |
| 444 | call s:check_col_calc(20, 1, 32) |
| 445 | exe "normal \<C-Y>" |
| 446 | call s:check_col_calc(20, 2, 32) |
| 447 | normal gg |
| 448 | |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 449 | setl numberwidth=1 |
| 450 | |
| 451 | " Move down another line when numberwidth is too short to cover the whole |
| 452 | " <<< display |
| 453 | call s:check_col_calc(3, 1, 1) |
| 454 | exe "normal \<C-E>" |
| 455 | call s:check_col_calc(3, 2, 37) |
| 456 | exe "normal \<C-Y>" |
| 457 | call s:check_col_calc(3, 3, 37) |
| 458 | normal ggl |
| 459 | |
| 460 | " Only move 1 line down when we are just past the <<< display |
| 461 | call s:check_col_calc(4, 1, 2) |
| 462 | exe "normal \<C-E>" |
| 463 | call s:check_col_calc(4, 1, 20) |
| 464 | exe "normal \<C-Y>" |
| 465 | call s:check_col_calc(4, 2, 20) |
| 466 | normal gg |
| 467 | setl numberwidth& |
| 468 | |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 469 | " Test number + showbreak, so test that the additional indentation works |
| 470 | setl number showbreak=+++ |
| 471 | call s:check_col_calc(5, 1, 1) |
| 472 | exe "normal \<C-E>" |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 473 | call s:check_col_calc(8, 1, 17) |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 474 | exe "normal \<C-Y>" |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 475 | call s:check_col_calc(8, 2, 17) |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 476 | normal gg |
| 477 | |
| 478 | " Test number + cpo+=n mode, where wrapped lines aren't indented |
| 479 | setl number cpo+=n showbreak= |
| 480 | call s:check_col_calc(5, 1, 1) |
| 481 | exe "normal \<C-E>" |
| 482 | call s:check_col_calc(1, 2, 37) |
| 483 | exe "normal \<C-Y>" |
| 484 | call s:check_col_calc(1, 3, 37) |
| 485 | normal gg |
| 486 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 487 | bwipe! |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 488 | endfunc |
| 489 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 490 | func Test_smoothscroll_cursor_scrolloff() |
| 491 | call NewWindow(10, 20) |
| 492 | setl smoothscroll wrap |
| 493 | setl scrolloff=3 |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 494 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 495 | " 120 chars are 6 screen lines |
| 496 | call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST") |
| 497 | call setline(2, "below") |
| 498 | |
| 499 | call s:check_col_calc(1, 1, 1) |
| 500 | |
| 501 | " CTRL-E shows "<<<DEFG...", cursor move four lines down |
| 502 | exe "normal \<C-E>" |
| 503 | call s:check_col_calc(1, 4, 81) |
| 504 | |
| 505 | " cursor on start of second line, "gk" moves into first line, skipcol doesn't |
| 506 | " change |
| 507 | exe "normal G0gk" |
| 508 | call s:check_col_calc(1, 5, 101) |
| 509 | |
| 510 | " move cursor left one window width worth, scrolls one screen line |
| 511 | exe "normal 20h" |
| 512 | call s:check_col_calc(1, 5, 81) |
| 513 | |
| 514 | " move cursor left one window width worth, scrolls one screen line |
| 515 | exe "normal 20h" |
| 516 | call s:check_col_calc(1, 4, 61) |
| 517 | |
Bram Moolenaar | b21b8e9 | 2022-12-03 18:35:07 +0000 | [diff] [blame] | 518 | " cursor on last line, "gk" should not cause a scroll |
| 519 | set scrolloff=0 |
| 520 | normal G0 |
| 521 | call s:check_col_calc(1, 7, 1) |
| 522 | normal gk |
| 523 | call s:check_col_calc(1, 6, 101) |
| 524 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 525 | bwipe! |
| 526 | endfunc |
| 527 | |
| 528 | |
Yee Cheng Chin | e6392b1 | 2022-11-19 14:31:08 +0000 | [diff] [blame] | 529 | " Test that mouse picking is still accurate when we have smooth scrolled lines |
| 530 | func Test_smoothscroll_mouse_pos() |
| 531 | CheckNotGui |
| 532 | CheckUnix |
| 533 | |
| 534 | let save_mouse = &mouse |
| 535 | let save_term = &term |
| 536 | let save_ttymouse = &ttymouse |
| 537 | set mouse=a term=xterm ttymouse=xterm2 |
| 538 | |
| 539 | call NewWindow(10, 20) |
| 540 | setl smoothscroll wrap |
| 541 | " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines. |
| 542 | call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"]) |
| 543 | |
| 544 | func s:check_mouse_click(row, col, buf_row, buf_col) |
| 545 | call MouseLeftClick(a:row, a:col) |
| 546 | |
| 547 | call assert_equal(a:col, wincol()) |
| 548 | call assert_equal(a:row, winline()) |
| 549 | call assert_equal(a:buf_row, line('.')) |
| 550 | call assert_equal(a:buf_col, col('.')) |
| 551 | endfunc |
| 552 | |
| 553 | " Check that clicking without scroll works first. |
| 554 | call s:check_mouse_click(3, 5, 1, 45) |
| 555 | call s:check_mouse_click(4, 1, 2, 1) |
| 556 | call s:check_mouse_click(4, 6, 2, 6) |
| 557 | call s:check_mouse_click(5, 1, 3, 1) |
| 558 | call s:check_mouse_click(5, 6, 3, 6) |
| 559 | |
| 560 | " Smooth scroll, and checks that this didn't mess up mouse clicking |
| 561 | exe "normal \<C-E>" |
| 562 | call s:check_mouse_click(2, 5, 1, 45) |
| 563 | call s:check_mouse_click(3, 1, 2, 1) |
| 564 | call s:check_mouse_click(3, 6, 2, 6) |
| 565 | call s:check_mouse_click(4, 1, 3, 1) |
| 566 | call s:check_mouse_click(4, 6, 3, 6) |
| 567 | |
| 568 | exe "normal \<C-E>" |
| 569 | call s:check_mouse_click(1, 5, 1, 45) |
| 570 | call s:check_mouse_click(2, 1, 2, 1) |
| 571 | call s:check_mouse_click(2, 6, 2, 6) |
| 572 | call s:check_mouse_click(3, 1, 3, 1) |
| 573 | call s:check_mouse_click(3, 6, 3, 6) |
| 574 | |
| 575 | " Make a new first line 11 physical lines tall so it's taller than window |
| 576 | " height, to test overflow calculations with really long lines wrapping. |
| 577 | normal gg |
| 578 | call setline(1, "12345678901234567890"->repeat(11)) |
| 579 | exe "normal 6\<C-E>" |
| 580 | call s:check_mouse_click(5, 1, 1, 201) |
| 581 | call s:check_mouse_click(6, 1, 2, 1) |
| 582 | call s:check_mouse_click(7, 1, 3, 1) |
| 583 | |
| 584 | let &mouse = save_mouse |
| 585 | let &term = save_term |
| 586 | let &ttymouse = save_ttymouse |
| 587 | endfunc |
| 588 | |
Bram Moolenaar | 870219c | 2023-01-26 14:14:43 +0000 | [diff] [blame] | 589 | " this was dividing by zero |
Luuk van Baal | c8502f9 | 2023-05-06 12:40:15 +0100 | [diff] [blame] | 590 | func Test_smoothscroll_zero_width() |
Bram Moolenaar | 870219c | 2023-01-26 14:14:43 +0000 | [diff] [blame] | 591 | CheckScreendump |
| 592 | |
| 593 | let lines =<< trim END |
| 594 | winsize 0 0 |
| 595 | vsplit |
| 596 | vsplit |
| 597 | vsplit |
| 598 | vsplit |
| 599 | vsplit |
| 600 | sil norm H |
| 601 | set wrap |
| 602 | set smoothscroll |
| 603 | set number |
| 604 | END |
| 605 | call writefile(lines, 'XSmoothScrollZero', 'D') |
| 606 | let buf = RunVimInTerminal('-u NONE -i NONE -n -m -X -Z -e -s -S XSmoothScrollZero', #{rows: 6, cols: 60, wait_for_ruler: 0}) |
Bram Moolenaar | 870219c | 2023-01-26 14:14:43 +0000 | [diff] [blame] | 607 | call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {}) |
| 608 | |
| 609 | call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>") |
| 610 | call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {}) |
| 611 | |
| 612 | call StopVimInTerminal(buf) |
| 613 | endfunc |
| 614 | |
Luuk van Baal | c8502f9 | 2023-05-06 12:40:15 +0100 | [diff] [blame] | 615 | " this was unnecessarily inserting lines |
| 616 | func Test_smoothscroll_ins_lines() |
| 617 | CheckScreendump |
| 618 | |
| 619 | let lines =<< trim END |
| 620 | set wrap |
| 621 | set smoothscroll |
| 622 | set scrolloff=0 |
| 623 | set conceallevel=2 |
| 624 | call setline(1, [ |
| 625 | \'line one' .. 'with lots of text in one line '->repeat(2), |
| 626 | \'line two', |
| 627 | \'line three', |
| 628 | \'line four', |
| 629 | \'line five' |
| 630 | \]) |
| 631 | END |
| 632 | call writefile(lines, 'XSmoothScrollInsLines', 'D') |
| 633 | let buf = RunVimInTerminal('-S XSmoothScrollInsLines', #{rows: 6, cols: 40}) |
| 634 | |
| 635 | call term_sendkeys(buf, "\<C-E>gjgk") |
| 636 | call VerifyScreenDump(buf, 'Test_smooth_ins_lines', {}) |
| 637 | |
| 638 | call StopVimInTerminal(buf) |
| 639 | endfunc |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 640 | |
Luuk van Baal | 3ce8c38 | 2023-05-08 15:51:14 +0100 | [diff] [blame] | 641 | " this placed the cursor in the command line |
| 642 | func Test_smoothscroll_cursormoved_line() |
| 643 | CheckScreendump |
| 644 | |
| 645 | let lines =<< trim END |
| 646 | set smoothscroll |
| 647 | call setline(1, [ |
| 648 | \'', |
| 649 | \'_'->repeat(&lines * &columns), |
| 650 | \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2) |
| 651 | \]) |
| 652 | autocmd CursorMoved * eval [line('w0'), line('w$')] |
| 653 | call search('xxx') |
| 654 | END |
| 655 | call writefile(lines, 'XSmoothCursorMovedLine', 'D') |
| 656 | let buf = RunVimInTerminal('-S XSmoothCursorMovedLine', #{rows: 6}) |
| 657 | |
| 658 | call VerifyScreenDump(buf, 'Test_smooth_cursormoved_line', {}) |
| 659 | |
| 660 | call StopVimInTerminal(buf) |
| 661 | endfunc |
| 662 | |
| 663 | func Test_smoothscroll_eob() |
| 664 | CheckScreendump |
| 665 | |
| 666 | let lines =<< trim END |
| 667 | set smoothscroll |
| 668 | call setline(1, ['']->repeat(100)) |
| 669 | norm G |
| 670 | END |
| 671 | call writefile(lines, 'XSmoothEob', 'D') |
| 672 | let buf = RunVimInTerminal('-S XSmoothEob', #{rows: 10}) |
| 673 | |
| 674 | " does not scroll halfway when scrolling to end of buffer |
| 675 | call VerifyScreenDump(buf, 'Test_smooth_eob_1', {}) |
| 676 | |
| 677 | " cursor is not placed below window |
| 678 | call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\<CR>\<C-B>G") |
| 679 | call VerifyScreenDump(buf, 'Test_smooth_eob_2', {}) |
| 680 | |
| 681 | call StopVimInTerminal(buf) |
| 682 | endfunc |
| 683 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 684 | " vim: shiftwidth=2 sts=2 expandtab |