Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 1 | " Test for reset 'scroll' and 'smoothscroll' |
| 2 | |
| 3 | source check.vim |
| 4 | source screendump.vim |
Bram Moolenaar | af2d20c | 2017-10-29 15:26:57 +0100 | [diff] [blame] | 5 | |
| 6 | func Test_reset_scroll() |
| 7 | let scr = &l:scroll |
| 8 | |
| 9 | setlocal scroll=1 |
| 10 | setlocal scroll& |
| 11 | call assert_equal(scr, &l:scroll) |
| 12 | |
| 13 | setlocal scroll=1 |
| 14 | setlocal scroll=0 |
| 15 | call assert_equal(scr, &l:scroll) |
| 16 | |
| 17 | try |
| 18 | execute 'setlocal scroll=' . (winheight(0) + 1) |
| 19 | " not reached |
| 20 | call assert_false(1) |
| 21 | catch |
| 22 | call assert_exception('E49:') |
| 23 | endtry |
| 24 | |
| 25 | split |
| 26 | |
| 27 | let scr = &l:scroll |
| 28 | |
| 29 | setlocal scroll=1 |
| 30 | setlocal scroll& |
| 31 | call assert_equal(scr, &l:scroll) |
| 32 | |
| 33 | setlocal scroll=1 |
| 34 | setlocal scroll=0 |
| 35 | call assert_equal(scr, &l:scroll) |
| 36 | |
| 37 | quit! |
| 38 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 39 | |
Bram Moolenaar | 8df9748 | 2022-10-03 12:11:13 +0100 | [diff] [blame] | 40 | func Test_CtrlE_CtrlY_stop_at_end() |
| 41 | enew |
| 42 | call setline(1, ['one', 'two']) |
| 43 | set number |
| 44 | exe "normal \<C-Y>" |
| 45 | call assert_equal([" 1 one "], ScreenLines(1, 10)) |
| 46 | exe "normal \<C-E>\<C-E>\<C-E>" |
| 47 | call assert_equal([" 2 two "], ScreenLines(1, 10)) |
| 48 | |
| 49 | bwipe! |
| 50 | set nonumber |
| 51 | endfunc |
| 52 | |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 53 | func Test_smoothscroll_CtrlE_CtrlY() |
| 54 | CheckScreendump |
| 55 | |
| 56 | let lines =<< trim END |
| 57 | vim9script |
| 58 | setline(1, [ |
| 59 | 'line one', |
| 60 | 'word '->repeat(20), |
| 61 | 'line three', |
| 62 | 'long word '->repeat(7), |
| 63 | 'line', |
| 64 | 'line', |
| 65 | 'line', |
| 66 | ]) |
| 67 | set smoothscroll |
| 68 | :5 |
| 69 | END |
| 70 | call writefile(lines, 'XSmoothScroll', 'D') |
| 71 | let buf = RunVimInTerminal('-S XSmoothScroll', #{rows: 12, cols: 40}) |
| 72 | |
| 73 | call term_sendkeys(buf, "\<C-E>") |
| 74 | call VerifyScreenDump(buf, 'Test_smoothscroll_1', {}) |
| 75 | call term_sendkeys(buf, "\<C-E>") |
| 76 | call VerifyScreenDump(buf, 'Test_smoothscroll_2', {}) |
| 77 | call term_sendkeys(buf, "\<C-E>") |
| 78 | call VerifyScreenDump(buf, 'Test_smoothscroll_3', {}) |
| 79 | call term_sendkeys(buf, "\<C-E>") |
| 80 | call VerifyScreenDump(buf, 'Test_smoothscroll_4', {}) |
| 81 | |
| 82 | call term_sendkeys(buf, "\<C-Y>") |
| 83 | call VerifyScreenDump(buf, 'Test_smoothscroll_5', {}) |
| 84 | call term_sendkeys(buf, "\<C-Y>") |
| 85 | call VerifyScreenDump(buf, 'Test_smoothscroll_6', {}) |
| 86 | call term_sendkeys(buf, "\<C-Y>") |
| 87 | call VerifyScreenDump(buf, 'Test_smoothscroll_7', {}) |
| 88 | call term_sendkeys(buf, "\<C-Y>") |
| 89 | call VerifyScreenDump(buf, 'Test_smoothscroll_8', {}) |
| 90 | |
Bram Moolenaar | 6b2d4ff | 2022-10-03 14:06:02 +0100 | [diff] [blame] | 91 | if has('folding') |
| 92 | call term_sendkeys(buf, ":set foldmethod=indent\<CR>") |
| 93 | " move the cursor so we can reuse the same dumps |
| 94 | call term_sendkeys(buf, "5G") |
| 95 | call term_sendkeys(buf, "\<C-E>") |
| 96 | call VerifyScreenDump(buf, 'Test_smoothscroll_1', {}) |
| 97 | call term_sendkeys(buf, "\<C-E>") |
| 98 | call VerifyScreenDump(buf, 'Test_smoothscroll_2', {}) |
| 99 | call term_sendkeys(buf, "7G") |
| 100 | call term_sendkeys(buf, "\<C-Y>") |
| 101 | call VerifyScreenDump(buf, 'Test_smoothscroll_7', {}) |
| 102 | call term_sendkeys(buf, "\<C-Y>") |
| 103 | call VerifyScreenDump(buf, 'Test_smoothscroll_8', {}) |
| 104 | endif |
| 105 | |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 106 | call StopVimInTerminal(buf) |
| 107 | endfunc |
| 108 | |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 109 | func Test_smoothscroll_number() |
| 110 | CheckScreendump |
| 111 | |
| 112 | let lines =<< trim END |
| 113 | vim9script |
| 114 | setline(1, [ |
| 115 | 'one ' .. 'word '->repeat(20), |
| 116 | 'two ' .. 'long word '->repeat(7), |
| 117 | 'line', |
| 118 | 'line', |
| 119 | 'line', |
| 120 | ]) |
| 121 | set smoothscroll |
| 122 | set number cpo+=n |
| 123 | :3 |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 124 | |
| 125 | def g:DoRel() |
| 126 | set number relativenumber scrolloff=0 |
| 127 | :%del |
| 128 | setline(1, [ |
| 129 | 'one', |
| 130 | 'very long text '->repeat(12), |
| 131 | 'three', |
| 132 | ]) |
| 133 | exe "normal 2Gzt\<C-E>" |
| 134 | enddef |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 135 | END |
| 136 | call writefile(lines, 'XSmoothNumber', 'D') |
| 137 | let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40}) |
| 138 | |
| 139 | call VerifyScreenDump(buf, 'Test_smooth_number_1', {}) |
| 140 | call term_sendkeys(buf, "\<C-E>") |
| 141 | call VerifyScreenDump(buf, 'Test_smooth_number_2', {}) |
| 142 | call term_sendkeys(buf, "\<C-E>") |
| 143 | call VerifyScreenDump(buf, 'Test_smooth_number_3', {}) |
| 144 | |
| 145 | call term_sendkeys(buf, ":set cpo-=n\<CR>") |
| 146 | call VerifyScreenDump(buf, 'Test_smooth_number_4', {}) |
| 147 | call term_sendkeys(buf, "\<C-Y>") |
| 148 | call VerifyScreenDump(buf, 'Test_smooth_number_5', {}) |
| 149 | call term_sendkeys(buf, "\<C-Y>") |
| 150 | call VerifyScreenDump(buf, 'Test_smooth_number_6', {}) |
| 151 | |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 152 | call term_sendkeys(buf, ":call DoRel()\<CR>") |
| 153 | call VerifyScreenDump(buf, 'Test_smooth_number_7', {}) |
| 154 | |
Bram Moolenaar | b6aab8f | 2022-10-03 20:01:16 +0100 | [diff] [blame] | 155 | call StopVimInTerminal(buf) |
| 156 | endfunc |
| 157 | |
Bram Moolenaar | 13cdde3 | 2022-10-15 14:07:48 +0100 | [diff] [blame] | 158 | func Test_smoothscroll_list() |
| 159 | CheckScreendump |
| 160 | |
| 161 | let lines =<< trim END |
| 162 | vim9script |
| 163 | set smoothscroll scrolloff=0 |
| 164 | set list |
| 165 | setline(1, [ |
| 166 | 'one', |
| 167 | 'very long text '->repeat(12), |
| 168 | 'three', |
| 169 | ]) |
| 170 | exe "normal 2Gzt\<C-E>" |
| 171 | END |
| 172 | call writefile(lines, 'XSmoothList', 'D') |
| 173 | let buf = RunVimInTerminal('-S XSmoothList', #{rows: 8, cols: 40}) |
| 174 | |
| 175 | call VerifyScreenDump(buf, 'Test_smooth_list_1', {}) |
| 176 | |
| 177 | call term_sendkeys(buf, ":set listchars+=precedes:#\<CR>") |
| 178 | call VerifyScreenDump(buf, 'Test_smooth_list_2', {}) |
| 179 | |
| 180 | call StopVimInTerminal(buf) |
| 181 | endfunc |
| 182 | |
Bram Moolenaar | 1a58e1d | 2022-10-06 13:09:17 +0100 | [diff] [blame] | 183 | func Test_smoothscroll_diff_mode() |
| 184 | CheckScreendump |
| 185 | |
| 186 | let lines =<< trim END |
| 187 | vim9script |
| 188 | var text = 'just some text here' |
| 189 | setline(1, text) |
| 190 | set smoothscroll |
| 191 | diffthis |
| 192 | new |
| 193 | setline(1, text) |
| 194 | set smoothscroll |
| 195 | diffthis |
| 196 | END |
| 197 | call writefile(lines, 'XSmoothDiff', 'D') |
| 198 | let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8}) |
| 199 | |
| 200 | call VerifyScreenDump(buf, 'Test_smooth_diff_1', {}) |
| 201 | call term_sendkeys(buf, "\<C-Y>") |
| 202 | call VerifyScreenDump(buf, 'Test_smooth_diff_1', {}) |
| 203 | call term_sendkeys(buf, "\<C-E>") |
| 204 | call VerifyScreenDump(buf, 'Test_smooth_diff_1', {}) |
| 205 | |
| 206 | call StopVimInTerminal(buf) |
| 207 | endfunc |
| 208 | |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 209 | func Test_smoothscroll_wrap_scrolloff_zero() |
| 210 | CheckScreendump |
| 211 | |
| 212 | let lines =<< trim END |
| 213 | vim9script |
| 214 | setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7)) |
| 215 | set smoothscroll scrolloff=0 |
| 216 | :3 |
| 217 | END |
| 218 | call writefile(lines, 'XSmoothWrap', 'D') |
| 219 | let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40}) |
| 220 | |
| 221 | call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {}) |
| 222 | |
Bram Moolenaar | 46b5474 | 2022-10-06 15:46:49 +0100 | [diff] [blame] | 223 | " moving cursor down - whole bottom line shows |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 224 | call term_sendkeys(buf, "j") |
| 225 | call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {}) |
| 226 | |
| 227 | call term_sendkeys(buf, "\<C-E>j") |
| 228 | call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {}) |
| 229 | |
| 230 | call term_sendkeys(buf, "G") |
| 231 | call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {}) |
| 232 | |
Bram Moolenaar | 46b5474 | 2022-10-06 15:46:49 +0100 | [diff] [blame] | 233 | " moving cursor up - whole top line shows |
| 234 | call term_sendkeys(buf, "2k") |
| 235 | call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {}) |
| 236 | |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 237 | call StopVimInTerminal(buf) |
| 238 | endfunc |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 239 | |
Bram Moolenaar | 8cf3459 | 2022-10-08 21:13:40 +0100 | [diff] [blame] | 240 | func Test_smoothscroll_wrap_long_line() |
| 241 | CheckScreendump |
| 242 | |
| 243 | let lines =<< trim END |
| 244 | vim9script |
| 245 | setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30))]) |
| 246 | set smoothscroll scrolloff=0 |
| 247 | normal 3G10|zt |
| 248 | END |
| 249 | call writefile(lines, 'XSmoothWrap', 'D') |
| 250 | let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40}) |
| 251 | call VerifyScreenDump(buf, 'Test_smooth_long_1', {}) |
| 252 | |
| 253 | " scrolling up, cursor moves screen line down |
| 254 | call term_sendkeys(buf, "\<C-E>") |
| 255 | call VerifyScreenDump(buf, 'Test_smooth_long_2', {}) |
| 256 | call term_sendkeys(buf, "5\<C-E>") |
| 257 | call VerifyScreenDump(buf, 'Test_smooth_long_3', {}) |
| 258 | |
| 259 | " scrolling down, cursor moves screen line up |
| 260 | call term_sendkeys(buf, "5\<C-Y>") |
| 261 | call VerifyScreenDump(buf, 'Test_smooth_long_4', {}) |
| 262 | call term_sendkeys(buf, "\<C-Y>") |
| 263 | call VerifyScreenDump(buf, 'Test_smooth_long_5', {}) |
| 264 | |
Bram Moolenaar | 118c235 | 2022-10-09 17:19:27 +0100 | [diff] [blame] | 265 | " 'scrolloff' set to 1, scrolling up, cursor moves screen line down |
| 266 | call term_sendkeys(buf, ":set scrolloff=1\<CR>") |
| 267 | call term_sendkeys(buf, "10|\<C-E>") |
| 268 | call VerifyScreenDump(buf, 'Test_smooth_long_6', {}) |
| 269 | |
| 270 | " 'scrolloff' set to 1, scrolling down, cursor moves screen line up |
| 271 | call term_sendkeys(buf, "\<C-E>") |
| 272 | call term_sendkeys(buf, "gjgj") |
| 273 | call term_sendkeys(buf, "\<C-Y>") |
| 274 | call VerifyScreenDump(buf, 'Test_smooth_long_7', {}) |
| 275 | |
| 276 | " 'scrolloff' set to 2, scrolling up, cursor moves screen line down |
| 277 | call term_sendkeys(buf, ":set scrolloff=2\<CR>") |
| 278 | call term_sendkeys(buf, "10|\<C-E>") |
| 279 | call VerifyScreenDump(buf, 'Test_smooth_long_8', {}) |
| 280 | |
| 281 | " 'scrolloff' set to 2, scrolling down, cursor moves screen line up |
| 282 | call term_sendkeys(buf, "\<C-E>") |
| 283 | call term_sendkeys(buf, "gj") |
| 284 | call term_sendkeys(buf, "\<C-Y>") |
| 285 | call VerifyScreenDump(buf, 'Test_smooth_long_9', {}) |
| 286 | |
Bram Moolenaar | 8cf3459 | 2022-10-08 21:13:40 +0100 | [diff] [blame] | 287 | call StopVimInTerminal(buf) |
| 288 | endfunc |
| 289 | |
Bram Moolenaar | 2fbabd2 | 2022-10-12 19:53:38 +0100 | [diff] [blame] | 290 | func Test_smoothscroll_one_long_line() |
| 291 | CheckScreendump |
| 292 | |
| 293 | let lines =<< trim END |
| 294 | vim9script |
| 295 | setline(1, 'with lots of text '->repeat(7)) |
| 296 | set smoothscroll scrolloff=0 |
| 297 | END |
| 298 | call writefile(lines, 'XSmoothOneLong', 'D') |
| 299 | let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40}) |
| 300 | call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {}) |
| 301 | |
| 302 | call term_sendkeys(buf, "\<C-E>") |
| 303 | call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {}) |
| 304 | |
| 305 | call term_sendkeys(buf, "0") |
| 306 | call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {}) |
| 307 | |
| 308 | call StopVimInTerminal(buf) |
| 309 | endfunc |
| 310 | |
Yee Cheng Chin | 01ee52b | 2022-11-17 12:41:42 +0000 | [diff] [blame] | 311 | " Test that if the current cursor is on a smooth scrolled line, we correctly |
| 312 | " reposition it. Also check that we don't miscalculate the values by checking |
| 313 | " the consistency between wincol() and col('.') as they are calculated |
| 314 | " separately in code. |
| 315 | func Test_smoothscroll_cursor_position() |
| 316 | call NewWindow(10, 20) |
| 317 | setl smoothscroll wrap |
| 318 | call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") |
| 319 | |
| 320 | func s:check_col_calc(win_col, win_line, buf_col) |
| 321 | call assert_equal(a:win_col, wincol()) |
| 322 | call assert_equal(a:win_line, winline()) |
| 323 | call assert_equal(a:buf_col, col('.')) |
| 324 | endfunc |
| 325 | |
| 326 | call s:check_col_calc(1, 1, 1) |
| 327 | exe "normal \<C-E>" |
| 328 | |
| 329 | " Move down another line to avoid blocking the <<< display |
| 330 | call s:check_col_calc(1, 2, 41) |
| 331 | exe "normal \<C-Y>" |
| 332 | call s:check_col_calc(1, 3, 41) |
| 333 | normal ggg$ |
| 334 | exe "normal \<C-E>" |
| 335 | |
| 336 | " Move down only 1 line when we are out of the range of the <<< display |
| 337 | call s:check_col_calc(20, 1, 40) |
| 338 | exe "normal \<C-Y>" |
| 339 | call s:check_col_calc(20, 2, 40) |
| 340 | normal gg |
| 341 | |
| 342 | " Test number, where we have indented lines |
| 343 | setl number |
| 344 | call s:check_col_calc(5, 1, 1) |
| 345 | exe "normal \<C-E>" |
| 346 | call s:check_col_calc(5, 2, 33) |
| 347 | exe "normal \<C-Y>" |
| 348 | call s:check_col_calc(5, 3, 33) |
| 349 | normal ggg$ |
| 350 | exe "normal \<C-E>" |
| 351 | call s:check_col_calc(20, 1, 32) |
| 352 | exe "normal \<C-Y>" |
| 353 | call s:check_col_calc(20, 2, 32) |
| 354 | normal gg |
| 355 | |
| 356 | " Test number + showbreak, so test that the additional indentation works |
| 357 | setl number showbreak=+++ |
| 358 | call s:check_col_calc(5, 1, 1) |
| 359 | exe "normal \<C-E>" |
| 360 | call s:check_col_calc(8, 2, 30) |
| 361 | exe "normal \<C-Y>" |
| 362 | call s:check_col_calc(8, 3, 30) |
| 363 | normal gg |
| 364 | |
| 365 | " Test number + cpo+=n mode, where wrapped lines aren't indented |
| 366 | setl number cpo+=n showbreak= |
| 367 | call s:check_col_calc(5, 1, 1) |
| 368 | exe "normal \<C-E>" |
| 369 | call s:check_col_calc(1, 2, 37) |
| 370 | exe "normal \<C-Y>" |
| 371 | call s:check_col_calc(1, 3, 37) |
| 372 | normal gg |
| 373 | |
| 374 | bwipeout! |
| 375 | endfunc |
| 376 | |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 377 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 378 | " vim: shiftwidth=2 sts=2 expandtab |