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 |
| 124 | END |
| 125 | call writefile(lines, 'XSmoothNumber', 'D') |
| 126 | let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40}) |
| 127 | |
| 128 | call VerifyScreenDump(buf, 'Test_smooth_number_1', {}) |
| 129 | call term_sendkeys(buf, "\<C-E>") |
| 130 | call VerifyScreenDump(buf, 'Test_smooth_number_2', {}) |
| 131 | call term_sendkeys(buf, "\<C-E>") |
| 132 | call VerifyScreenDump(buf, 'Test_smooth_number_3', {}) |
| 133 | |
| 134 | call term_sendkeys(buf, ":set cpo-=n\<CR>") |
| 135 | call VerifyScreenDump(buf, 'Test_smooth_number_4', {}) |
| 136 | call term_sendkeys(buf, "\<C-Y>") |
| 137 | call VerifyScreenDump(buf, 'Test_smooth_number_5', {}) |
| 138 | call term_sendkeys(buf, "\<C-Y>") |
| 139 | call VerifyScreenDump(buf, 'Test_smooth_number_6', {}) |
| 140 | |
| 141 | call StopVimInTerminal(buf) |
| 142 | endfunc |
| 143 | |
Bram Moolenaar | 1a58e1d | 2022-10-06 13:09:17 +0100 | [diff] [blame] | 144 | func Test_smoothscroll_diff_mode() |
| 145 | CheckScreendump |
| 146 | |
| 147 | let lines =<< trim END |
| 148 | vim9script |
| 149 | var text = 'just some text here' |
| 150 | setline(1, text) |
| 151 | set smoothscroll |
| 152 | diffthis |
| 153 | new |
| 154 | setline(1, text) |
| 155 | set smoothscroll |
| 156 | diffthis |
| 157 | END |
| 158 | call writefile(lines, 'XSmoothDiff', 'D') |
| 159 | let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8}) |
| 160 | |
| 161 | call VerifyScreenDump(buf, 'Test_smooth_diff_1', {}) |
| 162 | call term_sendkeys(buf, "\<C-Y>") |
| 163 | call VerifyScreenDump(buf, 'Test_smooth_diff_1', {}) |
| 164 | call term_sendkeys(buf, "\<C-E>") |
| 165 | call VerifyScreenDump(buf, 'Test_smooth_diff_1', {}) |
| 166 | |
| 167 | call StopVimInTerminal(buf) |
| 168 | endfunc |
| 169 | |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 170 | func Test_smoothscroll_wrap_scrolloff_zero() |
| 171 | CheckScreendump |
| 172 | |
| 173 | let lines =<< trim END |
| 174 | vim9script |
| 175 | setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7)) |
| 176 | set smoothscroll scrolloff=0 |
| 177 | :3 |
| 178 | END |
| 179 | call writefile(lines, 'XSmoothWrap', 'D') |
| 180 | let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40}) |
| 181 | |
| 182 | call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {}) |
| 183 | |
Bram Moolenaar | 46b5474 | 2022-10-06 15:46:49 +0100 | [diff] [blame] | 184 | " moving cursor down - whole bottom line shows |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 185 | call term_sendkeys(buf, "j") |
| 186 | call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {}) |
| 187 | |
| 188 | call term_sendkeys(buf, "\<C-E>j") |
| 189 | call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {}) |
| 190 | |
| 191 | call term_sendkeys(buf, "G") |
| 192 | call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {}) |
| 193 | |
Bram Moolenaar | 46b5474 | 2022-10-06 15:46:49 +0100 | [diff] [blame] | 194 | " moving cursor up - whole top line shows |
| 195 | call term_sendkeys(buf, "2k") |
| 196 | call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {}) |
| 197 | |
Bram Moolenaar | 9bab7a0 | 2022-10-06 14:57:53 +0100 | [diff] [blame] | 198 | call StopVimInTerminal(buf) |
| 199 | endfunc |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 200 | |
| 201 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 202 | " vim: shiftwidth=2 sts=2 expandtab |