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