zeertzjq | 8e5f26e | 2023-10-04 21:45:33 +0200 | [diff] [blame] | 1 | " Test for 'scroll', 'scrolloff', 'smoothscroll', etc. |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 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() |
zeertzjq | 8e5f26e | 2023-10-04 21:45:33 +0200 | [diff] [blame] | 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) |
Bram Moolenaar | 1d6539c | 2023-02-14 17:41:20 +0000 | [diff] [blame] | 54 | |
zeertzjq | 8e5f26e | 2023-10-04 21:45:33 +0200 | [diff] [blame] | 55 | bwipe! |
| 56 | endfunc |
| 57 | |
| 58 | func Test_mouse_scroll_inactive_with_cursorbind() |
| 59 | for scb in [0, 1] |
| 60 | for so in [0, 1, 2] |
| 61 | let msg = $'scb={scb} so={so}' |
| 62 | |
| 63 | new | only |
| 64 | let w1 = win_getid() |
| 65 | setlocal cursorbind |
| 66 | let &l:scb = scb |
| 67 | let &l:so = so |
| 68 | call setline(1, range(101, 109)) |
| 69 | rightbelow vnew |
| 70 | let w2 = win_getid() |
| 71 | setlocal cursorbind |
| 72 | let &l:scb = scb |
| 73 | let &l:so = so |
| 74 | call setline(1, range(101, 109)) |
| 75 | |
| 76 | normal! $ |
| 77 | call assert_equal(3, col('.', w1), msg) |
| 78 | call assert_equal(3, col('.', w2), msg) |
| 79 | call test_setmouse(1, 1) |
| 80 | call feedkeys("\<ScrollWheelDown>", 'xt') |
| 81 | call assert_equal(4, line('w0', w1), msg) |
| 82 | call assert_equal(4 + so, line('.', w1), msg) |
| 83 | call assert_equal(1, line('w0', w2), msg) |
| 84 | call assert_equal(1, line('.', w2), msg) |
| 85 | call feedkeys("\<ScrollWheelDown>", 'xt') |
| 86 | call assert_equal(7, line('w0', w1), msg) |
| 87 | call assert_equal(7 + so, line('.', w1), msg) |
| 88 | call assert_equal(1, line('w0', w2), msg) |
| 89 | call assert_equal(1, line('.', w2), msg) |
| 90 | call feedkeys("\<ScrollWheelUp>", 'xt') |
| 91 | call assert_equal(4, line('w0', w1), msg) |
| 92 | call assert_equal(7 + so, line('.', w1), msg) |
| 93 | call assert_equal(1, line('w0', w2), msg) |
| 94 | call assert_equal(1, line('.', w2), msg) |
| 95 | call feedkeys("\<ScrollWheelUp>", 'xt') |
| 96 | call assert_equal(1, line('w0', w1), msg) |
| 97 | call assert_equal(7 + so, line('.', w1), msg) |
| 98 | call assert_equal(1, line('w0', w2), msg) |
| 99 | call assert_equal(1, line('.', w2), msg) |
| 100 | normal! 0 |
| 101 | call assert_equal(1, line('.', w1), msg) |
| 102 | call assert_equal(1, col('.', w1), msg) |
| 103 | call assert_equal(1, line('.', w2), msg) |
| 104 | call assert_equal(1, col('.', w2), msg) |
| 105 | |
| 106 | bwipe! |
| 107 | bwipe! |
| 108 | endfor |
| 109 | endfor |
Bram Moolenaar | 1d6539c | 2023-02-14 17:41:20 +0000 | [diff] [blame] | 110 | endfunc |
| 111 | |
Bram Moolenaar | 8df9748 | 2022-10-03 12:11:13 +0100 | [diff] [blame] | 112 | func Test_CtrlE_CtrlY_stop_at_end() |
| 113 | enew |
| 114 | call setline(1, ['one', 'two']) |
| 115 | set number |
| 116 | exe "normal \<C-Y>" |
| 117 | call assert_equal([" 1 one "], ScreenLines(1, 10)) |
| 118 | exe "normal \<C-E>\<C-E>\<C-E>" |
| 119 | call assert_equal([" 2 two "], ScreenLines(1, 10)) |
| 120 | |
| 121 | bwipe! |
| 122 | set nonumber |
| 123 | endfunc |
| 124 | |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 125 | func Test_smoothscroll_CtrlE_CtrlY() |
| 126 | CheckScreendump |
| 127 | |
| 128 | let lines =<< trim END |
| 129 | vim9script |
| 130 | setline(1, [ |
| 131 | 'line one', |
| 132 | 'word '->repeat(20), |
| 133 | 'line three', |
| 134 | 'long word '->repeat(7), |
| 135 | 'line', |
| 136 | 'line', |
| 137 | 'line', |
| 138 | ]) |
| 139 | set smoothscroll |
| 140 | :5 |
| 141 | END |
| 142 | call writefile(lines, 'XSmoothScroll', 'D') |
| 143 | let buf = RunVimInTerminal('-S XSmoothScroll', #{rows: 12, cols: 40}) |
| 144 | |
| 145 | call term_sendkeys(buf, "\<C-E>") |
| 146 | call VerifyScreenDump(buf, 'Test_smoothscroll_1', {}) |
| 147 | call term_sendkeys(buf, "\<C-E>") |
| 148 | call VerifyScreenDump(buf, 'Test_smoothscroll_2', {}) |
| 149 | call term_sendkeys(buf, "\<C-E>") |
| 150 | call VerifyScreenDump(buf, 'Test_smoothscroll_3', {}) |
| 151 | call term_sendkeys(buf, "\<C-E>") |
| 152 | call VerifyScreenDump(buf, 'Test_smoothscroll_4', {}) |
| 153 | |
| 154 | call term_sendkeys(buf, "\<C-Y>") |
| 155 | call VerifyScreenDump(buf, 'Test_smoothscroll_5', {}) |
| 156 | call term_sendkeys(buf, "\<C-Y>") |
| 157 | call VerifyScreenDump(buf, 'Test_smoothscroll_6', {}) |
| 158 | call term_sendkeys(buf, "\<C-Y>") |
| 159 | call VerifyScreenDump(buf, 'Test_smoothscroll_7', {}) |
| 160 | call term_sendkeys(buf, "\<C-Y>") |
| 161 | call VerifyScreenDump(buf, 'Test_smoothscroll_8', {}) |
| 162 | |
Bram Moolenaar | 6b2d4ff | 2022-10-03 14:06:02 +0100 | [diff] [blame] | 163 | if has('folding') |
| 164 | call term_sendkeys(buf, ":set foldmethod=indent\<CR>") |
| 165 | " move the cursor so we can reuse the same dumps |
| 166 | call term_sendkeys(buf, "5G") |
| 167 | call term_sendkeys(buf, "\<C-E>") |
| 168 | call VerifyScreenDump(buf, 'Test_smoothscroll_1', {}) |
| 169 | call term_sendkeys(buf, "\<C-E>") |
| 170 | call VerifyScreenDump(buf, 'Test_smoothscroll_2', {}) |
| 171 | call term_sendkeys(buf, "7G") |
| 172 | call term_sendkeys(buf, "\<C-Y>") |
| 173 | call VerifyScreenDump(buf, 'Test_smoothscroll_7', {}) |
| 174 | call term_sendkeys(buf, "\<C-Y>") |
| 175 | call VerifyScreenDump(buf, 'Test_smoothscroll_8', {}) |
| 176 | endif |
| 177 | |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 178 | call StopVimInTerminal(buf) |
| 179 | endfunc |
| 180 | |
Bram Moolenaar | 15d4747 | 2023-06-05 20:44:55 +0100 | [diff] [blame] | 181 | func Test_smoothscroll_multibyte() |
| 182 | CheckScreendump |
| 183 | |
| 184 | let lines =<< trim END |
| 185 | set scrolloff=0 smoothscroll |
| 186 | call setline(1, [repeat('ϛ', 45), repeat('2', 36)]) |
| 187 | exe "normal G35l\<C-E>k" |
| 188 | END |
| 189 | call writefile(lines, 'XSmoothMultibyte', 'D') |
| 190 | let buf = RunVimInTerminal('-S XSmoothMultibyte', #{rows: 6, cols: 40}) |
| 191 | call VerifyScreenDump(buf, 'Test_smoothscroll_multi_1', {}) |
| 192 | |
| 193 | call StopVimInTerminal(buf) |
| 194 | endfunc |
| 195 | |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 196 | func Test_smoothscroll_number() |
| 197 | CheckScreendump |
| 198 | |
| 199 | let lines =<< trim END |
| 200 | vim9script |
| 201 | setline(1, [ |
| 202 | 'one ' .. 'word '->repeat(20), |
| 203 | 'two ' .. 'long word '->repeat(7), |
| 204 | 'line', |
| 205 | 'line', |
| 206 | 'line', |
| 207 | ]) |
| 208 | set smoothscroll |
zeertzjq | 88bb3e0 | 2023-05-02 20:52:59 +0100 | [diff] [blame] | 209 | set splitkeep=topline |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 210 | set number cpo+=n |
| 211 | :3 |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 212 | |
| 213 | def g:DoRel() |
| 214 | set number relativenumber scrolloff=0 |
| 215 | :%del |
| 216 | setline(1, [ |
| 217 | 'one', |
| 218 | 'very long text '->repeat(12), |
| 219 | 'three', |
| 220 | ]) |
| 221 | exe "normal 2Gzt\<C-E>" |
| 222 | enddef |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 223 | END |
| 224 | call writefile(lines, 'XSmoothNumber', 'D') |
| 225 | let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40}) |
| 226 | |
| 227 | call VerifyScreenDump(buf, 'Test_smooth_number_1', {}) |
| 228 | call term_sendkeys(buf, "\<C-E>") |
| 229 | call VerifyScreenDump(buf, 'Test_smooth_number_2', {}) |
| 230 | call term_sendkeys(buf, "\<C-E>") |
| 231 | call VerifyScreenDump(buf, 'Test_smooth_number_3', {}) |
| 232 | |
| 233 | call term_sendkeys(buf, ":set cpo-=n\<CR>") |
| 234 | call VerifyScreenDump(buf, 'Test_smooth_number_4', {}) |
| 235 | call term_sendkeys(buf, "\<C-Y>") |
| 236 | call VerifyScreenDump(buf, 'Test_smooth_number_5', {}) |
| 237 | call term_sendkeys(buf, "\<C-Y>") |
| 238 | call VerifyScreenDump(buf, 'Test_smooth_number_6', {}) |
| 239 | |
zeertzjq | 88bb3e0 | 2023-05-02 20:52:59 +0100 | [diff] [blame] | 240 | call term_sendkeys(buf, ":botright split\<CR>gg") |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 241 | call VerifyScreenDump(buf, 'Test_smooth_number_7', {}) |
zeertzjq | 88bb3e0 | 2023-05-02 20:52:59 +0100 | [diff] [blame] | 242 | call term_sendkeys(buf, "\<C-E>") |
| 243 | call VerifyScreenDump(buf, 'Test_smooth_number_8', {}) |
| 244 | call term_sendkeys(buf, "\<C-E>") |
| 245 | call VerifyScreenDump(buf, 'Test_smooth_number_9', {}) |
| 246 | call term_sendkeys(buf, ":close\<CR>") |
| 247 | |
| 248 | call term_sendkeys(buf, ":call DoRel()\<CR>") |
| 249 | call VerifyScreenDump(buf, 'Test_smooth_number_10', {}) |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 250 | |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 251 | call StopVimInTerminal(buf) |
| 252 | endfunc |
| 253 | |
Bram Moolenaar | 13cdde3 | 2022-10-15 14:07:48 +0100 | [diff] [blame] | 254 | func Test_smoothscroll_list() |
| 255 | CheckScreendump |
| 256 | |
| 257 | let lines =<< trim END |
| 258 | vim9script |
| 259 | set smoothscroll scrolloff=0 |
| 260 | set list |
| 261 | setline(1, [ |
| 262 | 'one', |
| 263 | 'very long text '->repeat(12), |
| 264 | 'three', |
| 265 | ]) |
| 266 | exe "normal 2Gzt\<C-E>" |
| 267 | END |
| 268 | call writefile(lines, 'XSmoothList', 'D') |
| 269 | let buf = RunVimInTerminal('-S XSmoothList', #{rows: 8, cols: 40}) |
| 270 | |
| 271 | call VerifyScreenDump(buf, 'Test_smooth_list_1', {}) |
| 272 | |
| 273 | call term_sendkeys(buf, ":set listchars+=precedes:#\<CR>") |
| 274 | call VerifyScreenDump(buf, 'Test_smooth_list_2', {}) |
| 275 | |
| 276 | call StopVimInTerminal(buf) |
| 277 | endfunc |
| 278 | |
Bram Moolenaar | 1a58e1d | 2022-10-06 13:09:17 +0100 | [diff] [blame] | 279 | func Test_smoothscroll_diff_mode() |
| 280 | CheckScreendump |
| 281 | |
| 282 | let lines =<< trim END |
| 283 | vim9script |
| 284 | var text = 'just some text here' |
| 285 | setline(1, text) |
| 286 | set smoothscroll |
| 287 | diffthis |
| 288 | new |
| 289 | setline(1, text) |
| 290 | set smoothscroll |
| 291 | diffthis |
| 292 | END |
| 293 | call writefile(lines, 'XSmoothDiff', 'D') |
| 294 | let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8}) |
| 295 | |
| 296 | call VerifyScreenDump(buf, 'Test_smooth_diff_1', {}) |
| 297 | call term_sendkeys(buf, "\<C-Y>") |
| 298 | call VerifyScreenDump(buf, 'Test_smooth_diff_1', {}) |
| 299 | call term_sendkeys(buf, "\<C-E>") |
| 300 | call VerifyScreenDump(buf, 'Test_smooth_diff_1', {}) |
| 301 | |
| 302 | call StopVimInTerminal(buf) |
| 303 | endfunc |
| 304 | |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 305 | func Test_smoothscroll_wrap_scrolloff_zero() |
| 306 | CheckScreendump |
| 307 | |
| 308 | let lines =<< trim END |
| 309 | vim9script |
| 310 | setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7)) |
| 311 | set smoothscroll scrolloff=0 |
| 312 | :3 |
| 313 | END |
| 314 | call writefile(lines, 'XSmoothWrap', 'D') |
| 315 | let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40}) |
| 316 | |
| 317 | call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {}) |
| 318 | |
Bram Moolenaar | 46b5474 | 2022-10-06 15:46:49 +0100 | [diff] [blame] | 319 | " moving cursor down - whole bottom line shows |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 320 | call term_sendkeys(buf, "j") |
| 321 | call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {}) |
| 322 | |
| 323 | call term_sendkeys(buf, "\<C-E>j") |
| 324 | call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {}) |
| 325 | |
| 326 | call term_sendkeys(buf, "G") |
| 327 | call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {}) |
| 328 | |
Luuk van Baal | d49f646 | 2023-05-19 14:04:47 +0100 | [diff] [blame] | 329 | call term_sendkeys(buf, "4\<C-Y>G") |
| 330 | call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {}) |
| 331 | |
| 332 | " moving cursor up right after the <<< marker - no need to show whole line |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 333 | call term_sendkeys(buf, "2gj3l2k") |
Bram Moolenaar | 46b5474 | 2022-10-06 15:46:49 +0100 | [diff] [blame] | 334 | call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {}) |
| 335 | |
Luuk van Baal | d49f646 | 2023-05-19 14:04:47 +0100 | [diff] [blame] | 336 | " moving cursor up where the <<< marker is - whole top line shows |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 337 | call term_sendkeys(buf, "2j02k") |
| 338 | call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {}) |
| 339 | |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 340 | call StopVimInTerminal(buf) |
| 341 | endfunc |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 342 | |
Bram Moolenaar | 8cf3459 | 2022-10-08 21:13:40 +0100 | [diff] [blame] | 343 | func Test_smoothscroll_wrap_long_line() |
| 344 | CheckScreendump |
| 345 | |
| 346 | let lines =<< trim END |
| 347 | vim9script |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 348 | 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] | 349 | set smoothscroll scrolloff=0 |
| 350 | normal 3G10|zt |
| 351 | END |
| 352 | call writefile(lines, 'XSmoothWrap', 'D') |
| 353 | let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40}) |
| 354 | call VerifyScreenDump(buf, 'Test_smooth_long_1', {}) |
| 355 | |
| 356 | " scrolling up, cursor moves screen line down |
| 357 | call term_sendkeys(buf, "\<C-E>") |
| 358 | call VerifyScreenDump(buf, 'Test_smooth_long_2', {}) |
| 359 | call term_sendkeys(buf, "5\<C-E>") |
| 360 | call VerifyScreenDump(buf, 'Test_smooth_long_3', {}) |
| 361 | |
| 362 | " scrolling down, cursor moves screen line up |
| 363 | call term_sendkeys(buf, "5\<C-Y>") |
| 364 | call VerifyScreenDump(buf, 'Test_smooth_long_4', {}) |
| 365 | call term_sendkeys(buf, "\<C-Y>") |
| 366 | call VerifyScreenDump(buf, 'Test_smooth_long_5', {}) |
| 367 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 368 | " 'scrolloff' set to 1, scrolling up, cursor moves screen line down |
| 369 | call term_sendkeys(buf, ":set scrolloff=1\<CR>") |
| 370 | call term_sendkeys(buf, "10|\<C-E>") |
| 371 | call VerifyScreenDump(buf, 'Test_smooth_long_6', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 372 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 373 | " 'scrolloff' set to 1, scrolling down, cursor moves screen line up |
| 374 | call term_sendkeys(buf, "\<C-E>") |
| 375 | call term_sendkeys(buf, "gjgj") |
| 376 | call term_sendkeys(buf, "\<C-Y>") |
| 377 | call VerifyScreenDump(buf, 'Test_smooth_long_7', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 378 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 379 | " 'scrolloff' set to 2, scrolling up, cursor moves screen line down |
| 380 | call term_sendkeys(buf, ":set scrolloff=2\<CR>") |
| 381 | call term_sendkeys(buf, "10|\<C-E>") |
| 382 | call VerifyScreenDump(buf, 'Test_smooth_long_8', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 383 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 384 | " 'scrolloff' set to 2, scrolling down, cursor moves screen line up |
| 385 | call term_sendkeys(buf, "\<C-E>") |
| 386 | call term_sendkeys(buf, "gj") |
| 387 | call term_sendkeys(buf, "\<C-Y>") |
| 388 | call VerifyScreenDump(buf, 'Test_smooth_long_9', {}) |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 389 | |
| 390 | " 'scrolloff' set to 0, move cursor down one line. |
| 391 | " Cursor should move properly, and since this is a really long line, it will |
| 392 | " be put on top of the screen. |
| 393 | call term_sendkeys(buf, ":set scrolloff=0\<CR>") |
| 394 | call term_sendkeys(buf, "0j") |
| 395 | call VerifyScreenDump(buf, 'Test_smooth_long_10', {}) |
| 396 | |
Bram Moolenaar | db4d88c | 2022-12-31 15:13:22 +0000 | [diff] [blame] | 397 | " Test zt/zz/zb that they work properly when a long line is above it |
Luuk van Baal | 6f37e53 | 2023-05-09 21:23:54 +0100 | [diff] [blame] | 398 | call term_sendkeys(buf, "zt") |
Bram Moolenaar | db4d88c | 2022-12-31 15:13:22 +0000 | [diff] [blame] | 399 | call VerifyScreenDump(buf, 'Test_smooth_long_11', {}) |
| 400 | call term_sendkeys(buf, "zz") |
| 401 | call VerifyScreenDump(buf, 'Test_smooth_long_12', {}) |
Luuk van Baal | 6f37e53 | 2023-05-09 21:23:54 +0100 | [diff] [blame] | 402 | call term_sendkeys(buf, "zb") |
Bram Moolenaar | db4d88c | 2022-12-31 15:13:22 +0000 | [diff] [blame] | 403 | call VerifyScreenDump(buf, 'Test_smooth_long_13', {}) |
| 404 | |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 405 | " Repeat the step and move the cursor down again. |
| 406 | " This time, use a shorter long line that is barely long enough to span more |
| 407 | " than one window. Note that the cursor is at the bottom this time because |
| 408 | " Vim prefers to do so if we are scrolling a few lines only. |
| 409 | call term_sendkeys(buf, ":call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(10)) .. ' end', 'four'])\<CR>") |
Luuk van Baal | 5d01f86 | 2023-05-11 19:24:20 +0100 | [diff] [blame] | 410 | " Currently visible lines were replaced, test that the lines and cursor |
| 411 | " are correctly displayed. |
| 412 | call VerifyScreenDump(buf, 'Test_smooth_long_14', {}) |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 413 | call term_sendkeys(buf, "3Gzt") |
| 414 | call term_sendkeys(buf, "j") |
Luuk van Baal | 5d01f86 | 2023-05-11 19:24:20 +0100 | [diff] [blame] | 415 | call VerifyScreenDump(buf, 'Test_smooth_long_15', {}) |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 416 | |
| 417 | " Repeat the step but this time start it when the line is smooth-scrolled by |
| 418 | " one line. This tests that the offset calculation is still correct and |
| 419 | " still end up scrolling down to the next line with cursor at bottom of |
| 420 | " screen. |
| 421 | call term_sendkeys(buf, "3Gzt") |
| 422 | call term_sendkeys(buf, "\<C-E>j") |
Luuk van Baal | 5d01f86 | 2023-05-11 19:24:20 +0100 | [diff] [blame] | 423 | call VerifyScreenDump(buf, 'Test_smooth_long_16', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 424 | |
Bram Moolenaar | 8cf3459 | 2022-10-08 21:13:40 +0100 | [diff] [blame] | 425 | call StopVimInTerminal(buf) |
| 426 | endfunc |
| 427 | |
Bram Moolenaar | 2fbabd2 | 2022-10-12 19:53:38 +0100 | [diff] [blame] | 428 | func Test_smoothscroll_one_long_line() |
| 429 | CheckScreendump |
| 430 | |
| 431 | let lines =<< trim END |
| 432 | vim9script |
| 433 | setline(1, 'with lots of text '->repeat(7)) |
| 434 | set smoothscroll scrolloff=0 |
| 435 | END |
| 436 | call writefile(lines, 'XSmoothOneLong', 'D') |
| 437 | let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40}) |
| 438 | call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 439 | |
Bram Moolenaar | 2fbabd2 | 2022-10-12 19:53:38 +0100 | [diff] [blame] | 440 | call term_sendkeys(buf, "\<C-E>") |
| 441 | call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {}) |
| 442 | |
| 443 | call term_sendkeys(buf, "0") |
| 444 | call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {}) |
| 445 | |
| 446 | call StopVimInTerminal(buf) |
| 447 | endfunc |
| 448 | |
Bram Moolenaar | 75ac25b | 2022-11-17 19:00:14 +0000 | [diff] [blame] | 449 | func Test_smoothscroll_long_line_showbreak() |
| 450 | CheckScreendump |
| 451 | |
| 452 | let lines =<< trim END |
| 453 | vim9script |
| 454 | # a line that spans four screen lines |
| 455 | setline(1, 'with lots of text in one line '->repeat(6)) |
| 456 | set smoothscroll scrolloff=0 showbreak=+++\ |
| 457 | END |
| 458 | call writefile(lines, 'XSmoothLongShowbreak', 'D') |
| 459 | let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40}) |
| 460 | call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 461 | |
Bram Moolenaar | 75ac25b | 2022-11-17 19:00:14 +0000 | [diff] [blame] | 462 | call term_sendkeys(buf, "\<C-E>") |
| 463 | call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {}) |
| 464 | |
| 465 | call term_sendkeys(buf, "0") |
| 466 | call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {}) |
| 467 | |
| 468 | call StopVimInTerminal(buf) |
| 469 | endfunc |
| 470 | |
zeertzjq | ecb87dd | 2023-06-03 19:45:06 +0100 | [diff] [blame] | 471 | " Check that 'smoothscroll' marker is drawn over double-width char correctly. |
| 472 | " Run with multiple encodings. |
| 473 | func Test_smoothscroll_marker_over_double_width() |
| 474 | " Run this in a separate Vim instance to avoid messing up. |
| 475 | let after =<< trim [CODE] |
| 476 | scriptencoding utf-8 |
| 477 | call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10)) |
| 478 | setlocal smoothscroll |
| 479 | redraw |
| 480 | exe "norm \<C-E>" |
| 481 | redraw |
| 482 | " Check the chars one by one. Don't check the whole line concatenated. |
| 483 | call assert_equal('<', screenstring(1, 1)) |
| 484 | call assert_equal('<', screenstring(1, 2)) |
| 485 | call assert_equal('<', screenstring(1, 3)) |
| 486 | call assert_equal(' ', screenstring(1, 4)) |
| 487 | call assert_equal('口', screenstring(1, 5)) |
| 488 | call assert_equal('口', screenstring(1, 7)) |
| 489 | call assert_equal('口', screenstring(1, 9)) |
| 490 | call assert_equal('口', screenstring(1, 11)) |
| 491 | call assert_equal('口', screenstring(1, 13)) |
| 492 | call assert_equal('口', screenstring(1, 15)) |
| 493 | call writefile(v:errors, 'Xresult') |
| 494 | qall! |
| 495 | [CODE] |
| 496 | |
| 497 | let encodings = ['utf-8', 'cp932', 'cp936', 'cp949', 'cp950'] |
| 498 | if !has('win32') |
| 499 | let encodings += ['euc-jp'] |
| 500 | endif |
| 501 | for enc in encodings |
| 502 | let msg = 'enc=' .. enc |
| 503 | if RunVim([], after, $'--clean --cmd "set encoding={enc}"') |
| 504 | call assert_equal([], readfile('Xresult'), msg) |
| 505 | endif |
| 506 | call delete('Xresult') |
| 507 | endfor |
| 508 | endfunc |
| 509 | |
| 510 | " Same as the test above, but check the text actually shown on screen. |
| 511 | " Only run with UTF-8 encoding. |
| 512 | func Test_smoothscroll_marker_over_double_width_dump() |
| 513 | CheckScreendump |
| 514 | |
| 515 | let lines =<< trim END |
| 516 | call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10)) |
| 517 | setlocal smoothscroll |
| 518 | END |
| 519 | call writefile(lines, 'XSmoothMarkerOverDoubleWidth', 'D') |
| 520 | let buf = RunVimInTerminal('-S XSmoothMarkerOverDoubleWidth', #{rows: 6, cols: 40}) |
| 521 | call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_1', {}) |
| 522 | |
| 523 | call term_sendkeys(buf, "\<C-E>") |
| 524 | call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_2', {}) |
| 525 | |
| 526 | call StopVimInTerminal(buf) |
| 527 | endfunc |
| 528 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 529 | func s:check_col_calc(win_col, win_line, buf_col) |
| 530 | call assert_equal(a:win_col, wincol()) |
| 531 | call assert_equal(a:win_line, winline()) |
| 532 | call assert_equal(a:buf_col, col('.')) |
| 533 | endfunc |
| 534 | |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 535 | " Test that if the current cursor is on a smooth scrolled line, we correctly |
| 536 | " reposition it. Also check that we don't miscalculate the values by checking |
| 537 | " the consistency between wincol() and col('.') as they are calculated |
| 538 | " separately in code. |
| 539 | func Test_smoothscroll_cursor_position() |
| 540 | call NewWindow(10, 20) |
| 541 | setl smoothscroll wrap |
| 542 | call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") |
| 543 | |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 544 | call s:check_col_calc(1, 1, 1) |
| 545 | exe "normal \<C-E>" |
| 546 | |
| 547 | " Move down another line to avoid blocking the <<< display |
| 548 | call s:check_col_calc(1, 2, 41) |
| 549 | exe "normal \<C-Y>" |
| 550 | call s:check_col_calc(1, 3, 41) |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 551 | |
Luuk van Baal | 8667a56 | 2023-05-12 15:47:25 +0100 | [diff] [blame] | 552 | " Test "g0/g<Home>" |
| 553 | exe "normal gg\<C-E>" |
| 554 | norm $gkg0 |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 555 | call s:check_col_calc(4, 1, 24) |
Luuk van Baal | 8667a56 | 2023-05-12 15:47:25 +0100 | [diff] [blame] | 556 | |
| 557 | " Test moving the cursor behind the <<< display with 'virtualedit' |
| 558 | set virtualedit=all |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 559 | exe "normal \<C-E>gkh" |
Luuk van Baal | 8667a56 | 2023-05-12 15:47:25 +0100 | [diff] [blame] | 560 | call s:check_col_calc(3, 2, 23) |
| 561 | set virtualedit& |
| 562 | |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 563 | normal gg3l |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 564 | exe "normal \<C-E>" |
| 565 | |
| 566 | " 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] | 567 | call s:check_col_calc(4, 1, 24) |
| 568 | exe "normal \<C-Y>" |
| 569 | call s:check_col_calc(4, 2, 24) |
| 570 | normal ggg$ |
| 571 | exe "normal \<C-E>" |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 572 | call s:check_col_calc(20, 1, 40) |
| 573 | exe "normal \<C-Y>" |
| 574 | call s:check_col_calc(20, 2, 40) |
| 575 | normal gg |
| 576 | |
| 577 | " Test number, where we have indented lines |
| 578 | setl number |
| 579 | call s:check_col_calc(5, 1, 1) |
| 580 | exe "normal \<C-E>" |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 581 | |
| 582 | " Move down only 1 line when the <<< display is on the number column |
| 583 | call s:check_col_calc(5, 1, 17) |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 584 | exe "normal \<C-Y>" |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 585 | call s:check_col_calc(5, 2, 17) |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 586 | normal ggg$ |
| 587 | exe "normal \<C-E>" |
| 588 | call s:check_col_calc(20, 1, 32) |
| 589 | exe "normal \<C-Y>" |
| 590 | call s:check_col_calc(20, 2, 32) |
| 591 | normal gg |
| 592 | |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 593 | setl numberwidth=1 |
| 594 | |
| 595 | " Move down another line when numberwidth is too short to cover the whole |
| 596 | " <<< display |
| 597 | call s:check_col_calc(3, 1, 1) |
| 598 | exe "normal \<C-E>" |
| 599 | call s:check_col_calc(3, 2, 37) |
| 600 | exe "normal \<C-Y>" |
| 601 | call s:check_col_calc(3, 3, 37) |
| 602 | normal ggl |
| 603 | |
| 604 | " Only move 1 line down when we are just past the <<< display |
| 605 | call s:check_col_calc(4, 1, 2) |
| 606 | exe "normal \<C-E>" |
| 607 | call s:check_col_calc(4, 1, 20) |
| 608 | exe "normal \<C-Y>" |
| 609 | call s:check_col_calc(4, 2, 20) |
| 610 | normal gg |
| 611 | setl numberwidth& |
| 612 | |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 613 | " Test number + showbreak, so test that the additional indentation works |
| 614 | setl number showbreak=+++ |
| 615 | call s:check_col_calc(5, 1, 1) |
| 616 | exe "normal \<C-E>" |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 617 | call s:check_col_calc(8, 1, 17) |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 618 | exe "normal \<C-Y>" |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 619 | call s:check_col_calc(8, 2, 17) |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 620 | normal gg |
| 621 | |
| 622 | " Test number + cpo+=n mode, where wrapped lines aren't indented |
| 623 | setl number cpo+=n showbreak= |
| 624 | call s:check_col_calc(5, 1, 1) |
| 625 | exe "normal \<C-E>" |
| 626 | call s:check_col_calc(1, 2, 37) |
| 627 | exe "normal \<C-Y>" |
| 628 | call s:check_col_calc(1, 3, 37) |
| 629 | normal gg |
| 630 | |
Luuk van Baal | 24b62ec | 2023-05-13 14:12:15 +0100 | [diff] [blame] | 631 | " Test list + listchars "precedes", where there is always 1 overlap |
| 632 | " regardless of number and cpo-=n. |
| 633 | setl number list listchars=precedes:< cpo-=n |
| 634 | call s:check_col_calc(5, 1, 1) |
Luuk van Baal | 798fa76 | 2023-05-15 18:17:43 +0100 | [diff] [blame] | 635 | exe "normal 3|\<C-E>h" |
Luuk van Baal | 24b62ec | 2023-05-13 14:12:15 +0100 | [diff] [blame] | 636 | call s:check_col_calc(6, 1, 18) |
| 637 | norm h |
| 638 | call s:check_col_calc(5, 2, 17) |
| 639 | normal gg |
| 640 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 641 | bwipe! |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 642 | endfunc |
| 643 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 644 | func Test_smoothscroll_cursor_scrolloff() |
| 645 | call NewWindow(10, 20) |
| 646 | setl smoothscroll wrap |
| 647 | setl scrolloff=3 |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 648 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 649 | " 120 chars are 6 screen lines |
| 650 | call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST") |
| 651 | call setline(2, "below") |
| 652 | |
| 653 | call s:check_col_calc(1, 1, 1) |
| 654 | |
| 655 | " CTRL-E shows "<<<DEFG...", cursor move four lines down |
| 656 | exe "normal \<C-E>" |
| 657 | call s:check_col_calc(1, 4, 81) |
| 658 | |
| 659 | " cursor on start of second line, "gk" moves into first line, skipcol doesn't |
| 660 | " change |
| 661 | exe "normal G0gk" |
| 662 | call s:check_col_calc(1, 5, 101) |
| 663 | |
| 664 | " move cursor left one window width worth, scrolls one screen line |
| 665 | exe "normal 20h" |
| 666 | call s:check_col_calc(1, 5, 81) |
| 667 | |
| 668 | " move cursor left one window width worth, scrolls one screen line |
| 669 | exe "normal 20h" |
| 670 | call s:check_col_calc(1, 4, 61) |
| 671 | |
Bram Moolenaar | b21b8e9 | 2022-12-03 18:35:07 +0000 | [diff] [blame] | 672 | " cursor on last line, "gk" should not cause a scroll |
| 673 | set scrolloff=0 |
| 674 | normal G0 |
| 675 | call s:check_col_calc(1, 7, 1) |
| 676 | normal gk |
| 677 | call s:check_col_calc(1, 6, 101) |
| 678 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 679 | bwipe! |
| 680 | endfunc |
| 681 | |
| 682 | |
Yee Cheng Chin | e6392b1 | 2022-11-19 14:31:08 +0000 | [diff] [blame] | 683 | " Test that mouse picking is still accurate when we have smooth scrolled lines |
| 684 | func Test_smoothscroll_mouse_pos() |
| 685 | CheckNotGui |
| 686 | CheckUnix |
| 687 | |
| 688 | let save_mouse = &mouse |
| 689 | let save_term = &term |
| 690 | let save_ttymouse = &ttymouse |
| 691 | set mouse=a term=xterm ttymouse=xterm2 |
| 692 | |
| 693 | call NewWindow(10, 20) |
| 694 | setl smoothscroll wrap |
| 695 | " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines. |
| 696 | call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"]) |
| 697 | |
| 698 | func s:check_mouse_click(row, col, buf_row, buf_col) |
| 699 | call MouseLeftClick(a:row, a:col) |
| 700 | |
| 701 | call assert_equal(a:col, wincol()) |
| 702 | call assert_equal(a:row, winline()) |
| 703 | call assert_equal(a:buf_row, line('.')) |
| 704 | call assert_equal(a:buf_col, col('.')) |
| 705 | endfunc |
| 706 | |
| 707 | " Check that clicking without scroll works first. |
| 708 | call s:check_mouse_click(3, 5, 1, 45) |
| 709 | call s:check_mouse_click(4, 1, 2, 1) |
| 710 | call s:check_mouse_click(4, 6, 2, 6) |
| 711 | call s:check_mouse_click(5, 1, 3, 1) |
| 712 | call s:check_mouse_click(5, 6, 3, 6) |
| 713 | |
| 714 | " Smooth scroll, and checks that this didn't mess up mouse clicking |
| 715 | exe "normal \<C-E>" |
| 716 | call s:check_mouse_click(2, 5, 1, 45) |
| 717 | call s:check_mouse_click(3, 1, 2, 1) |
| 718 | call s:check_mouse_click(3, 6, 2, 6) |
| 719 | call s:check_mouse_click(4, 1, 3, 1) |
| 720 | call s:check_mouse_click(4, 6, 3, 6) |
| 721 | |
| 722 | exe "normal \<C-E>" |
| 723 | call s:check_mouse_click(1, 5, 1, 45) |
| 724 | call s:check_mouse_click(2, 1, 2, 1) |
| 725 | call s:check_mouse_click(2, 6, 2, 6) |
| 726 | call s:check_mouse_click(3, 1, 3, 1) |
| 727 | call s:check_mouse_click(3, 6, 3, 6) |
| 728 | |
| 729 | " Make a new first line 11 physical lines tall so it's taller than window |
| 730 | " height, to test overflow calculations with really long lines wrapping. |
| 731 | normal gg |
| 732 | call setline(1, "12345678901234567890"->repeat(11)) |
| 733 | exe "normal 6\<C-E>" |
| 734 | call s:check_mouse_click(5, 1, 1, 201) |
| 735 | call s:check_mouse_click(6, 1, 2, 1) |
| 736 | call s:check_mouse_click(7, 1, 3, 1) |
| 737 | |
| 738 | let &mouse = save_mouse |
| 739 | let &term = save_term |
| 740 | let &ttymouse = save_ttymouse |
zeertzjq | ad493ef | 2024-03-29 10:23:19 +0100 | [diff] [blame] | 741 | bwipe! |
Yee Cheng Chin | e6392b1 | 2022-11-19 14:31:08 +0000 | [diff] [blame] | 742 | endfunc |
| 743 | |
Bram Moolenaar | 870219c | 2023-01-26 14:14:43 +0000 | [diff] [blame] | 744 | " this was dividing by zero |
Luuk van Baal | c8502f9 | 2023-05-06 12:40:15 +0100 | [diff] [blame] | 745 | func Test_smoothscroll_zero_width() |
Bram Moolenaar | 870219c | 2023-01-26 14:14:43 +0000 | [diff] [blame] | 746 | CheckScreendump |
| 747 | |
| 748 | let lines =<< trim END |
| 749 | winsize 0 0 |
| 750 | vsplit |
| 751 | vsplit |
| 752 | vsplit |
| 753 | vsplit |
| 754 | vsplit |
| 755 | sil norm H |
| 756 | set wrap |
| 757 | set smoothscroll |
| 758 | set number |
| 759 | END |
| 760 | call writefile(lines, 'XSmoothScrollZero', 'D') |
| 761 | 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] | 762 | call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {}) |
| 763 | |
| 764 | call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>") |
| 765 | call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {}) |
| 766 | |
| 767 | call StopVimInTerminal(buf) |
| 768 | endfunc |
| 769 | |
Luuk van Baal | c8502f9 | 2023-05-06 12:40:15 +0100 | [diff] [blame] | 770 | " this was unnecessarily inserting lines |
| 771 | func Test_smoothscroll_ins_lines() |
| 772 | CheckScreendump |
| 773 | |
| 774 | let lines =<< trim END |
| 775 | set wrap |
| 776 | set smoothscroll |
| 777 | set scrolloff=0 |
| 778 | set conceallevel=2 |
| 779 | call setline(1, [ |
| 780 | \'line one' .. 'with lots of text in one line '->repeat(2), |
| 781 | \'line two', |
| 782 | \'line three', |
| 783 | \'line four', |
| 784 | \'line five' |
| 785 | \]) |
| 786 | END |
| 787 | call writefile(lines, 'XSmoothScrollInsLines', 'D') |
| 788 | let buf = RunVimInTerminal('-S XSmoothScrollInsLines', #{rows: 6, cols: 40}) |
| 789 | |
| 790 | call term_sendkeys(buf, "\<C-E>gjgk") |
| 791 | call VerifyScreenDump(buf, 'Test_smooth_ins_lines', {}) |
| 792 | |
| 793 | call StopVimInTerminal(buf) |
| 794 | endfunc |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 795 | |
Luuk van Baal | 3ce8c38 | 2023-05-08 15:51:14 +0100 | [diff] [blame] | 796 | " this placed the cursor in the command line |
| 797 | func Test_smoothscroll_cursormoved_line() |
| 798 | CheckScreendump |
| 799 | |
| 800 | let lines =<< trim END |
| 801 | set smoothscroll |
| 802 | call setline(1, [ |
| 803 | \'', |
| 804 | \'_'->repeat(&lines * &columns), |
| 805 | \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2) |
| 806 | \]) |
| 807 | autocmd CursorMoved * eval [line('w0'), line('w$')] |
| 808 | call search('xxx') |
| 809 | END |
| 810 | call writefile(lines, 'XSmoothCursorMovedLine', 'D') |
| 811 | let buf = RunVimInTerminal('-S XSmoothCursorMovedLine', #{rows: 6}) |
| 812 | |
| 813 | call VerifyScreenDump(buf, 'Test_smooth_cursormoved_line', {}) |
| 814 | |
| 815 | call StopVimInTerminal(buf) |
| 816 | endfunc |
| 817 | |
| 818 | func Test_smoothscroll_eob() |
| 819 | CheckScreendump |
| 820 | |
| 821 | let lines =<< trim END |
| 822 | set smoothscroll |
| 823 | call setline(1, ['']->repeat(100)) |
| 824 | norm G |
| 825 | END |
| 826 | call writefile(lines, 'XSmoothEob', 'D') |
| 827 | let buf = RunVimInTerminal('-S XSmoothEob', #{rows: 10}) |
| 828 | |
| 829 | " does not scroll halfway when scrolling to end of buffer |
| 830 | call VerifyScreenDump(buf, 'Test_smooth_eob_1', {}) |
| 831 | |
| 832 | " cursor is not placed below window |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 833 | call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\<CR>\<C-L>\<C-B>G") |
Luuk van Baal | 3ce8c38 | 2023-05-08 15:51:14 +0100 | [diff] [blame] | 834 | call VerifyScreenDump(buf, 'Test_smooth_eob_2', {}) |
| 835 | |
| 836 | call StopVimInTerminal(buf) |
| 837 | endfunc |
| 838 | |
Luuk van Baal | d49f646 | 2023-05-19 14:04:47 +0100 | [diff] [blame] | 839 | " skipcol should not reset when doing incremental search on the same word |
| 840 | func Test_smoothscroll_incsearch() |
| 841 | CheckScreendump |
| 842 | |
| 843 | let lines =<< trim END |
| 844 | set smoothscroll number scrolloff=0 incsearch |
| 845 | call setline(1, repeat([''], 20)) |
| 846 | call setline(11, repeat('a', 100)) |
| 847 | call setline(14, 'bbbb') |
| 848 | END |
| 849 | call writefile(lines, 'XSmoothIncsearch', 'D') |
zeertzjq | 3c80227 | 2023-06-03 22:08:33 +0100 | [diff] [blame] | 850 | let buf = RunVimInTerminal('-S XSmoothIncsearch', #{rows: 8, cols: 40}) |
Luuk van Baal | d49f646 | 2023-05-19 14:04:47 +0100 | [diff] [blame] | 851 | |
| 852 | call term_sendkeys(buf, "/b") |
| 853 | call VerifyScreenDump(buf, 'Test_smooth_incsearch_1', {}) |
| 854 | call term_sendkeys(buf, "b") |
| 855 | call VerifyScreenDump(buf, 'Test_smooth_incsearch_2', {}) |
| 856 | call term_sendkeys(buf, "b") |
| 857 | call VerifyScreenDump(buf, 'Test_smooth_incsearch_3', {}) |
| 858 | call term_sendkeys(buf, "b") |
| 859 | call VerifyScreenDump(buf, 'Test_smooth_incsearch_4', {}) |
| 860 | call term_sendkeys(buf, "\<CR>") |
| 861 | |
| 862 | call StopVimInTerminal(buf) |
| 863 | endfunc |
| 864 | |
zeertzjq | 3c80227 | 2023-06-03 22:08:33 +0100 | [diff] [blame] | 865 | " Test scrolling multiple lines and stopping at non-zero skipcol. |
| 866 | func Test_smoothscroll_multi_skipcol() |
| 867 | CheckScreendump |
| 868 | |
| 869 | let lines =<< trim END |
| 870 | setlocal cursorline scrolloff=0 smoothscroll |
zeertzjq | d9a92dc | 2023-06-05 18:41:35 +0100 | [diff] [blame] | 871 | call setline(1, repeat([''], 8)) |
zeertzjq | 3c80227 | 2023-06-03 22:08:33 +0100 | [diff] [blame] | 872 | call setline(3, repeat('a', 50)) |
zeertzjq | d9a92dc | 2023-06-05 18:41:35 +0100 | [diff] [blame] | 873 | call setline(4, repeat('a', 50)) |
| 874 | call setline(7, 'bbb') |
| 875 | call setline(8, 'ccc') |
zeertzjq | 3c80227 | 2023-06-03 22:08:33 +0100 | [diff] [blame] | 876 | redraw |
| 877 | END |
| 878 | call writefile(lines, 'XSmoothMultiSkipcol', 'D') |
| 879 | let buf = RunVimInTerminal('-S XSmoothMultiSkipcol', #{rows: 10, cols: 40}) |
| 880 | call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_1', {}) |
| 881 | |
| 882 | call term_sendkeys(buf, "3\<C-E>") |
| 883 | call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_2', {}) |
| 884 | |
zeertzjq | d9a92dc | 2023-06-05 18:41:35 +0100 | [diff] [blame] | 885 | call term_sendkeys(buf, "2\<C-E>") |
| 886 | call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_3', {}) |
| 887 | |
zeertzjq | 3c80227 | 2023-06-03 22:08:33 +0100 | [diff] [blame] | 888 | call StopVimInTerminal(buf) |
| 889 | endfunc |
| 890 | |
fullwaywang | 8154e64 | 2023-06-24 21:58:09 +0100 | [diff] [blame] | 891 | " this was dividing by zero bug in scroll_cursor_bot |
| 892 | func Test_smoothscroll_zero_width_scroll_cursor_bot() |
| 893 | CheckScreendump |
| 894 | |
| 895 | let lines =<< trim END |
| 896 | silent normal yy |
| 897 | silent normal 19p |
zeertzjq | e429893 | 2023-06-26 19:02:43 +0100 | [diff] [blame] | 898 | set cpoptions+=n |
fullwaywang | 8154e64 | 2023-06-24 21:58:09 +0100 | [diff] [blame] | 899 | vsplit |
| 900 | vertical resize 0 |
| 901 | set foldcolumn=1 |
| 902 | set number |
| 903 | set smoothscroll |
| 904 | silent normal 20G |
| 905 | END |
| 906 | call writefile(lines, 'XSmoothScrollZeroBot', 'D') |
zeertzjq | e429893 | 2023-06-26 19:02:43 +0100 | [diff] [blame] | 907 | let buf = RunVimInTerminal('-u NONE -S XSmoothScrollZeroBot', #{rows: 19}) |
fullwaywang | 8154e64 | 2023-06-24 21:58:09 +0100 | [diff] [blame] | 908 | call VerifyScreenDump(buf, 'Test_smoothscroll_zero_bot', {}) |
| 909 | |
| 910 | call StopVimInTerminal(buf) |
| 911 | endfunc |
| 912 | |
Luuk van Baal | bb800a7 | 2023-11-14 17:05:18 +0100 | [diff] [blame] | 913 | " scroll_cursor_top() should reset skipcol when it changes topline |
| 914 | func Test_smoothscroll_cursor_top() |
| 915 | CheckScreendump |
| 916 | |
| 917 | let lines =<< trim END |
| 918 | set smoothscroll scrolloff=2 |
| 919 | new | 11resize | wincmd j |
| 920 | call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4']) |
| 921 | exe "norm G3\<C-E>k" |
| 922 | END |
| 923 | call writefile(lines, 'XSmoothScrollCursorTop', 'D') |
zeertzjq | 5b4d1fc | 2023-12-03 17:54:10 +0100 | [diff] [blame] | 924 | let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCursorTop', #{rows: 12, cols: 40}) |
Luuk van Baal | bb800a7 | 2023-11-14 17:05:18 +0100 | [diff] [blame] | 925 | call VerifyScreenDump(buf, 'Test_smoothscroll_cursor_top', {}) |
| 926 | |
| 927 | call StopVimInTerminal(buf) |
| 928 | endfunc |
| 929 | |
Christian Brabandt | cb0b99f | 2023-11-14 20:05:59 +0100 | [diff] [blame] | 930 | " Division by zero, shouldn't crash |
| 931 | func Test_smoothscroll_crash() |
| 932 | CheckScreendump |
| 933 | |
| 934 | let lines =<< trim END |
| 935 | 20 new |
| 936 | vsp |
| 937 | put =repeat('aaaa', 20) |
| 938 | set nu fdc=1 smoothscroll cpo+=n |
| 939 | vert resize 0 |
| 940 | exe "norm! 0\<c-e>" |
| 941 | END |
| 942 | call writefile(lines, 'XSmoothScrollCrash', 'D') |
zeertzjq | 5b4d1fc | 2023-12-03 17:54:10 +0100 | [diff] [blame] | 943 | let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCrash', #{rows: 12, cols: 40}) |
Christian Brabandt | cb0b99f | 2023-11-14 20:05:59 +0100 | [diff] [blame] | 944 | call term_sendkeys(buf, "2\<C-E>\<C-L>") |
| 945 | |
| 946 | call StopVimInTerminal(buf) |
| 947 | endfunc |
| 948 | |
zeertzjq | 5b4d1fc | 2023-12-03 17:54:10 +0100 | [diff] [blame] | 949 | func Test_smoothscroll_insert_bottom() |
| 950 | CheckScreendump |
| 951 | |
| 952 | let lines =<< trim END |
| 953 | call setline(1, repeat([repeat('A very long line ...', 10)], 5)) |
| 954 | set wrap smoothscroll scrolloff=0 |
| 955 | END |
| 956 | call writefile(lines, 'XSmoothScrollInsertBottom', 'D') |
| 957 | let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInsertBottom', #{rows: 9, cols: 40}) |
| 958 | call term_sendkeys(buf, "Go123456789\<CR>") |
| 959 | call VerifyScreenDump(buf, 'Test_smoothscroll_insert_bottom', {}) |
| 960 | |
| 961 | call StopVimInTerminal(buf) |
| 962 | endfunc |
| 963 | |
zeertzjq | c7a8eb5 | 2024-05-08 20:22:40 +0200 | [diff] [blame] | 964 | func Test_smoothscroll_in_qf_window() |
| 965 | CheckFeature quickfix |
| 966 | CheckScreendump |
| 967 | |
| 968 | let lines =<< trim END |
| 969 | set nocompatible display=lastline |
| 970 | copen 5 |
| 971 | setlocal number smoothscroll |
| 972 | let g:l = [{'text': 'foo'}] + repeat([{'text': join(range(30))}], 10) |
| 973 | call setqflist(g:l, 'r') |
| 974 | normal! G |
| 975 | wincmd t |
| 976 | let g:l1 = [{'text': join(range(1000))}] |
| 977 | END |
| 978 | call writefile(lines, 'XSmoothScrollInQfWindow', 'D') |
| 979 | let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInQfWindow', #{rows: 20, cols: 60}) |
| 980 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_1', {}) |
| 981 | |
| 982 | call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>") |
| 983 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {}) |
| 984 | |
| 985 | call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>") |
| 986 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {}) |
| 987 | |
| 988 | call term_sendkeys(buf, ":call setqflist(g:l1, 'r')\<CR>") |
| 989 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_4', {}) |
| 990 | |
| 991 | call term_sendkeys(buf, "\<C-W>b$\<C-W>t") |
| 992 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_5', {}) |
| 993 | |
| 994 | call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>") |
| 995 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {}) |
| 996 | |
| 997 | call term_sendkeys(buf, ":call setqflist(g:l1, 'r')\<CR>") |
| 998 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_4', {}) |
| 999 | |
| 1000 | call term_sendkeys(buf, "\<C-W>b$\<C-W>t") |
| 1001 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_5', {}) |
| 1002 | |
| 1003 | call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>") |
| 1004 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {}) |
| 1005 | |
| 1006 | call StopVimInTerminal(buf) |
| 1007 | endfunc |
| 1008 | |
Sean Dewar | 02fcae0 | 2024-02-21 19:40:44 +0100 | [diff] [blame] | 1009 | func Test_smoothscroll_in_zero_width_window() |
| 1010 | set cpo+=n number smoothscroll |
| 1011 | set winwidth=99999 winminwidth=0 |
| 1012 | |
| 1013 | vsplit |
| 1014 | call assert_equal(0, winwidth(winnr('#'))) |
| 1015 | call win_execute(win_getid(winnr('#')), "norm! \<C-Y>") |
| 1016 | |
| 1017 | only! |
| 1018 | set winwidth& winminwidth& |
| 1019 | set cpo-=n nonumber nosmoothscroll |
| 1020 | endfunc |
| 1021 | |
| 1022 | func Test_smoothscroll_textoff_small_winwidth() |
| 1023 | set smoothscroll number |
| 1024 | call setline(1, 'llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch') |
| 1025 | vsplit |
| 1026 | |
| 1027 | let textoff = getwininfo(win_getid())[0].textoff |
| 1028 | execute 'vertical resize' textoff + 1 |
| 1029 | redraw |
| 1030 | call assert_equal(0, winsaveview().skipcol) |
| 1031 | execute "normal! 0\<C-E>" |
| 1032 | redraw |
| 1033 | call assert_equal(1, winsaveview().skipcol) |
| 1034 | execute 'vertical resize' textoff - 1 |
| 1035 | " This caused a signed integer overflow. |
| 1036 | redraw |
| 1037 | call assert_equal(1, winsaveview().skipcol) |
| 1038 | execute 'vertical resize' textoff |
| 1039 | " This caused an infinite loop. |
| 1040 | redraw |
| 1041 | call assert_equal(1, winsaveview().skipcol) |
| 1042 | |
| 1043 | %bw! |
| 1044 | set smoothscroll& number& |
| 1045 | endfunc |
| 1046 | |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1047 | func Test_smoothscroll_page() |
zeertzjq | ad493ef | 2024-03-29 10:23:19 +0100 | [diff] [blame] | 1048 | call NewWindow(10, 40) |
| 1049 | setlocal smoothscroll |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1050 | call setline(1, 'abcde '->repeat(150)) |
| 1051 | |
| 1052 | exe "norm! \<C-F>" |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1053 | call assert_equal(400, winsaveview().skipcol) |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1054 | exe "norm! \<C-F>" |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1055 | call assert_equal(800, winsaveview().skipcol) |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1056 | exe "norm! \<C-F>" |
| 1057 | call assert_equal(880, winsaveview().skipcol) |
| 1058 | exe "norm! \<C-B>" |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1059 | call assert_equal(480, winsaveview().skipcol) |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1060 | exe "norm! \<C-B>" |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1061 | call assert_equal(80, winsaveview().skipcol) |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1062 | exe "norm! \<C-B>" |
| 1063 | call assert_equal(0, winsaveview().skipcol) |
| 1064 | |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1065 | " Half-page scrolling does not go beyond end of buffer and moves the cursor. |
Luuk van Baal | bd28cae | 2024-04-03 22:50:40 +0200 | [diff] [blame] | 1066 | " Even with 'nostartofline', the correct amount of lines is scrolled. |
| 1067 | setl nostartofline |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1068 | exe "norm! 15|\<C-D>" |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1069 | call assert_equal(200, winsaveview().skipcol) |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1070 | call assert_equal(215, col('.')) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1071 | exe "norm! \<C-D>" |
| 1072 | call assert_equal(400, winsaveview().skipcol) |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1073 | call assert_equal(415, col('.')) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1074 | exe "norm! \<C-D>" |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1075 | call assert_equal(520, winsaveview().skipcol) |
Luuk van Baal | 78c5150 | 2024-04-09 21:30:19 +0200 | [diff] [blame] | 1076 | call assert_equal(615, col('.')) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1077 | exe "norm! \<C-D>" |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1078 | call assert_equal(520, winsaveview().skipcol) |
Luuk van Baal | 78c5150 | 2024-04-09 21:30:19 +0200 | [diff] [blame] | 1079 | call assert_equal(815, col('.')) |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1080 | exe "norm! \<C-D>" |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1081 | call assert_equal(520, winsaveview().skipcol) |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1082 | call assert_equal(895, col('.')) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1083 | exe "norm! \<C-U>" |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1084 | call assert_equal(320, winsaveview().skipcol) |
| 1085 | call assert_equal(695, col('.')) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1086 | exe "norm! \<C-U>" |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1087 | call assert_equal(120, winsaveview().skipcol) |
| 1088 | call assert_equal(495, col('.')) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1089 | exe "norm! \<C-U>" |
| 1090 | call assert_equal(0, winsaveview().skipcol) |
Luuk van Baal | 78c5150 | 2024-04-09 21:30:19 +0200 | [diff] [blame] | 1091 | call assert_equal(295, col('.')) |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1092 | exe "norm! \<C-U>" |
| 1093 | call assert_equal(0, winsaveview().skipcol) |
Luuk van Baal | 78c5150 | 2024-04-09 21:30:19 +0200 | [diff] [blame] | 1094 | call assert_equal(95, col('.')) |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1095 | exe "norm! \<C-U>" |
| 1096 | call assert_equal(0, winsaveview().skipcol) |
| 1097 | call assert_equal(15, col('.')) |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1098 | |
| 1099 | bwipe! |
| 1100 | endfunc |
| 1101 | |
| 1102 | func Test_smoothscroll_next_topline() |
| 1103 | call NewWindow(10, 40) |
| 1104 | setlocal smoothscroll |
| 1105 | call setline(1, ['abcde '->repeat(150)]->repeat(2)) |
| 1106 | |
| 1107 | " Scrolling a screenline that causes the cursor to move to the next buffer |
| 1108 | " line should not skip part of that line to bring the cursor into view. |
| 1109 | exe "norm! 22\<C-E>" |
| 1110 | call assert_equal(880, winsaveview().skipcol) |
| 1111 | exe "norm! \<C-E>" |
| 1112 | redraw |
| 1113 | call assert_equal(0, winsaveview().skipcol) |
| 1114 | |
Luuk van Baal | bd28cae | 2024-04-03 22:50:40 +0200 | [diff] [blame] | 1115 | " Also when scrolling back. |
| 1116 | exe "norm! G\<C-Y>" |
| 1117 | redraw |
| 1118 | call assert_equal(880, winsaveview().skipcol) |
| 1119 | |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1120 | " Cursor in correct place when not in the first screenline of a buffer line. |
| 1121 | exe "norm! gg4gj20\<C-D>\<C-D>" |
| 1122 | redraw |
| 1123 | call assert_equal(2, line('w0')) |
| 1124 | |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1125 | " Cursor does not end up above topline, adjusting topline later. |
| 1126 | setlocal nu cpo+=n |
| 1127 | exe "norm! G$g013\<C-Y>" |
| 1128 | redraw |
| 1129 | call assert_equal(2, line('.')) |
| 1130 | call assert_equal(0, winsaveview().skipcol) |
| 1131 | |
| 1132 | set cpo-=n |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1133 | bwipe! |
| 1134 | endfunc |
| 1135 | |
| 1136 | func Test_smoothscroll_long_line_zb() |
| 1137 | call NewWindow(10, 40) |
| 1138 | call setline(1, 'abcde '->repeat(150)) |
| 1139 | |
| 1140 | " Also works without 'smoothscroll' when last line of buffer doesn't fit. |
| 1141 | " Used to set topline to buffer line count plus one, causing an empty screen. |
| 1142 | norm zb |
| 1143 | redraw |
| 1144 | call assert_equal(1, winsaveview().topline) |
| 1145 | |
| 1146 | " Moving cursor to bottom works on line that doesn't fit with 'smoothscroll'. |
| 1147 | " Skipcol was adjusted later for cursor being on not visible part of line. |
| 1148 | setlocal smoothscroll |
| 1149 | norm zb |
| 1150 | redraw |
| 1151 | call assert_equal(520, winsaveview().skipcol) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1152 | |
zeertzjq | ad493ef | 2024-03-29 10:23:19 +0100 | [diff] [blame] | 1153 | bwipe! |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1154 | endfunc |
| 1155 | |
Luuk van Baal | b32055e | 2024-05-16 20:44:09 +0200 | [diff] [blame^] | 1156 | func Test_smooth_long_scrolloff() |
| 1157 | CheckScreendump |
| 1158 | |
| 1159 | let lines =<< trim END |
| 1160 | set smoothscroll scrolloff=3 |
| 1161 | call setline(1, ['one', 'two long'->repeat(100), 'three', 'four', 'five', 'six']) |
| 1162 | END |
| 1163 | call writefile(lines, 'XSmoothLongScrolloff', 'D') |
| 1164 | let buf = RunVimInTerminal('-u NONE -S XSmoothLongScrolloff', #{rows: 8, cols: 40}) |
| 1165 | "FIXME: empty screen due to reset_skipcol()/curs_columns() shenanigans |
| 1166 | call term_sendkeys(buf, ":norm j601|\<CR>") |
| 1167 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_1', {}) |
| 1168 | |
| 1169 | call term_sendkeys(buf, "gj") |
| 1170 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_2', {}) |
| 1171 | |
| 1172 | call term_sendkeys(buf, "gj") |
| 1173 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_3', {}) |
| 1174 | |
| 1175 | call term_sendkeys(buf, "gj") |
| 1176 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_4', {}) |
| 1177 | |
| 1178 | call term_sendkeys(buf, "gj") |
| 1179 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_5', {}) |
| 1180 | |
| 1181 | call term_sendkeys(buf, "gj") |
| 1182 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_6', {}) |
| 1183 | |
| 1184 | call term_sendkeys(buf, "gk") |
| 1185 | "FIXME: empty screen due to reset_skipcol()/curs_columns() shenanigans |
| 1186 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_7', {}) |
| 1187 | |
| 1188 | call StopVimInTerminal(buf) |
| 1189 | endfunc |
| 1190 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1191 | " vim: shiftwidth=2 sts=2 expandtab |