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