local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear local exec = helpers.exec local feed = helpers.feed local assert_alive = helpers.assert_alive before_each(clear) describe('smoothscroll', function() local screen before_each(function() screen = Screen.new(40, 12) screen:attach() end) -- oldtest: Test_CtrlE_CtrlY_stop_at_end() it('disabled does not break and stop at end', function() exec([[ enew call setline(1, ['one', 'two']) set number ]]) feed('') screen:expect({any = " 1 ^one"}) feed('') screen:expect({any = " 2 ^two"}) end) -- oldtest: Test_smoothscroll_CtrlE_CtrlY() it('works with and ', function() exec([[ call setline(1, [ 'line one', 'word '->repeat(20), 'line three', 'long word '->repeat(7), 'line', 'line', 'line', ]) set smoothscroll scrolloff=5 :5 ]]) local s1 = [[ word word word word word word word word | word word word word word word word word | word word word word | line three | long word long word long word long word | long word long word long word | ^line | line | line | ~ | ~ | | ]] local s2 = [[ <<') screen:expect(s1) feed('') screen:expect(s2) feed('') screen:expect(s3) feed('') screen:expect(s4) feed('') screen:expect(s5) feed('') screen:expect(s6) feed('') screen:expect(s7) feed('') screen:expect(s8) exec('set foldmethod=indent') -- move the cursor so we can reuse the same dumps feed('5G') screen:expect(s1) feed('') screen:expect(s2) feed('7G') screen:expect(s7) feed('') screen:expect(s8) end) -- oldtest: Test_smoothscroll_multibyte() it('works with multibyte characters', function() screen:try_resize(40, 6) exec([[ set scrolloff=0 smoothscroll call setline(1, [repeat('ϛ', 45), repeat('2', 36)]) exe "normal G35l\k" ]]) screen:expect([[ ϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛ^ϛϛϛϛϛ| ϛϛϛϛϛ | 222222222222222222222222222222222222 | ~ | ~ | | ]]) end) -- oldtest: Test_smoothscroll_number() it("works 'number' and 'cpo'+=n", function() exec([[ call setline(1, [ 'one ' .. 'word '->repeat(20), 'two ' .. 'long word '->repeat(7), 'line', 'line', 'line', ]) set smoothscroll scrolloff=5 set splitkeep=topline set number cpo+=n :3 func g:DoRel() set number relativenumber scrolloff=0 :%del call setline(1, [ 'one', 'very long text '->repeat(12), 'three', ]) exe "normal 2Gzt\" endfunc ]]) screen:expect([[ 1 one word word word word word word wo| rd word word word word word word word wo| rd word word word word word | 2 two long word long word long word lo| ng word long word long word long word | 3 ^line | 4 line | 5 line | ~ | ~ | ~ | | ]]) feed('') screen:expect([[ <<') screen:expect([[ <<') screen:expect([[ <<< rd word word word word word word wor| d word word word word word word | 2 two long word long word long word lo| ng word long word long word long wor| d | 3 ^line | 4 line | 5 line | ~ | ~ | ~ | | ]]) feed('') screen:expect([[ 1 one word word word word word word wo| rd word word word word word word wor| d word word word word word word | 2 two long word long word long word lo| ng word long word long word long wor| d | 3 ^line | 4 line | 5 line | ~ | ~ | | ]]) exec('botright split') feed('gg') screen:expect([[ 1 one word word word word word word wo| rd word word word word word word wor| d word word word word word word | 2 two long word long word long word@@@| [No Name] [+] | 1 ^one word word word word word word wo| rd word word word word word word wor| d word word word word word word | 2 two long word long word long word lo| ng word long word long word long @@@| [No Name] [+] | | ]]) feed('') screen:expect([[ 1 one word word word word word word wo| rd word word word word word word wor| d word word word word word word | 2 two long word long word long word@@@| [No Name] [+] | <<< rd word word word word word word wor| d word word word word word word^ | 2 two long word long word long word lo| ng word long word long word long wor| d | [No Name] [+] | | ]]) feed('') screen:expect([[ 1 one word word word word word word wo| rd word word word word word word wor| d word word word word word word | 2 two long word long word long word@@@| [No Name] [+] | <<< d word word word word word word^ | 2 two long word long word long word lo| ng word long word long word long wor| d | 3 line | [No Name] [+] | | ]]) exec('close') exec('call DoRel()') screen:expect([[ 2<<<^ong text very long text very long te| xt very long text very long text ver| y long text very long text very long| text very long text very long text | 1 three | ~ | ~ | ~ | ~ | ~ | ~ | --No lines in buffer-- | ]]) end) -- oldtest: Test_smoothscroll_list() it("works with list mode", function() screen:try_resize(40, 8) exec([[ set smoothscroll scrolloff=0 set list call setline(1, [ 'one', 'very long text '->repeat(12), 'three', ]) exe "normal 2Gzt\" ]]) screen:expect([[ <<') screen:expect_unchanged() feed('') screen:expect_unchanged() end) -- oldtest: Test_smoothscroll_wrap_scrolloff_zero() it("works with zero 'scrolloff'", function() screen:try_resize(40, 8) exec([[ call setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7)) set smoothscroll scrolloff=0 display= :3 ]]) screen:expect([[ <<j') screen:expect_unchanged() feed('G') screen:expect_unchanged() feed('4G') screen:expect_unchanged() -- moving cursor up right after the <<< marker - no need to show whole line feed('2gj3l2k') screen:expect([[ <<<^h some text with some text | Line with some text with some text with | some text with some text with some text | with some text with some text | Line with some text with some text with | some text with some text with some text | with some text with some text | | ]]) -- moving cursor up where the <<< marker is - whole top line shows feed('2j02k') screen:expect([[ ^Line with some text with some text with | some text with some text with some text | with some text with some text | Line with some text with some text with | some text with some text with some text | with some text with some text | @ | | ]]) end) -- oldtest: Test_smoothscroll_wrap_long_line() it("adjusts the cursor position in a long line", function() screen:try_resize(40, 6) exec([[ call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four']) set smoothscroll scrolloff=0 normal 3G10|zt ]]) -- scrolling up, cursor moves screen line down screen:expect([[ Line with^ lots of text with lots of text| with lots of text with lots of text wit| h lots of text with lots of text with lo| ts of text with lots of text with lots o| f text with lots of text with lots of te| | ]]) feed('') screen:expect([[ <<') screen:expect([[ <<< lots ^of text with lots of text with | lots of text with lots of text with lots| of text with lots of text with lots of | text with lots of text with lots of text| with lots of text with lots of text wit| | ]]) -- scrolling down, cursor moves screen line up feed('5') screen:expect([[ <<') screen:expect([[ Line with lots of text with lots of text| with lots of text with lots of text wit| h lots of text with lots of text with lo| ts of text with lots of text with lots o| f text wi^th lots of text with lots of te| | ]]) -- 'scrolloff' set to 1, scrolling up, cursor moves screen line down exec('set scrolloff=1') feed('10|') screen:expect([[ <<gjgj') screen:expect([[ <<') screen:expect([[ <<gj') screen:expect_unchanged() -- 'scrolloff' set to 0, move cursor down one line. Cursor should move properly, -- and since this is a really long line, it will be put on top of the screen. exec('set scrolloff=0') feed('0j') screen:expect([[ <<repeat(10)) .. ' end', 'four'])") -- Currently visible lines were replaced, test that the lines and cursor -- are correctly displayed. screen:expect_unchanged() feed('3Gztj') screen:expect_unchanged() -- Repeat the step but this time start it when the line is smooth-scrolled by -- one line. This tests that the offset calculation is still correct and -- still end up scrolling down to the next line with cursor at bottom of -- screen. feed('3Gztj') screen:expect([[ <<repeat(7)) set smoothscroll scrolloff=0 ]]) local s1 = [[ ^with lots of text with lots of text with| lots of text with lots of text with lot| s of text with lots of text with lots of| text | ~ | | ]] screen:expect(s1) feed('') screen:expect([[ <<repeat(6))") exec('set smoothscroll scrolloff=0 showbreak=+++\\ ') local s1 = [[ ^with lots of text in one line with lots | +++ of text in one line with lots of tex| +++ t in one line with lots of text in o| +++ ne line with lots of text in one lin| +++ e with lots of text in one line | | ]] screen:expect(s1) feed('') screen:expect([[ +++ ^of text in one line with lots of tex| +++ t in one line with lots of text in o| +++ ne line with lots of text in one lin| +++ e with lots of text in one line | ~ | | ]]) feed('0') screen:expect(s1) end) -- oldtest: Test_smoothscroll_marker_over_double_width_dump() it('marker is drawn over double-width char correctly', function() screen:try_resize(40, 6) exec([[ call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10)) setlocal smoothscroll ]]) screen:expect([[ ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| 口口口口口口口口口口 | ~ | ~ | ~ | | ]]) feed('') screen:expect([[ <<< 口口口口口口口^口 | ~ | ~ | ~ | ~ | | ]]) end) -- oldtest: Test_smoothscroll_zero_width() it("does not divide by zero with a narrow window", function() screen:try_resize(12, 2) screen:set_default_attr_ids({ [1] = {foreground = Screen.colors.Brown}, [2] = {foreground = Screen.colors.Blue1, bold = true}, }) exec([[ call setline(1, ['a'->repeat(100)]) set wrap smoothscroll number laststatus=0 wincmd v wincmd v wincmd v wincmd v ]]) screen:expect([[ {1: 1^ }│{1: }│{1: }│{1: }│{1: }| | ]]) feed('llllllllllo') screen:expect([[ {2:<<<}{1: }aa^aaaaaa| | ]]) end) -- oldtest: Test_smoothscroll_ins_lines() it("does not unnecessarily insert lines", function() screen:try_resize(40, 6) exec([=[ set wrap smoothscroll scrolloff=0 conceallevel=2 concealcursor=nc call setline(1, [ \'line one' .. 'with lots of text in one line '->repeat(2), \'line two', \'line three', \'line four', \'line five' \]) ]=]) feed('gjgk') screen:expect([[ <<repeat(&lines * &columns), \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2) \]) autocmd CursorMoved * eval [line('w0'), line('w$')] call search('xxx') ]=]) screen:expect([[ <<<_____________________________________| ________________________________________| ______________________________________^xx| x______________________________________x| xx | | ]]) end) -- oldtest: Test_smoothscroll_eob() it("does not scroll halfway at end of buffer", function() screen:try_resize(40, 10) exec([[ set smoothscroll call setline(1, ['']->repeat(100)) norm G ]]) -- does not scroll halfway when scrolling to end of buffer screen:expect([[ | | | | | | | | ^ | | ]]) exec("call setline(92, 'a'->repeat(100))") feed('G') -- cursor is not placed below window screen:expect([[ <<') screen:expect([[ {0:<<<}{1:aaaaaa^a }| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| aaaaaaaaaa | | | bbb | ccc | {0:~ }| {0:~ }| | ]]) feed('2') screen:expect([[ {0:<<<}{1:aaaaaa^a }| | | bbb | ccc | {0:~ }| {0:~ }| {0:~ }| {0:~ }| | ]]) end) -- oldtest: Test_smoothscroll_zero_width_scroll_cursor_bot() it('does not divide by zero in zero-width window', function() screen:try_resize(40, 19) screen:set_default_attr_ids({ [1] = {foreground = Screen.colors.Brown}; -- LineNr [2] = {bold = true, foreground = Screen.colors.Blue}; -- NonText [3] = {bold = true, reverse = true}; -- StatusLine [4] = {reverse = true}; -- StatusLineNC }) exec([[ silent normal yy silent normal 19p set cpoptions+=n vsplit vertical resize 0 set foldcolumn=1 set number set smoothscroll silent normal 20G ]]) screen:expect([[ {1: }│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:@}│ | {2:^@}│ | {3:< }{4:[No Name] [+] }| | ]]) end) -- oldtest: Test_smoothscroll_cursor_top() it('resets skipcol when scrolling cursor to top', function() screen:try_resize(40, 12) exec([[ set smoothscroll scrolloff=2 new | 11resize | wincmd j call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4']) exe "norm G3\k" ]]) screen:expect([[ | [No Name] | line1 | line2 | ^line3line3line3line3line3line3line3line3| line3line3line3line3line3line3line3line3| line3line3line3line3 | line4 | ~ | ~ | [No Name] [+] | | ]]) end) -- oldtest: Test_smoothscroll_crash() it('does not crash with small window and cpo+=n', function() screen:try_resize(40, 12) exec([[ 20 new vsp put =repeat('aaaa', 20) set nu fdc=1 smoothscroll cpo+=n vert resize 0 exe "norm! 0\" ]]) feed('2') assert_alive() end) it("works with virt_lines above and below", function() screen:try_resize(55, 7) exec([=[ call setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(3)) set smoothscroll let ns = nvim_create_namespace('') call nvim_buf_set_extmark(0, ns, 0, 0, {'virt_lines':[[['virt_below1']]]}) call nvim_buf_set_extmark(0, ns, 1, 0, {'virt_lines':[[['virt_above1']]],'virt_lines_above':1}) call nvim_buf_set_extmark(0, ns, 1, 0, {'virt_lines':[[['virt_below2']]]}) call nvim_buf_set_extmark(0, ns, 2, 0, {'virt_lines':[[['virt_above2']]],'virt_lines_above':1}) norm ggL ]=]) screen:expect([[ Line with some text with some text with some text with | some text with some text with some text with some text | virt_below1 | virt_above1 | ^Line with some text with some text with some text with | some text with some text with some text with some text | | ]]) feed('') screen:expect([[ <<') screen:expect([[ virt_below1 | virt_above1 | ^Line with some text with some text with some text with | some text with some text with some text with some text | virt_below2 | virt_above2 | | ]]) feed('') screen:expect([[ virt_above1 | ^Line with some text with some text with some text with | some text with some text with some text with some text | virt_below2 | virt_above2 | Line with some text with some text with some text wi@@@| | ]]) feed('') screen:expect([[ ^Line with some text with some text with some text with | some text with some text with some text with some text | virt_below2 | virt_above2 | Line with some text with some text with some text with | some text with some text with some text with some text | | ]]) feed('') screen:expect([[ <<repeat(7))]->repeat(7)) set smoothscroll scrolloff=0 norm sj ]]) screen:expect([[ <<') screen:expect([[ 2+ [No Name] | <<k') screen:expect([[ 2+ [No Name] | winbar | <<;Cc;0;BN;;;;;N;NULL;;;| {1: }; 0001;;Cc;0;BN;;;;;N;START| {1: } OF HEADING;;;; 0002;;Cc;0;| {1: }BN;;;;;N;START OF TEXT;;;; 0003;;Cc;0;BN;;;;;N;END OF TEXT;;;; | {1: }0004;;Cc;0;BN;;;;;N;END OF | {1: }TRANSMISSION;;;; 0005;;Cc;0| {1: };BN;;;;;N;ENQUIRY;;;; 0006;| {1: };Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; 0007;| {1: };Cc;0;BN;;;;;N;BELL;;;; 000| {1: }8;;Cc;0;BN;;;;;N;BACKSPACE;| | ]]) feed('j') screen:expect([[ {2:<<<}{1: }CJK COMPATIBILITY IDEOGRAPH-2F91F;Lo| {1: };0;L;243AB;;;;N;;;;; 2F920;CJK COMPA| {1: }TIBILITY IDEOGRAPH-2F920;Lo;0;L;7228| {1: };;;;N;;;;; 2F921;CJK COMPATIBILITY I| {1: }DEOGRAPH-2F921;Lo;0;L;7235;;;;N;;;;;| {1: } 2F922;CJK COMPATIBILITY IDEOGRAPH-2| {1: }F922;Lo;0;L;7250;;;;N;;;;; | {1: 2 }^2F923;CJK COMPATIBILITY IDEOGRAPH-2F| {1: }923;Lo;0;L;24608;;;;N;;;;; | {1: 3 }2F924;CJK COMPATIBILITY IDEOGRAPH-2F| {1: }924;Lo;0;L;7280;;;;N;;;;; | | ]]) end) end)