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 | |
zeertzjq | 47f8584 | 2024-10-01 19:35:47 +0200 | [diff] [blame] | 305 | func Test_smoothscroll_diff_change_line() |
| 306 | CheckScreendump |
| 307 | |
| 308 | let lines =<< trim END |
| 309 | set diffopt+=followwrap smoothscroll |
| 310 | call setline(1, repeat(' abc', &columns)) |
| 311 | call setline(2, 'bar') |
| 312 | call setline(3, repeat(' abc', &columns)) |
| 313 | vnew |
| 314 | call setline(1, repeat(' abc', &columns)) |
| 315 | call setline(2, 'foo') |
| 316 | call setline(3, 'bar') |
| 317 | call setline(4, repeat(' abc', &columns)) |
| 318 | windo exe "normal! 2gg5\<C-E>" |
| 319 | windo diffthis |
| 320 | END |
| 321 | call writefile(lines, 'XSmoothDiffChangeLine', 'D') |
| 322 | let buf = RunVimInTerminal('-S XSmoothDiffChangeLine', #{rows: 20, columns: 55}) |
| 323 | |
| 324 | call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_1', {}) |
| 325 | call term_sendkeys(buf, "Abar") |
| 326 | call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_2', {}) |
| 327 | call term_sendkeys(buf, "\<Esc>") |
| 328 | call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_3', {}) |
| 329 | call term_sendkeys(buf, "yyp") |
| 330 | call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_4', {}) |
| 331 | |
| 332 | call StopVimInTerminal(buf) |
| 333 | endfunc |
| 334 | |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 335 | func Test_smoothscroll_wrap_scrolloff_zero() |
| 336 | CheckScreendump |
| 337 | |
| 338 | let lines =<< trim END |
| 339 | vim9script |
| 340 | setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7)) |
| 341 | set smoothscroll scrolloff=0 |
| 342 | :3 |
| 343 | END |
| 344 | call writefile(lines, 'XSmoothWrap', 'D') |
| 345 | let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40}) |
| 346 | |
| 347 | call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {}) |
| 348 | |
Bram Moolenaar | 46b5474 | 2022-10-06 15:46:49 +0100 | [diff] [blame] | 349 | " moving cursor down - whole bottom line shows |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 350 | call term_sendkeys(buf, "j") |
| 351 | call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {}) |
| 352 | |
| 353 | call term_sendkeys(buf, "\<C-E>j") |
| 354 | call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {}) |
| 355 | |
| 356 | call term_sendkeys(buf, "G") |
| 357 | call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {}) |
| 358 | |
Luuk van Baal | d49f646 | 2023-05-19 14:04:47 +0100 | [diff] [blame] | 359 | call term_sendkeys(buf, "4\<C-Y>G") |
| 360 | call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {}) |
| 361 | |
| 362 | " 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] | 363 | call term_sendkeys(buf, "2gj3l2k") |
Bram Moolenaar | 46b5474 | 2022-10-06 15:46:49 +0100 | [diff] [blame] | 364 | call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {}) |
| 365 | |
Luuk van Baal | d49f646 | 2023-05-19 14:04:47 +0100 | [diff] [blame] | 366 | " moving cursor up where the <<< marker is - whole top line shows |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 367 | call term_sendkeys(buf, "2j02k") |
| 368 | call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {}) |
| 369 | |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 370 | call StopVimInTerminal(buf) |
| 371 | endfunc |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 372 | |
Bram Moolenaar | 8cf3459 | 2022-10-08 21:13:40 +0100 | [diff] [blame] | 373 | func Test_smoothscroll_wrap_long_line() |
| 374 | CheckScreendump |
| 375 | |
| 376 | let lines =<< trim END |
| 377 | vim9script |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 378 | 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] | 379 | set smoothscroll scrolloff=0 |
| 380 | normal 3G10|zt |
| 381 | END |
| 382 | call writefile(lines, 'XSmoothWrap', 'D') |
| 383 | let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40}) |
| 384 | call VerifyScreenDump(buf, 'Test_smooth_long_1', {}) |
| 385 | |
| 386 | " scrolling up, cursor moves screen line down |
| 387 | call term_sendkeys(buf, "\<C-E>") |
| 388 | call VerifyScreenDump(buf, 'Test_smooth_long_2', {}) |
| 389 | call term_sendkeys(buf, "5\<C-E>") |
| 390 | call VerifyScreenDump(buf, 'Test_smooth_long_3', {}) |
| 391 | |
| 392 | " scrolling down, cursor moves screen line up |
| 393 | call term_sendkeys(buf, "5\<C-Y>") |
| 394 | call VerifyScreenDump(buf, 'Test_smooth_long_4', {}) |
| 395 | call term_sendkeys(buf, "\<C-Y>") |
| 396 | call VerifyScreenDump(buf, 'Test_smooth_long_5', {}) |
| 397 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 398 | " 'scrolloff' set to 1, scrolling up, cursor moves screen line down |
| 399 | call term_sendkeys(buf, ":set scrolloff=1\<CR>") |
| 400 | call term_sendkeys(buf, "10|\<C-E>") |
| 401 | call VerifyScreenDump(buf, 'Test_smooth_long_6', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 402 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 403 | " 'scrolloff' set to 1, scrolling down, cursor moves screen line up |
| 404 | call term_sendkeys(buf, "\<C-E>") |
| 405 | call term_sendkeys(buf, "gjgj") |
| 406 | call term_sendkeys(buf, "\<C-Y>") |
| 407 | call VerifyScreenDump(buf, 'Test_smooth_long_7', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 408 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 409 | " 'scrolloff' set to 2, scrolling up, cursor moves screen line down |
| 410 | call term_sendkeys(buf, ":set scrolloff=2\<CR>") |
| 411 | call term_sendkeys(buf, "10|\<C-E>") |
| 412 | call VerifyScreenDump(buf, 'Test_smooth_long_8', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 413 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 414 | " 'scrolloff' set to 2, scrolling down, cursor moves screen line up |
| 415 | call term_sendkeys(buf, "\<C-E>") |
| 416 | call term_sendkeys(buf, "gj") |
| 417 | call term_sendkeys(buf, "\<C-Y>") |
| 418 | call VerifyScreenDump(buf, 'Test_smooth_long_9', {}) |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 419 | |
| 420 | " 'scrolloff' set to 0, move cursor down one line. |
| 421 | " Cursor should move properly, and since this is a really long line, it will |
| 422 | " be put on top of the screen. |
| 423 | call term_sendkeys(buf, ":set scrolloff=0\<CR>") |
| 424 | call term_sendkeys(buf, "0j") |
| 425 | call VerifyScreenDump(buf, 'Test_smooth_long_10', {}) |
| 426 | |
Bram Moolenaar | db4d88c | 2022-12-31 15:13:22 +0000 | [diff] [blame] | 427 | " 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] | 428 | call term_sendkeys(buf, "zt") |
Bram Moolenaar | db4d88c | 2022-12-31 15:13:22 +0000 | [diff] [blame] | 429 | call VerifyScreenDump(buf, 'Test_smooth_long_11', {}) |
| 430 | call term_sendkeys(buf, "zz") |
| 431 | call VerifyScreenDump(buf, 'Test_smooth_long_12', {}) |
Luuk van Baal | 6f37e53 | 2023-05-09 21:23:54 +0100 | [diff] [blame] | 432 | call term_sendkeys(buf, "zb") |
Bram Moolenaar | db4d88c | 2022-12-31 15:13:22 +0000 | [diff] [blame] | 433 | call VerifyScreenDump(buf, 'Test_smooth_long_13', {}) |
| 434 | |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 435 | " Repeat the step and move the cursor down again. |
| 436 | " This time, use a shorter long line that is barely long enough to span more |
| 437 | " than one window. Note that the cursor is at the bottom this time because |
| 438 | " Vim prefers to do so if we are scrolling a few lines only. |
| 439 | 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] | 440 | " Currently visible lines were replaced, test that the lines and cursor |
| 441 | " are correctly displayed. |
| 442 | call VerifyScreenDump(buf, 'Test_smooth_long_14', {}) |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 443 | call term_sendkeys(buf, "3Gzt") |
| 444 | call term_sendkeys(buf, "j") |
Luuk van Baal | 5d01f86 | 2023-05-11 19:24:20 +0100 | [diff] [blame] | 445 | call VerifyScreenDump(buf, 'Test_smooth_long_15', {}) |
Yee Cheng Chin | 361895d | 2022-11-19 12:25:16 +0000 | [diff] [blame] | 446 | |
| 447 | " Repeat the step but this time start it when the line is smooth-scrolled by |
| 448 | " one line. This tests that the offset calculation is still correct and |
| 449 | " still end up scrolling down to the next line with cursor at bottom of |
| 450 | " screen. |
| 451 | call term_sendkeys(buf, "3Gzt") |
| 452 | call term_sendkeys(buf, "\<C-E>j") |
Luuk van Baal | 5d01f86 | 2023-05-11 19:24:20 +0100 | [diff] [blame] | 453 | call VerifyScreenDump(buf, 'Test_smooth_long_16', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 454 | |
Bram Moolenaar | 8cf3459 | 2022-10-08 21:13:40 +0100 | [diff] [blame] | 455 | call StopVimInTerminal(buf) |
| 456 | endfunc |
| 457 | |
Bram Moolenaar | 2fbabd2 | 2022-10-12 19:53:38 +0100 | [diff] [blame] | 458 | func Test_smoothscroll_one_long_line() |
| 459 | CheckScreendump |
| 460 | |
| 461 | let lines =<< trim END |
| 462 | vim9script |
| 463 | setline(1, 'with lots of text '->repeat(7)) |
| 464 | set smoothscroll scrolloff=0 |
| 465 | END |
| 466 | call writefile(lines, 'XSmoothOneLong', 'D') |
| 467 | let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40}) |
| 468 | call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 469 | |
Bram Moolenaar | 2fbabd2 | 2022-10-12 19:53:38 +0100 | [diff] [blame] | 470 | call term_sendkeys(buf, "\<C-E>") |
| 471 | call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {}) |
| 472 | |
| 473 | call term_sendkeys(buf, "0") |
| 474 | call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {}) |
| 475 | |
| 476 | call StopVimInTerminal(buf) |
| 477 | endfunc |
| 478 | |
Bram Moolenaar | 75ac25b | 2022-11-17 19:00:14 +0000 | [diff] [blame] | 479 | func Test_smoothscroll_long_line_showbreak() |
| 480 | CheckScreendump |
| 481 | |
| 482 | let lines =<< trim END |
| 483 | vim9script |
| 484 | # a line that spans four screen lines |
| 485 | setline(1, 'with lots of text in one line '->repeat(6)) |
| 486 | set smoothscroll scrolloff=0 showbreak=+++\ |
| 487 | END |
| 488 | call writefile(lines, 'XSmoothLongShowbreak', 'D') |
| 489 | let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40}) |
| 490 | call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 491 | |
Bram Moolenaar | 75ac25b | 2022-11-17 19:00:14 +0000 | [diff] [blame] | 492 | call term_sendkeys(buf, "\<C-E>") |
| 493 | call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {}) |
| 494 | |
| 495 | call term_sendkeys(buf, "0") |
| 496 | call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {}) |
| 497 | |
| 498 | call StopVimInTerminal(buf) |
| 499 | endfunc |
| 500 | |
zeertzjq | ecb87dd | 2023-06-03 19:45:06 +0100 | [diff] [blame] | 501 | " Check that 'smoothscroll' marker is drawn over double-width char correctly. |
| 502 | " Run with multiple encodings. |
| 503 | func Test_smoothscroll_marker_over_double_width() |
| 504 | " Run this in a separate Vim instance to avoid messing up. |
| 505 | let after =<< trim [CODE] |
| 506 | scriptencoding utf-8 |
| 507 | call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10)) |
| 508 | setlocal smoothscroll |
| 509 | redraw |
| 510 | exe "norm \<C-E>" |
| 511 | redraw |
| 512 | " Check the chars one by one. Don't check the whole line concatenated. |
| 513 | call assert_equal('<', screenstring(1, 1)) |
| 514 | call assert_equal('<', screenstring(1, 2)) |
| 515 | call assert_equal('<', screenstring(1, 3)) |
| 516 | call assert_equal(' ', screenstring(1, 4)) |
| 517 | call assert_equal('口', screenstring(1, 5)) |
| 518 | call assert_equal('口', screenstring(1, 7)) |
| 519 | call assert_equal('口', screenstring(1, 9)) |
| 520 | call assert_equal('口', screenstring(1, 11)) |
| 521 | call assert_equal('口', screenstring(1, 13)) |
| 522 | call assert_equal('口', screenstring(1, 15)) |
| 523 | call writefile(v:errors, 'Xresult') |
| 524 | qall! |
| 525 | [CODE] |
| 526 | |
| 527 | let encodings = ['utf-8', 'cp932', 'cp936', 'cp949', 'cp950'] |
| 528 | if !has('win32') |
| 529 | let encodings += ['euc-jp'] |
| 530 | endif |
| 531 | for enc in encodings |
| 532 | let msg = 'enc=' .. enc |
| 533 | if RunVim([], after, $'--clean --cmd "set encoding={enc}"') |
| 534 | call assert_equal([], readfile('Xresult'), msg) |
| 535 | endif |
| 536 | call delete('Xresult') |
| 537 | endfor |
| 538 | endfunc |
| 539 | |
| 540 | " Same as the test above, but check the text actually shown on screen. |
| 541 | " Only run with UTF-8 encoding. |
| 542 | func Test_smoothscroll_marker_over_double_width_dump() |
| 543 | CheckScreendump |
| 544 | |
| 545 | let lines =<< trim END |
| 546 | call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10)) |
| 547 | setlocal smoothscroll |
| 548 | END |
| 549 | call writefile(lines, 'XSmoothMarkerOverDoubleWidth', 'D') |
| 550 | let buf = RunVimInTerminal('-S XSmoothMarkerOverDoubleWidth', #{rows: 6, cols: 40}) |
| 551 | call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_1', {}) |
| 552 | |
| 553 | call term_sendkeys(buf, "\<C-E>") |
| 554 | call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_2', {}) |
| 555 | |
| 556 | call StopVimInTerminal(buf) |
| 557 | endfunc |
| 558 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 559 | func s:check_col_calc(win_col, win_line, buf_col) |
| 560 | call assert_equal(a:win_col, wincol()) |
| 561 | call assert_equal(a:win_line, winline()) |
| 562 | call assert_equal(a:buf_col, col('.')) |
| 563 | endfunc |
| 564 | |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 565 | " Test that if the current cursor is on a smooth scrolled line, we correctly |
| 566 | " reposition it. Also check that we don't miscalculate the values by checking |
| 567 | " the consistency between wincol() and col('.') as they are calculated |
| 568 | " separately in code. |
| 569 | func Test_smoothscroll_cursor_position() |
| 570 | call NewWindow(10, 20) |
| 571 | setl smoothscroll wrap |
| 572 | call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") |
| 573 | |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 574 | call s:check_col_calc(1, 1, 1) |
| 575 | exe "normal \<C-E>" |
| 576 | |
| 577 | " Move down another line to avoid blocking the <<< display |
| 578 | call s:check_col_calc(1, 2, 41) |
| 579 | exe "normal \<C-Y>" |
| 580 | call s:check_col_calc(1, 3, 41) |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 581 | |
Luuk van Baal | 8667a56 | 2023-05-12 15:47:25 +0100 | [diff] [blame] | 582 | " Test "g0/g<Home>" |
| 583 | exe "normal gg\<C-E>" |
| 584 | norm $gkg0 |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 585 | call s:check_col_calc(4, 1, 24) |
Luuk van Baal | 8667a56 | 2023-05-12 15:47:25 +0100 | [diff] [blame] | 586 | |
| 587 | " Test moving the cursor behind the <<< display with 'virtualedit' |
| 588 | set virtualedit=all |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 589 | exe "normal \<C-E>gkh" |
Luuk van Baal | 8667a56 | 2023-05-12 15:47:25 +0100 | [diff] [blame] | 590 | call s:check_col_calc(3, 2, 23) |
| 591 | set virtualedit& |
| 592 | |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 593 | normal gg3l |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 594 | exe "normal \<C-E>" |
| 595 | |
| 596 | " 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] | 597 | call s:check_col_calc(4, 1, 24) |
| 598 | exe "normal \<C-Y>" |
| 599 | call s:check_col_calc(4, 2, 24) |
| 600 | normal ggg$ |
| 601 | exe "normal \<C-E>" |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 602 | call s:check_col_calc(20, 1, 40) |
| 603 | exe "normal \<C-Y>" |
| 604 | call s:check_col_calc(20, 2, 40) |
| 605 | normal gg |
| 606 | |
| 607 | " Test number, where we have indented lines |
| 608 | setl number |
| 609 | call s:check_col_calc(5, 1, 1) |
| 610 | exe "normal \<C-E>" |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 611 | |
| 612 | " Move down only 1 line when the <<< display is on the number column |
| 613 | call s:check_col_calc(5, 1, 17) |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 614 | exe "normal \<C-Y>" |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 615 | call s:check_col_calc(5, 2, 17) |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 616 | normal ggg$ |
| 617 | exe "normal \<C-E>" |
| 618 | call s:check_col_calc(20, 1, 32) |
| 619 | exe "normal \<C-Y>" |
| 620 | call s:check_col_calc(20, 2, 32) |
| 621 | normal gg |
| 622 | |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 623 | setl numberwidth=1 |
| 624 | |
| 625 | " Move down another line when numberwidth is too short to cover the whole |
| 626 | " <<< display |
| 627 | call s:check_col_calc(3, 1, 1) |
| 628 | exe "normal \<C-E>" |
| 629 | call s:check_col_calc(3, 2, 37) |
| 630 | exe "normal \<C-Y>" |
| 631 | call s:check_col_calc(3, 3, 37) |
| 632 | normal ggl |
| 633 | |
| 634 | " Only move 1 line down when we are just past the <<< display |
| 635 | call s:check_col_calc(4, 1, 2) |
| 636 | exe "normal \<C-E>" |
| 637 | call s:check_col_calc(4, 1, 20) |
| 638 | exe "normal \<C-Y>" |
| 639 | call s:check_col_calc(4, 2, 20) |
| 640 | normal gg |
| 641 | setl numberwidth& |
| 642 | |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 643 | " Test number + showbreak, so test that the additional indentation works |
| 644 | setl number showbreak=+++ |
| 645 | call s:check_col_calc(5, 1, 1) |
| 646 | exe "normal \<C-E>" |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 647 | call s:check_col_calc(8, 1, 17) |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 648 | exe "normal \<C-Y>" |
Yee Cheng Chin | 81ba26e | 2022-11-18 12:52:50 +0000 | [diff] [blame] | 649 | call s:check_col_calc(8, 2, 17) |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 650 | normal gg |
| 651 | |
| 652 | " Test number + cpo+=n mode, where wrapped lines aren't indented |
| 653 | setl number cpo+=n showbreak= |
| 654 | call s:check_col_calc(5, 1, 1) |
| 655 | exe "normal \<C-E>" |
| 656 | call s:check_col_calc(1, 2, 37) |
| 657 | exe "normal \<C-Y>" |
| 658 | call s:check_col_calc(1, 3, 37) |
| 659 | normal gg |
| 660 | |
Luuk van Baal | 24b62ec | 2023-05-13 14:12:15 +0100 | [diff] [blame] | 661 | " Test list + listchars "precedes", where there is always 1 overlap |
| 662 | " regardless of number and cpo-=n. |
| 663 | setl number list listchars=precedes:< cpo-=n |
| 664 | call s:check_col_calc(5, 1, 1) |
Luuk van Baal | 798fa76 | 2023-05-15 18:17:43 +0100 | [diff] [blame] | 665 | exe "normal 3|\<C-E>h" |
Luuk van Baal | 24b62ec | 2023-05-13 14:12:15 +0100 | [diff] [blame] | 666 | call s:check_col_calc(6, 1, 18) |
| 667 | norm h |
| 668 | call s:check_col_calc(5, 2, 17) |
| 669 | normal gg |
| 670 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 671 | bwipe! |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 672 | endfunc |
| 673 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 674 | func Test_smoothscroll_cursor_scrolloff() |
| 675 | call NewWindow(10, 20) |
| 676 | setl smoothscroll wrap |
| 677 | setl scrolloff=3 |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 678 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 679 | " 120 chars are 6 screen lines |
| 680 | call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST") |
| 681 | call setline(2, "below") |
| 682 | |
| 683 | call s:check_col_calc(1, 1, 1) |
| 684 | |
| 685 | " CTRL-E shows "<<<DEFG...", cursor move four lines down |
| 686 | exe "normal \<C-E>" |
| 687 | call s:check_col_calc(1, 4, 81) |
| 688 | |
| 689 | " cursor on start of second line, "gk" moves into first line, skipcol doesn't |
| 690 | " change |
| 691 | exe "normal G0gk" |
| 692 | call s:check_col_calc(1, 5, 101) |
| 693 | |
| 694 | " move cursor left one window width worth, scrolls one screen line |
| 695 | exe "normal 20h" |
| 696 | call s:check_col_calc(1, 5, 81) |
| 697 | |
| 698 | " move cursor left one window width worth, scrolls one screen line |
| 699 | exe "normal 20h" |
| 700 | call s:check_col_calc(1, 4, 61) |
| 701 | |
Bram Moolenaar | b21b8e9 | 2022-12-03 18:35:07 +0000 | [diff] [blame] | 702 | " cursor on last line, "gk" should not cause a scroll |
| 703 | set scrolloff=0 |
| 704 | normal G0 |
| 705 | call s:check_col_calc(1, 7, 1) |
| 706 | normal gk |
| 707 | call s:check_col_calc(1, 6, 101) |
| 708 | |
Bram Moolenaar | 1b73edd | 2022-12-03 11:51:54 +0000 | [diff] [blame] | 709 | bwipe! |
| 710 | endfunc |
| 711 | |
| 712 | |
Yee Cheng Chin | e6392b1 | 2022-11-19 14:31:08 +0000 | [diff] [blame] | 713 | " Test that mouse picking is still accurate when we have smooth scrolled lines |
| 714 | func Test_smoothscroll_mouse_pos() |
| 715 | CheckNotGui |
| 716 | CheckUnix |
| 717 | |
| 718 | let save_mouse = &mouse |
| 719 | let save_term = &term |
| 720 | let save_ttymouse = &ttymouse |
| 721 | set mouse=a term=xterm ttymouse=xterm2 |
| 722 | |
| 723 | call NewWindow(10, 20) |
| 724 | setl smoothscroll wrap |
| 725 | " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines. |
| 726 | call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"]) |
| 727 | |
| 728 | func s:check_mouse_click(row, col, buf_row, buf_col) |
| 729 | call MouseLeftClick(a:row, a:col) |
| 730 | |
| 731 | call assert_equal(a:col, wincol()) |
| 732 | call assert_equal(a:row, winline()) |
| 733 | call assert_equal(a:buf_row, line('.')) |
| 734 | call assert_equal(a:buf_col, col('.')) |
| 735 | endfunc |
| 736 | |
| 737 | " Check that clicking without scroll works first. |
| 738 | call s:check_mouse_click(3, 5, 1, 45) |
| 739 | call s:check_mouse_click(4, 1, 2, 1) |
| 740 | call s:check_mouse_click(4, 6, 2, 6) |
| 741 | call s:check_mouse_click(5, 1, 3, 1) |
| 742 | call s:check_mouse_click(5, 6, 3, 6) |
| 743 | |
| 744 | " Smooth scroll, and checks that this didn't mess up mouse clicking |
| 745 | exe "normal \<C-E>" |
| 746 | call s:check_mouse_click(2, 5, 1, 45) |
| 747 | call s:check_mouse_click(3, 1, 2, 1) |
| 748 | call s:check_mouse_click(3, 6, 2, 6) |
| 749 | call s:check_mouse_click(4, 1, 3, 1) |
| 750 | call s:check_mouse_click(4, 6, 3, 6) |
| 751 | |
| 752 | exe "normal \<C-E>" |
| 753 | call s:check_mouse_click(1, 5, 1, 45) |
| 754 | call s:check_mouse_click(2, 1, 2, 1) |
| 755 | call s:check_mouse_click(2, 6, 2, 6) |
| 756 | call s:check_mouse_click(3, 1, 3, 1) |
| 757 | call s:check_mouse_click(3, 6, 3, 6) |
| 758 | |
| 759 | " Make a new first line 11 physical lines tall so it's taller than window |
| 760 | " height, to test overflow calculations with really long lines wrapping. |
| 761 | normal gg |
| 762 | call setline(1, "12345678901234567890"->repeat(11)) |
| 763 | exe "normal 6\<C-E>" |
| 764 | call s:check_mouse_click(5, 1, 1, 201) |
| 765 | call s:check_mouse_click(6, 1, 2, 1) |
| 766 | call s:check_mouse_click(7, 1, 3, 1) |
| 767 | |
| 768 | let &mouse = save_mouse |
| 769 | let &term = save_term |
| 770 | let &ttymouse = save_ttymouse |
zeertzjq | ad493ef | 2024-03-29 10:23:19 +0100 | [diff] [blame] | 771 | bwipe! |
Yee Cheng Chin | e6392b1 | 2022-11-19 14:31:08 +0000 | [diff] [blame] | 772 | endfunc |
| 773 | |
Bram Moolenaar | 870219c | 2023-01-26 14:14:43 +0000 | [diff] [blame] | 774 | " this was dividing by zero |
Luuk van Baal | c8502f9 | 2023-05-06 12:40:15 +0100 | [diff] [blame] | 775 | func Test_smoothscroll_zero_width() |
Bram Moolenaar | 870219c | 2023-01-26 14:14:43 +0000 | [diff] [blame] | 776 | CheckScreendump |
| 777 | |
| 778 | let lines =<< trim END |
| 779 | winsize 0 0 |
| 780 | vsplit |
| 781 | vsplit |
| 782 | vsplit |
| 783 | vsplit |
| 784 | vsplit |
| 785 | sil norm H |
| 786 | set wrap |
| 787 | set smoothscroll |
| 788 | set number |
| 789 | END |
| 790 | call writefile(lines, 'XSmoothScrollZero', 'D') |
| 791 | 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] | 792 | call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {}) |
| 793 | |
| 794 | call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>") |
| 795 | call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {}) |
| 796 | |
| 797 | call StopVimInTerminal(buf) |
| 798 | endfunc |
| 799 | |
Luuk van Baal | c8502f9 | 2023-05-06 12:40:15 +0100 | [diff] [blame] | 800 | " this was unnecessarily inserting lines |
| 801 | func Test_smoothscroll_ins_lines() |
| 802 | CheckScreendump |
| 803 | |
| 804 | let lines =<< trim END |
| 805 | set wrap |
| 806 | set smoothscroll |
| 807 | set scrolloff=0 |
| 808 | set conceallevel=2 |
| 809 | call setline(1, [ |
| 810 | \'line one' .. 'with lots of text in one line '->repeat(2), |
| 811 | \'line two', |
| 812 | \'line three', |
| 813 | \'line four', |
| 814 | \'line five' |
| 815 | \]) |
| 816 | END |
| 817 | call writefile(lines, 'XSmoothScrollInsLines', 'D') |
| 818 | let buf = RunVimInTerminal('-S XSmoothScrollInsLines', #{rows: 6, cols: 40}) |
| 819 | |
| 820 | call term_sendkeys(buf, "\<C-E>gjgk") |
| 821 | call VerifyScreenDump(buf, 'Test_smooth_ins_lines', {}) |
| 822 | |
| 823 | call StopVimInTerminal(buf) |
| 824 | endfunc |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 825 | |
Luuk van Baal | 3ce8c38 | 2023-05-08 15:51:14 +0100 | [diff] [blame] | 826 | " this placed the cursor in the command line |
| 827 | func Test_smoothscroll_cursormoved_line() |
| 828 | CheckScreendump |
| 829 | |
| 830 | let lines =<< trim END |
| 831 | set smoothscroll |
| 832 | call setline(1, [ |
| 833 | \'', |
| 834 | \'_'->repeat(&lines * &columns), |
| 835 | \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2) |
| 836 | \]) |
| 837 | autocmd CursorMoved * eval [line('w0'), line('w$')] |
| 838 | call search('xxx') |
| 839 | END |
| 840 | call writefile(lines, 'XSmoothCursorMovedLine', 'D') |
| 841 | let buf = RunVimInTerminal('-S XSmoothCursorMovedLine', #{rows: 6}) |
| 842 | |
| 843 | call VerifyScreenDump(buf, 'Test_smooth_cursormoved_line', {}) |
| 844 | |
| 845 | call StopVimInTerminal(buf) |
| 846 | endfunc |
| 847 | |
| 848 | func Test_smoothscroll_eob() |
| 849 | CheckScreendump |
| 850 | |
| 851 | let lines =<< trim END |
| 852 | set smoothscroll |
| 853 | call setline(1, ['']->repeat(100)) |
| 854 | norm G |
| 855 | END |
| 856 | call writefile(lines, 'XSmoothEob', 'D') |
| 857 | let buf = RunVimInTerminal('-S XSmoothEob', #{rows: 10}) |
| 858 | |
| 859 | " does not scroll halfway when scrolling to end of buffer |
| 860 | call VerifyScreenDump(buf, 'Test_smooth_eob_1', {}) |
| 861 | |
| 862 | " cursor is not placed below window |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 863 | 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] | 864 | call VerifyScreenDump(buf, 'Test_smooth_eob_2', {}) |
| 865 | |
| 866 | call StopVimInTerminal(buf) |
| 867 | endfunc |
| 868 | |
Luuk van Baal | d49f646 | 2023-05-19 14:04:47 +0100 | [diff] [blame] | 869 | " skipcol should not reset when doing incremental search on the same word |
| 870 | func Test_smoothscroll_incsearch() |
| 871 | CheckScreendump |
| 872 | |
| 873 | let lines =<< trim END |
| 874 | set smoothscroll number scrolloff=0 incsearch |
| 875 | call setline(1, repeat([''], 20)) |
| 876 | call setline(11, repeat('a', 100)) |
| 877 | call setline(14, 'bbbb') |
| 878 | END |
| 879 | call writefile(lines, 'XSmoothIncsearch', 'D') |
zeertzjq | 3c80227 | 2023-06-03 22:08:33 +0100 | [diff] [blame] | 880 | let buf = RunVimInTerminal('-S XSmoothIncsearch', #{rows: 8, cols: 40}) |
Luuk van Baal | d49f646 | 2023-05-19 14:04:47 +0100 | [diff] [blame] | 881 | |
| 882 | call term_sendkeys(buf, "/b") |
| 883 | call VerifyScreenDump(buf, 'Test_smooth_incsearch_1', {}) |
| 884 | call term_sendkeys(buf, "b") |
| 885 | call VerifyScreenDump(buf, 'Test_smooth_incsearch_2', {}) |
| 886 | call term_sendkeys(buf, "b") |
| 887 | call VerifyScreenDump(buf, 'Test_smooth_incsearch_3', {}) |
| 888 | call term_sendkeys(buf, "b") |
| 889 | call VerifyScreenDump(buf, 'Test_smooth_incsearch_4', {}) |
| 890 | call term_sendkeys(buf, "\<CR>") |
| 891 | |
| 892 | call StopVimInTerminal(buf) |
| 893 | endfunc |
| 894 | |
zeertzjq | 3c80227 | 2023-06-03 22:08:33 +0100 | [diff] [blame] | 895 | " Test scrolling multiple lines and stopping at non-zero skipcol. |
| 896 | func Test_smoothscroll_multi_skipcol() |
| 897 | CheckScreendump |
| 898 | |
| 899 | let lines =<< trim END |
| 900 | setlocal cursorline scrolloff=0 smoothscroll |
zeertzjq | d9a92dc | 2023-06-05 18:41:35 +0100 | [diff] [blame] | 901 | call setline(1, repeat([''], 8)) |
zeertzjq | 3c80227 | 2023-06-03 22:08:33 +0100 | [diff] [blame] | 902 | call setline(3, repeat('a', 50)) |
zeertzjq | d9a92dc | 2023-06-05 18:41:35 +0100 | [diff] [blame] | 903 | call setline(4, repeat('a', 50)) |
| 904 | call setline(7, 'bbb') |
| 905 | call setline(8, 'ccc') |
zeertzjq | 3c80227 | 2023-06-03 22:08:33 +0100 | [diff] [blame] | 906 | redraw |
| 907 | END |
| 908 | call writefile(lines, 'XSmoothMultiSkipcol', 'D') |
| 909 | let buf = RunVimInTerminal('-S XSmoothMultiSkipcol', #{rows: 10, cols: 40}) |
| 910 | call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_1', {}) |
| 911 | |
| 912 | call term_sendkeys(buf, "3\<C-E>") |
| 913 | call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_2', {}) |
| 914 | |
zeertzjq | d9a92dc | 2023-06-05 18:41:35 +0100 | [diff] [blame] | 915 | call term_sendkeys(buf, "2\<C-E>") |
| 916 | call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_3', {}) |
| 917 | |
zeertzjq | 3c80227 | 2023-06-03 22:08:33 +0100 | [diff] [blame] | 918 | call StopVimInTerminal(buf) |
| 919 | endfunc |
| 920 | |
fullwaywang | 8154e64 | 2023-06-24 21:58:09 +0100 | [diff] [blame] | 921 | " this was dividing by zero bug in scroll_cursor_bot |
| 922 | func Test_smoothscroll_zero_width_scroll_cursor_bot() |
| 923 | CheckScreendump |
| 924 | |
| 925 | let lines =<< trim END |
| 926 | silent normal yy |
| 927 | silent normal 19p |
zeertzjq | e429893 | 2023-06-26 19:02:43 +0100 | [diff] [blame] | 928 | set cpoptions+=n |
fullwaywang | 8154e64 | 2023-06-24 21:58:09 +0100 | [diff] [blame] | 929 | vsplit |
| 930 | vertical resize 0 |
| 931 | set foldcolumn=1 |
| 932 | set number |
| 933 | set smoothscroll |
| 934 | silent normal 20G |
| 935 | END |
| 936 | call writefile(lines, 'XSmoothScrollZeroBot', 'D') |
zeertzjq | e429893 | 2023-06-26 19:02:43 +0100 | [diff] [blame] | 937 | let buf = RunVimInTerminal('-u NONE -S XSmoothScrollZeroBot', #{rows: 19}) |
fullwaywang | 8154e64 | 2023-06-24 21:58:09 +0100 | [diff] [blame] | 938 | call VerifyScreenDump(buf, 'Test_smoothscroll_zero_bot', {}) |
| 939 | |
| 940 | call StopVimInTerminal(buf) |
| 941 | endfunc |
| 942 | |
Luuk van Baal | bb800a7 | 2023-11-14 17:05:18 +0100 | [diff] [blame] | 943 | " scroll_cursor_top() should reset skipcol when it changes topline |
| 944 | func Test_smoothscroll_cursor_top() |
| 945 | CheckScreendump |
| 946 | |
| 947 | let lines =<< trim END |
| 948 | set smoothscroll scrolloff=2 |
| 949 | new | 11resize | wincmd j |
| 950 | call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4']) |
| 951 | exe "norm G3\<C-E>k" |
| 952 | END |
| 953 | call writefile(lines, 'XSmoothScrollCursorTop', 'D') |
zeertzjq | 5b4d1fc | 2023-12-03 17:54:10 +0100 | [diff] [blame] | 954 | let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCursorTop', #{rows: 12, cols: 40}) |
Luuk van Baal | bb800a7 | 2023-11-14 17:05:18 +0100 | [diff] [blame] | 955 | call VerifyScreenDump(buf, 'Test_smoothscroll_cursor_top', {}) |
| 956 | |
| 957 | call StopVimInTerminal(buf) |
| 958 | endfunc |
| 959 | |
Christian Brabandt | cb0b99f | 2023-11-14 20:05:59 +0100 | [diff] [blame] | 960 | " Division by zero, shouldn't crash |
| 961 | func Test_smoothscroll_crash() |
| 962 | CheckScreendump |
| 963 | |
| 964 | let lines =<< trim END |
| 965 | 20 new |
| 966 | vsp |
| 967 | put =repeat('aaaa', 20) |
| 968 | set nu fdc=1 smoothscroll cpo+=n |
| 969 | vert resize 0 |
| 970 | exe "norm! 0\<c-e>" |
| 971 | END |
| 972 | call writefile(lines, 'XSmoothScrollCrash', 'D') |
zeertzjq | 5b4d1fc | 2023-12-03 17:54:10 +0100 | [diff] [blame] | 973 | let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCrash', #{rows: 12, cols: 40}) |
Christian Brabandt | cb0b99f | 2023-11-14 20:05:59 +0100 | [diff] [blame] | 974 | call term_sendkeys(buf, "2\<C-E>\<C-L>") |
| 975 | |
| 976 | call StopVimInTerminal(buf) |
| 977 | endfunc |
| 978 | |
zeertzjq | 5b4d1fc | 2023-12-03 17:54:10 +0100 | [diff] [blame] | 979 | func Test_smoothscroll_insert_bottom() |
| 980 | CheckScreendump |
| 981 | |
| 982 | let lines =<< trim END |
| 983 | call setline(1, repeat([repeat('A very long line ...', 10)], 5)) |
| 984 | set wrap smoothscroll scrolloff=0 |
| 985 | END |
| 986 | call writefile(lines, 'XSmoothScrollInsertBottom', 'D') |
| 987 | let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInsertBottom', #{rows: 9, cols: 40}) |
| 988 | call term_sendkeys(buf, "Go123456789\<CR>") |
| 989 | call VerifyScreenDump(buf, 'Test_smoothscroll_insert_bottom', {}) |
| 990 | |
| 991 | call StopVimInTerminal(buf) |
| 992 | endfunc |
| 993 | |
zeertzjq | c7a8eb5 | 2024-05-08 20:22:40 +0200 | [diff] [blame] | 994 | func Test_smoothscroll_in_qf_window() |
| 995 | CheckFeature quickfix |
| 996 | CheckScreendump |
| 997 | |
| 998 | let lines =<< trim END |
| 999 | set nocompatible display=lastline |
| 1000 | copen 5 |
| 1001 | setlocal number smoothscroll |
| 1002 | let g:l = [{'text': 'foo'}] + repeat([{'text': join(range(30))}], 10) |
| 1003 | call setqflist(g:l, 'r') |
| 1004 | normal! G |
| 1005 | wincmd t |
| 1006 | let g:l1 = [{'text': join(range(1000))}] |
| 1007 | END |
| 1008 | call writefile(lines, 'XSmoothScrollInQfWindow', 'D') |
| 1009 | let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInQfWindow', #{rows: 20, cols: 60}) |
| 1010 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_1', {}) |
| 1011 | |
| 1012 | call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>") |
| 1013 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {}) |
| 1014 | |
| 1015 | call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>") |
| 1016 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {}) |
| 1017 | |
| 1018 | call term_sendkeys(buf, ":call setqflist(g:l1, 'r')\<CR>") |
| 1019 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_4', {}) |
| 1020 | |
| 1021 | call term_sendkeys(buf, "\<C-W>b$\<C-W>t") |
| 1022 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_5', {}) |
| 1023 | |
| 1024 | call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>") |
| 1025 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {}) |
| 1026 | |
| 1027 | call term_sendkeys(buf, ":call setqflist(g:l1, 'r')\<CR>") |
| 1028 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_4', {}) |
| 1029 | |
| 1030 | call term_sendkeys(buf, "\<C-W>b$\<C-W>t") |
| 1031 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_5', {}) |
| 1032 | |
| 1033 | call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>") |
| 1034 | call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {}) |
| 1035 | |
| 1036 | call StopVimInTerminal(buf) |
| 1037 | endfunc |
| 1038 | |
Sean Dewar | 02fcae0 | 2024-02-21 19:40:44 +0100 | [diff] [blame] | 1039 | func Test_smoothscroll_in_zero_width_window() |
| 1040 | set cpo+=n number smoothscroll |
| 1041 | set winwidth=99999 winminwidth=0 |
| 1042 | |
| 1043 | vsplit |
| 1044 | call assert_equal(0, winwidth(winnr('#'))) |
| 1045 | call win_execute(win_getid(winnr('#')), "norm! \<C-Y>") |
| 1046 | |
| 1047 | only! |
| 1048 | set winwidth& winminwidth& |
| 1049 | set cpo-=n nonumber nosmoothscroll |
| 1050 | endfunc |
| 1051 | |
| 1052 | func Test_smoothscroll_textoff_small_winwidth() |
| 1053 | set smoothscroll number |
| 1054 | call setline(1, 'llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch') |
| 1055 | vsplit |
| 1056 | |
| 1057 | let textoff = getwininfo(win_getid())[0].textoff |
| 1058 | execute 'vertical resize' textoff + 1 |
| 1059 | redraw |
| 1060 | call assert_equal(0, winsaveview().skipcol) |
| 1061 | execute "normal! 0\<C-E>" |
| 1062 | redraw |
| 1063 | call assert_equal(1, winsaveview().skipcol) |
| 1064 | execute 'vertical resize' textoff - 1 |
| 1065 | " This caused a signed integer overflow. |
| 1066 | redraw |
| 1067 | call assert_equal(1, winsaveview().skipcol) |
| 1068 | execute 'vertical resize' textoff |
| 1069 | " This caused an infinite loop. |
| 1070 | redraw |
| 1071 | call assert_equal(1, winsaveview().skipcol) |
| 1072 | |
| 1073 | %bw! |
| 1074 | set smoothscroll& number& |
| 1075 | endfunc |
| 1076 | |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1077 | func Test_smoothscroll_page() |
zeertzjq | ad493ef | 2024-03-29 10:23:19 +0100 | [diff] [blame] | 1078 | call NewWindow(10, 40) |
| 1079 | setlocal smoothscroll |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1080 | call setline(1, 'abcde '->repeat(150)) |
| 1081 | |
| 1082 | exe "norm! \<C-F>" |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1083 | call assert_equal(400, winsaveview().skipcol) |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1084 | exe "norm! \<C-F>" |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1085 | call assert_equal(800, winsaveview().skipcol) |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1086 | exe "norm! \<C-F>" |
| 1087 | call assert_equal(880, winsaveview().skipcol) |
| 1088 | exe "norm! \<C-B>" |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1089 | call assert_equal(480, winsaveview().skipcol) |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1090 | exe "norm! \<C-B>" |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1091 | call assert_equal(80, winsaveview().skipcol) |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1092 | exe "norm! \<C-B>" |
| 1093 | call assert_equal(0, winsaveview().skipcol) |
| 1094 | |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1095 | " 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] | 1096 | " Even with 'nostartofline', the correct amount of lines is scrolled. |
| 1097 | setl nostartofline |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1098 | exe "norm! 15|\<C-D>" |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1099 | call assert_equal(200, winsaveview().skipcol) |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1100 | call assert_equal(215, col('.')) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1101 | exe "norm! \<C-D>" |
| 1102 | call assert_equal(400, winsaveview().skipcol) |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1103 | call assert_equal(415, col('.')) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1104 | exe "norm! \<C-D>" |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1105 | call assert_equal(520, winsaveview().skipcol) |
Luuk van Baal | 78c5150 | 2024-04-09 21:30:19 +0200 | [diff] [blame] | 1106 | call assert_equal(615, col('.')) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1107 | exe "norm! \<C-D>" |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1108 | call assert_equal(520, winsaveview().skipcol) |
Luuk van Baal | 78c5150 | 2024-04-09 21:30:19 +0200 | [diff] [blame] | 1109 | call assert_equal(815, col('.')) |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1110 | exe "norm! \<C-D>" |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1111 | call assert_equal(520, winsaveview().skipcol) |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1112 | call assert_equal(895, col('.')) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1113 | exe "norm! \<C-U>" |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1114 | call assert_equal(320, winsaveview().skipcol) |
| 1115 | call assert_equal(695, col('.')) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1116 | exe "norm! \<C-U>" |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1117 | call assert_equal(120, winsaveview().skipcol) |
| 1118 | call assert_equal(495, col('.')) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1119 | exe "norm! \<C-U>" |
| 1120 | call assert_equal(0, winsaveview().skipcol) |
Luuk van Baal | 78c5150 | 2024-04-09 21:30:19 +0200 | [diff] [blame] | 1121 | call assert_equal(295, col('.')) |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1122 | exe "norm! \<C-U>" |
| 1123 | call assert_equal(0, winsaveview().skipcol) |
Luuk van Baal | 78c5150 | 2024-04-09 21:30:19 +0200 | [diff] [blame] | 1124 | call assert_equal(95, col('.')) |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1125 | exe "norm! \<C-U>" |
| 1126 | call assert_equal(0, winsaveview().skipcol) |
| 1127 | call assert_equal(15, col('.')) |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1128 | |
| 1129 | bwipe! |
| 1130 | endfunc |
| 1131 | |
| 1132 | func Test_smoothscroll_next_topline() |
| 1133 | call NewWindow(10, 40) |
| 1134 | setlocal smoothscroll |
| 1135 | call setline(1, ['abcde '->repeat(150)]->repeat(2)) |
| 1136 | |
| 1137 | " Scrolling a screenline that causes the cursor to move to the next buffer |
| 1138 | " line should not skip part of that line to bring the cursor into view. |
| 1139 | exe "norm! 22\<C-E>" |
| 1140 | call assert_equal(880, winsaveview().skipcol) |
| 1141 | exe "norm! \<C-E>" |
| 1142 | redraw |
| 1143 | call assert_equal(0, winsaveview().skipcol) |
| 1144 | |
Luuk van Baal | bd28cae | 2024-04-03 22:50:40 +0200 | [diff] [blame] | 1145 | " Also when scrolling back. |
| 1146 | exe "norm! G\<C-Y>" |
| 1147 | redraw |
| 1148 | call assert_equal(880, winsaveview().skipcol) |
| 1149 | |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1150 | " Cursor in correct place when not in the first screenline of a buffer line. |
| 1151 | exe "norm! gg4gj20\<C-D>\<C-D>" |
| 1152 | redraw |
| 1153 | call assert_equal(2, line('w0')) |
| 1154 | |
Luuk van Baal | 9148ba8 | 2024-04-08 22:27:41 +0200 | [diff] [blame] | 1155 | " Cursor does not end up above topline, adjusting topline later. |
| 1156 | setlocal nu cpo+=n |
| 1157 | exe "norm! G$g013\<C-Y>" |
| 1158 | redraw |
| 1159 | call assert_equal(2, line('.')) |
| 1160 | call assert_equal(0, winsaveview().skipcol) |
| 1161 | |
| 1162 | set cpo-=n |
Luuk van Baal | cb204e6 | 2024-04-02 20:49:45 +0200 | [diff] [blame] | 1163 | bwipe! |
| 1164 | endfunc |
| 1165 | |
| 1166 | func Test_smoothscroll_long_line_zb() |
| 1167 | call NewWindow(10, 40) |
| 1168 | call setline(1, 'abcde '->repeat(150)) |
| 1169 | |
| 1170 | " Also works without 'smoothscroll' when last line of buffer doesn't fit. |
| 1171 | " Used to set topline to buffer line count plus one, causing an empty screen. |
| 1172 | norm zb |
| 1173 | redraw |
| 1174 | call assert_equal(1, winsaveview().topline) |
| 1175 | |
| 1176 | " Moving cursor to bottom works on line that doesn't fit with 'smoothscroll'. |
| 1177 | " Skipcol was adjusted later for cursor being on not visible part of line. |
| 1178 | setlocal smoothscroll |
| 1179 | norm zb |
| 1180 | redraw |
| 1181 | call assert_equal(520, winsaveview().skipcol) |
Luuk van Baal | 5a2e3ec | 2024-03-28 10:07:29 +0100 | [diff] [blame] | 1182 | |
zeertzjq | ad493ef | 2024-03-29 10:23:19 +0100 | [diff] [blame] | 1183 | bwipe! |
Luuk van Baal | b9f5b95 | 2024-03-26 18:46:45 +0100 | [diff] [blame] | 1184 | endfunc |
| 1185 | |
Luuk van Baal | b32055e | 2024-05-16 20:44:09 +0200 | [diff] [blame] | 1186 | func Test_smooth_long_scrolloff() |
| 1187 | CheckScreendump |
| 1188 | |
| 1189 | let lines =<< trim END |
| 1190 | set smoothscroll scrolloff=3 |
Luuk van Baal | 2e64273 | 2024-05-17 18:25:13 +0200 | [diff] [blame] | 1191 | call setline(1, ['one', 'two long '->repeat(100), 'three', 'four', 'five', 'six']) |
Luuk van Baal | b32055e | 2024-05-16 20:44:09 +0200 | [diff] [blame] | 1192 | END |
| 1193 | call writefile(lines, 'XSmoothLongScrolloff', 'D') |
| 1194 | let buf = RunVimInTerminal('-u NONE -S XSmoothLongScrolloff', #{rows: 8, cols: 40}) |
Luuk van Baal | 2e64273 | 2024-05-17 18:25:13 +0200 | [diff] [blame] | 1195 | call term_sendkeys(buf, ":norm j721|\<CR>") |
Luuk van Baal | b32055e | 2024-05-16 20:44:09 +0200 | [diff] [blame] | 1196 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_1', {}) |
| 1197 | |
| 1198 | call term_sendkeys(buf, "gj") |
| 1199 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_2', {}) |
| 1200 | |
| 1201 | call term_sendkeys(buf, "gj") |
| 1202 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_3', {}) |
| 1203 | |
| 1204 | call term_sendkeys(buf, "gj") |
| 1205 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_4', {}) |
| 1206 | |
| 1207 | call term_sendkeys(buf, "gj") |
| 1208 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_5', {}) |
| 1209 | |
| 1210 | call term_sendkeys(buf, "gj") |
| 1211 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_6', {}) |
| 1212 | |
| 1213 | call term_sendkeys(buf, "gk") |
Luuk van Baal | b32055e | 2024-05-16 20:44:09 +0200 | [diff] [blame] | 1214 | call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_7', {}) |
| 1215 | |
| 1216 | call StopVimInTerminal(buf) |
| 1217 | endfunc |
| 1218 | |
zeertzjq | 2c47ab8 | 2025-02-13 20:34:34 +0100 | [diff] [blame^] | 1219 | func Test_smoothscroll_listchars_eol() |
| 1220 | call NewWindow(10, 40) |
| 1221 | setlocal list listchars=eol:$ scrolloff=0 smoothscroll |
| 1222 | call setline(1, repeat('-', 40)) |
| 1223 | call append(1, repeat(['foobar'], 10)) |
| 1224 | |
| 1225 | normal! G |
| 1226 | call assert_equal(2, line('w0')) |
| 1227 | call assert_equal(0, winsaveview().skipcol) |
| 1228 | |
| 1229 | exe "normal! \<C-Y>" |
| 1230 | call assert_equal(1, line('w0')) |
| 1231 | call assert_equal(40, winsaveview().skipcol) |
| 1232 | |
| 1233 | exe "normal! \<C-Y>" |
| 1234 | call assert_equal(1, line('w0')) |
| 1235 | call assert_equal(0, winsaveview().skipcol) |
| 1236 | |
| 1237 | exe "normal! \<C-Y>" |
| 1238 | call assert_equal(1, line('w0')) |
| 1239 | call assert_equal(0, winsaveview().skipcol) |
| 1240 | |
| 1241 | exe "normal! \<C-E>" |
| 1242 | call assert_equal(1, line('w0')) |
| 1243 | call assert_equal(40, winsaveview().skipcol) |
| 1244 | |
| 1245 | exe "normal! \<C-E>" |
| 1246 | call assert_equal(2, line('w0')) |
| 1247 | call assert_equal(0, winsaveview().skipcol) |
| 1248 | |
| 1249 | for ve in ['', 'all', 'onemore'] |
| 1250 | let &virtualedit = ve |
| 1251 | normal! gg |
| 1252 | call assert_equal(1, line('w0')) |
| 1253 | call assert_equal(0, winsaveview().skipcol) |
| 1254 | |
| 1255 | exe "normal! \<C-E>" |
| 1256 | redraw " redrawing should not cause another scroll |
| 1257 | call assert_equal(1, line('w0')) |
| 1258 | call assert_equal(40, winsaveview().skipcol) |
| 1259 | |
| 1260 | exe "normal! \<C-E>" |
| 1261 | redraw |
| 1262 | call assert_equal(2, line('w0')) |
| 1263 | call assert_equal(0, winsaveview().skipcol) |
| 1264 | |
| 1265 | if ve != 'all' |
| 1266 | call assert_equal([0, 2, 1, 0], getpos('.')) |
| 1267 | endif |
| 1268 | endfor |
| 1269 | |
| 1270 | set virtualedit& |
| 1271 | bwipe! |
| 1272 | endfunc |
| 1273 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1274 | " vim: shiftwidth=2 sts=2 expandtab |