robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
67.5 KiB1649 linesraw
1local n = require('test.functional.testnvim')()
2local t = require('test.testutil')
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local clear = n.clear
7local exec = n.exec
8local feed = n.feed
9local assert_alive = n.assert_alive
10
11before_each(clear)
12
13describe('smoothscroll', function()
14  local screen
15
16  before_each(function()
17    screen = Screen.new(40, 12)
18  end)
19
20  -- oldtest: Test_CtrlE_CtrlY_stop_at_end()
21  it('disabled does not break <C-E> and <C-Y> stop at end', function()
22    exec([[
23      enew
24      call setline(1, ['one', 'two'])
25      set number
26    ]])
27    feed('<C-Y>')
28    screen:expect({ any = '{8:  1 }^one' })
29    feed('<C-E><C-E><C-E>')
30    screen:expect({ any = '{8:  2 }^two' })
31  end)
32
33  -- oldtest: Test_smoothscroll_CtrlE_CtrlY()
34  it('works with <C-E> and <C-E>', function()
35    exec([[
36      call setline(1, [ 'line one', 'word '->repeat(20), 'line three', 'long word '->repeat(7), 'line', 'line', 'line', ])
37      set smoothscroll scrolloff=5
38      :5
39    ]])
40    local s1 = [[
41      word word word word word word word word |*2
42      word word word word                     |
43      line three                              |
44      long word long word long word long word |
45      long word long word long word           |
46      ^line                                    |
47      line                                    |*2
48      {1:~                                       }|*2
49                                              |
50    ]]
51    local s2 = [[
52      {1:<<<}d word word word word word word word |
53      word word word word                     |
54      line three                              |
55      long word long word long word long word |
56      long word long word long word           |
57      ^line                                    |
58      line                                    |*2
59      {1:~                                       }|*3
60                                              |
61    ]]
62    local s3 = [[
63      {1:<<<}d word word word                     |
64      line three                              |
65      long word long word long word long word |
66      long word long word long word           |
67      ^line                                    |
68      line                                    |*2
69      {1:~                                       }|*4
70                                              |
71    ]]
72    local s4 = [[
73      line three                              |
74      long word long word long word long word |
75      long word long word long word           |
76      line                                    |*2
77      ^line                                    |
78      {1:~                                       }|*5
79                                              |
80    ]]
81    local s5 = [[
82      {1:<<<}d word word word                     |
83      line three                              |
84      long word long word long word long word |
85      long word long word long word           |
86      line                                    |*2
87      ^line                                    |
88      {1:~                                       }|*4
89                                              |
90    ]]
91    local s6 = [[
92      {1:<<<}d word word word word word word word |
93      word word word word                     |
94      line three                              |
95      long word long word long word long word |
96      long word long word long word           |
97      line                                    |*2
98      ^line                                    |
99      {1:~                                       }|*3
100                                              |
101    ]]
102    local s7 = [[
103      word word word word word word word word |*2
104      word word word word                     |
105      line three                              |
106      long word long word long word long word |
107      long word long word long word           |
108      line                                    |*2
109      ^line                                    |
110      {1:~                                       }|*2
111                                              |
112    ]]
113    local s8 = [[
114      line one                                |
115      word word word word word word word word |*2
116      word word word word                     |
117      line three                              |
118      long word long word long word long word |
119      long word long word long word           |
120      line                                    |*2
121      ^line                                    |
122      {1:~                                       }|
123                                              |
124    ]]
125    feed('<C-E>')
126    screen:expect(s1)
127    feed('<C-E>')
128    screen:expect(s2)
129    feed('<C-E>')
130    screen:expect(s3)
131    feed('<C-E>')
132    screen:expect(s4)
133    feed('<C-Y>')
134    screen:expect(s5)
135    feed('<C-Y>')
136    screen:expect(s6)
137    feed('<C-Y>')
138    screen:expect(s7)
139    feed('<C-Y>')
140    screen:expect(s8)
141    exec('set foldmethod=indent')
142    -- move the cursor so we can reuse the same dumps
143    feed('5G<C-E>')
144    screen:expect(s1)
145    feed('<C-E>')
146    screen:expect(s2)
147    feed('7G<C-Y>')
148    screen:expect(s7)
149    feed('<C-Y>')
150    screen:expect(s8)
151  end)
152
153  -- oldtest: Test_smoothscroll_multibyte()
154  it('works with multibyte characters', function()
155    screen:try_resize(40, 6)
156    exec([[
157      set scrolloff=0 smoothscroll
158      call setline(1, [repeat('ϛ', 45), repeat('2', 36)])
159      exe "normal G35l\<C-E>k"
160    ]])
161    screen:expect([[
162      ϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛϛ^ϛϛϛϛϛ|
163      ϛϛϛϛϛ                                   |
164      222222222222222222222222222222222222    |
165      {1:~                                       }|*2
166                                              |
167    ]])
168  end)
169
170  -- oldtest: Test_smoothscroll_number()
171  it("works 'number' and 'cpo'+=n", function()
172    exec([[
173      call setline(1, [ 'one ' .. 'word '->repeat(20), 'two ' .. 'long word '->repeat(7), 'line', 'line', 'line', ])
174      set smoothscroll scrolloff=5
175      set splitkeep=topline
176      set number cpo+=n
177      :3
178      func g:DoRel()
179        set number relativenumber scrolloff=0
180        :%del
181        call setline(1, [ 'one', 'very long text '->repeat(12), 'three', ])
182        exe "normal 2Gzt\<C-E>"
183      endfunc
184    ]])
185    screen:expect([[
186      {8:  1 }one word word word word word word wo|
187      rd word word word word word word word wo|
188      rd word word word word word             |
189      {8:  2 }two long word long word long word lo|
190      ng word long word long word long word   |
191      {8:  3 }^line                                |
192      {8:  4 }line                                |
193      {8:  5 }line                                |
194      {1:~                                       }|*3
195                                              |
196    ]])
197    feed('<C-E>')
198    screen:expect([[
199      {1:<<<}word word word word word word word wo|
200      rd word word word word word             |
201      {8:  2 }two long word long word long word lo|
202      ng word long word long word long word   |
203      {8:  3 }^line                                |
204      {8:  4 }line                                |
205      {8:  5 }line                                |
206      {1:~                                       }|*4
207                                              |
208    ]])
209    feed('<C-E>')
210    screen:expect([[
211      {1:<<<}word word word word word             |
212      {8:  2 }two long word long word long word lo|
213      ng word long word long word long word   |
214      {8:  3 }^line                                |
215      {8:  4 }line                                |
216      {8:  5 }line                                |
217      {1:~                                       }|*5
218                                              |
219    ]])
220    exec('set cpo-=n')
221    screen:expect([[
222      {1:<<<}{8: }d word word word word word word     |
223      {8:  2 }two long word long word long word lo|
224      {8:    }ng word long word long word long wor|
225      {8:    }d                                   |
226      {8:  3 }^line                                |
227      {8:  4 }line                                |
228      {8:  5 }line                                |
229      {1:~                                       }|*4
230                                              |
231    ]])
232    feed('<C-Y>')
233    screen:expect([[
234      {1:<<<}{8: }rd word word word word word word wor|
235      {8:    }d word word word word word word     |
236      {8:  2 }two long word long word long word lo|
237      {8:    }ng word long word long word long wor|
238      {8:    }d                                   |
239      {8:  3 }^line                                |
240      {8:  4 }line                                |
241      {8:  5 }line                                |
242      {1:~                                       }|*3
243                                              |
244    ]])
245    feed('<C-Y>')
246    screen:expect([[
247      {8:  1 }one word word word word word word wo|
248      {8:    }rd word word word word word word wor|
249      {8:    }d word word word word word word     |
250      {8:  2 }two long word long word long word lo|
251      {8:    }ng word long word long word long wor|
252      {8:    }d                                   |
253      {8:  3 }^line                                |
254      {8:  4 }line                                |
255      {8:  5 }line                                |
256      {1:~                                       }|*2
257                                              |
258    ]])
259    exec('botright split')
260    feed('gg')
261    screen:expect([[
262      {8:  1 }one word word word word word word wo|
263      {8:    }rd word word word word word word wor|
264      {8:    }d word word word word word word     |
265      {8:  2 }two long word long word long word{1:@@@}|
266      {2:[No Name] [+]                           }|
267      {8:  1 }^one word word word word word word wo|
268      {8:    }rd word word word word word word wor|
269      {8:    }d word word word word word word     |
270      {8:  2 }two long word long word long word lo|
271      {8:    }ng word long word long word long {1:@@@}|
272      {3:[No Name] [+]                           }|
273                                              |
274    ]])
275
276    feed('<C-E>')
277    screen:expect([[
278      {8:  1 }one word word word word word word wo|
279      {8:    }rd word word word word word word wor|
280      {8:    }d word word word word word word     |
281      {8:  2 }two long word long word long word{1:@@@}|
282      {2:[No Name] [+]                           }|
283      {1:<<<}{8: }rd word word word word word word wor|
284      {8:    }d word word word word word word^     |
285      {8:  2 }two long word long word long word lo|
286      {8:    }ng word long word long word long wor|
287      {8:    }d                                   |
288      {3:[No Name] [+]                           }|
289                                              |
290    ]])
291
292    feed('<C-E>')
293    screen:expect([[
294      {8:  1 }one word word word word word word wo|
295      {8:    }rd word word word word word word wor|
296      {8:    }d word word word word word word     |
297      {8:  2 }two long word long word long word{1:@@@}|
298      {2:[No Name] [+]                           }|
299      {1:<<<}{8: }d word word word word word word^     |
300      {8:  2 }two long word long word long word lo|
301      {8:    }ng word long word long word long wor|
302      {8:    }d                                   |
303      {8:  3 }line                                |
304      {3:[No Name] [+]                           }|
305                                              |
306    ]])
307    exec('close')
308    exec('call DoRel()')
309    screen:expect([[
310      {8:2}{1:<<<}^ong text very long text very long te|
311      {8:    }xt very long text very long text ver|
312      {8:    }y long text very long text very long|
313      {8:    } text very long text very long text |
314      {8:  1 }three                               |
315      {1:~                                       }|*6
316      --No lines in buffer--                  |
317    ]])
318  end)
319
320  -- oldtest: Test_smoothscroll_list()
321  it('works with list mode', function()
322    screen:try_resize(40, 8)
323    exec([[
324      set smoothscroll scrolloff=0
325      set list
326      call setline(1, [ 'one', 'very long text '->repeat(12), 'three', ])
327      exe "normal 2Gzt\<C-E>"
328    ]])
329    screen:expect([[
330      {1:<<<}t very long text very long text very |
331      ^long text very long text very long text |
332      very long text very long text very long |
333      text very long text{1:-}                    |
334      three                                   |
335      {1:~                                       }|*2
336                                              |
337    ]])
338    exec('set listchars+=precedes:#')
339    screen:expect([[
340      {1:#}ext very long text very long text very |
341      ^long text very long text very long text |
342      very long text very long text very long |
343      text very long text{1:-}                    |
344      three                                   |
345      {1:~                                       }|*2
346                                              |
347    ]])
348  end)
349
350  -- oldtest: Test_smoothscroll_diff_mode()
351  it('works with diff mode', function()
352    screen:try_resize(40, 8)
353    exec([[
354      let text = 'just some text here'
355      call setline(1, text)
356      set smoothscroll
357      diffthis
358      new
359      call setline(1, text)
360      set smoothscroll
361      diffthis
362    ]])
363
364    screen:expect([[
365      {7:- }^just some text here                   |
366      {1:~                                       }|*2
367      {3:[No Name] [+]                           }|
368      {7:- }just some text here                   |
369      {1:~                                       }|
370      {2:[No Name] [+]                           }|
371                                              |
372    ]])
373    feed('<C-Y>')
374    screen:expect_unchanged()
375    feed('<C-E>')
376    screen:expect_unchanged()
377  end)
378
379  -- oldtest: Test_smoothscroll_diff_change_line()
380  it('works in diff mode when changing line', function()
381    screen:try_resize(55, 20)
382    exec([[
383      set diffopt+=followwrap smoothscroll
384      call setline(1, repeat(' abc', &columns))
385      call setline(2, 'bar')
386      call setline(3, repeat(' abc', &columns))
387      vnew
388      call setline(1, repeat(' abc', &columns))
389      call setline(2, 'foo')
390      call setline(3, 'bar')
391      call setline(4, repeat(' abc', &columns))
392      windo exe "normal! 2gg5\<C-E>"
393      windo diffthis
394    ]])
395
396    screen:expect([[
397      {1:<<<}bc abc abc abc abc abc a│{1:<<<}bc abc abc abc abc abc a|
398      {7:  }bc abc abc abc abc abc ab│{7:  }bc abc abc abc abc abc ab|
399      {7:  }c abc abc abc abc abc abc│{7:  }c abc abc abc abc abc abc|
400      {7:  } abc abc abc abc abc     │{7:  } abc abc abc abc abc     |
401      {7:  }{22:foo                      }│{7:  }{23:-------------------------}|
402      {7:  }bar                      │{7:  }^bar                      |
403      {7:  } abc abc abc abc abc abc │{7:  } abc abc abc abc abc abc |
404      {7:  }abc abc abc abc abc abc a│{7:  }abc abc abc abc abc abc a|
405      {7:  }bc abc abc abc abc abc ab│{7:  }bc abc abc abc abc abc ab|
406      {7:  }c abc abc abc abc abc abc│{7:  }c abc abc abc abc abc abc|
407      {7:  } abc abc abc abc abc abc │{7:  } abc abc abc abc abc abc |
408      {7:  }abc abc abc abc abc abc a│{7:  }abc abc abc abc abc abc a|
409      {7:  }bc abc abc abc abc abc ab│{7:  }bc abc abc abc abc abc ab|
410      {7:  }c abc abc abc abc abc abc│{7:  }c abc abc abc abc abc abc|
411      {7:  } abc abc abc abc abc     │{7:  } abc abc abc abc abc     |
412      {1:~                          }│{1:~                          }|*3
413      {2:[No Name] [+]               }{3:[No Name] [+]              }|
414                                                             |
415    ]])
416    feed('Abar')
417    screen:expect([[
418      {1:<<<}bc abc abc abc abc abc a│{1:<<<}bc abc abc abc abc abc a|
419      {7:  }bc abc abc abc abc abc ab│{7:  }bc abc abc abc abc abc ab|
420      {7:  }c abc abc abc abc abc abc│{7:  }c abc abc abc abc abc abc|
421      {7:  } abc abc abc abc abc     │{7:  } abc abc abc abc abc     |
422      {7:  }{22:foo                      }│{7:  }{23:-------------------------}|
423      {7:  }bar                      │{7:  }barbar^                   |
424      {7:  } abc abc abc abc abc abc │{7:  } abc abc abc abc abc abc |
425      {7:  }abc abc abc abc abc abc a│{7:  }abc abc abc abc abc abc a|
426      {7:  }bc abc abc abc abc abc ab│{7:  }bc abc abc abc abc abc ab|
427      {7:  }c abc abc abc abc abc abc│{7:  }c abc abc abc abc abc abc|
428      {7:  } abc abc abc abc abc abc │{7:  } abc abc abc abc abc abc |
429      {7:  }abc abc abc abc abc abc a│{7:  }abc abc abc abc abc abc a|
430      {7:  }bc abc abc abc abc abc ab│{7:  }bc abc abc abc abc abc ab|
431      {7:  }c abc abc abc abc abc abc│{7:  }c abc abc abc abc abc abc|
432      {7:  } abc abc abc abc abc     │{7:  } abc abc abc abc abc     |
433      {1:~                          }│{1:~                          }|*3
434      {2:[No Name] [+]               }{3:[No Name] [+]              }|
435      {5:-- INSERT --}                                           |
436    ]])
437    feed('<Esc>')
438    screen:expect([[
439      {1:<<<}bc abc abc abc abc abc a│{1:<<<}bc abc abc abc abc abc a|
440      {7:  }bc abc abc abc abc abc ab│{7:  }bc abc abc abc abc abc ab|
441      {7:  }c abc abc abc abc abc abc│{7:  }c abc abc abc abc abc abc|
442      {7:  } abc abc abc abc abc     │{7:  } abc abc abc abc abc     |
443      {7:  }{22:foo                      }│{7:  }{23:-------------------------}|
444      {7:  }{4:bar                      }│{7:  }{4:bar}{27:ba^r}{4:                   }|
445      {7:  } abc abc abc abc abc abc │{7:  } abc abc abc abc abc abc |
446      {7:  }abc abc abc abc abc abc a│{7:  }abc abc abc abc abc abc a|
447      {7:  }bc abc abc abc abc abc ab│{7:  }bc abc abc abc abc abc ab|
448      {7:  }c abc abc abc abc abc abc│{7:  }c abc abc abc abc abc abc|
449      {7:  } abc abc abc abc abc abc │{7:  } abc abc abc abc abc abc |
450      {7:  }abc abc abc abc abc abc a│{7:  }abc abc abc abc abc abc a|
451      {7:  }bc abc abc abc abc abc ab│{7:  }bc abc abc abc abc abc ab|
452      {7:  }c abc abc abc abc abc abc│{7:  }c abc abc abc abc abc abc|
453      {7:  } abc abc abc abc abc     │{7:  } abc abc abc abc abc     |
454      {1:~                          }│{1:~                          }|*3
455      {2:[No Name] [+]               }{3:[No Name] [+]              }|
456                                                             |
457    ]])
458    feed('yyp')
459    screen:expect([[
460      {1:<<<}bc abc abc abc abc abc a│{1:<<<}bc abc abc abc abc abc a|
461      {7:  }bc abc abc abc abc abc ab│{7:  }bc abc abc abc abc abc ab|
462      {7:  }c abc abc abc abc abc abc│{7:  }c abc abc abc abc abc abc|
463      {7:  } abc abc abc abc abc     │{7:  } abc abc abc abc abc     |
464      {7:  }{27:foo}{4:                      }│{7:  }{27:barbar}{4:                   }|
465      {7:  }{4:bar                      }│{7:  }{4:^bar}{27:bar}{4:                   }|
466      {7:  } abc abc abc abc abc abc │{7:  } abc abc abc abc abc abc |
467      {7:  }abc abc abc abc abc abc a│{7:  }abc abc abc abc abc abc a|
468      {7:  }bc abc abc abc abc abc ab│{7:  }bc abc abc abc abc abc ab|
469      {7:  }c abc abc abc abc abc abc│{7:  }c abc abc abc abc abc abc|
470      {7:  } abc abc abc abc abc abc │{7:  } abc abc abc abc abc abc |
471      {7:  }abc abc abc abc abc abc a│{7:  }abc abc abc abc abc abc a|
472      {7:  }bc abc abc abc abc abc ab│{7:  }bc abc abc abc abc abc ab|
473      {7:  }c abc abc abc abc abc abc│{7:  }c abc abc abc abc abc abc|
474      {7:  } abc abc abc abc abc     │{7:  } abc abc abc abc abc     |
475      {1:~                          }│{1:~                          }|*3
476      {2:[No Name] [+]               }{3:[No Name] [+]              }|
477                                                             |
478    ]])
479  end)
480
481  -- oldtest: Test_smoothscroll_wrap_scrolloff_zero()
482  it("works with zero 'scrolloff'", function()
483    screen:try_resize(40, 8)
484    exec([[
485      call setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
486      set smoothscroll scrolloff=0 display=
487      :3
488    ]])
489    screen:expect([[
490      {1:<<<}h some text with some text           |
491      Line with some text with some text with |
492      some text with some text with some text |
493      with some text with some text           |
494      ^Line with some text with some text with |
495      some text with some text with some text |
496      with some text with some text           |
497                                              |
498    ]])
499    feed('j')
500    screen:expect_unchanged()
501    -- moving cursor down - whole bottom line shows
502    feed('<C-E>j')
503    screen:expect_unchanged()
504    feed('G')
505    screen:expect_unchanged()
506    feed('4<C-Y>G')
507    screen:expect_unchanged()
508    -- moving cursor up right after the <<< marker - no need to show whole line
509    feed('2gj3l2k')
510    screen:expect([[
511      {1:<<<}^h some text with some text           |
512      Line with some text with some text with |
513      some text with some text with some text |
514      with some text with some text           |
515      Line with some text with some text with |
516      some text with some text with some text |
517      with some text with some text           |
518                                              |
519    ]])
520    -- moving cursor up where the <<< marker is - whole top line shows
521    feed('2j02k')
522    screen:expect([[
523      ^Line with some text with some text with |
524      some text with some text with some text |
525      with some text with some text           |
526      Line with some text with some text with |
527      some text with some text with some text |
528      with some text with some text           |
529      {1:@                                       }|
530                                              |
531    ]])
532  end)
533
534  -- oldtest: Test_smoothscroll_wrap_long_line()
535  it('adjusts the cursor position in a long line', function()
536    screen:try_resize(40, 6)
537    exec([[
538      call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four'])
539      set smoothscroll scrolloff=0
540      normal 3G10|zt
541    ]])
542    -- scrolling up, cursor moves screen line down
543    screen:expect([[
544      Line with^ lots of text with lots of text|
545       with lots of text with lots of text wit|
546      h lots of text with lots of text with lo|
547      ts of text with lots of text with lots o|
548      f text with lots of text with lots of te|
549                                              |
550    ]])
551    feed('<C-E>')
552    screen:expect([[
553      {1:<<<}th lot^s of text with lots of text wit|
554      h lots of text with lots of text with lo|
555      ts of text with lots of text with lots o|
556      f text with lots of text with lots of te|
557      xt with lots of text with lots of text w|
558                                              |
559    ]])
560    feed('5<C-E>')
561    screen:expect([[
562      {1:<<<} lots ^of text with lots of text with |
563      lots of text with lots of text with lots|
564       of text with lots of text with lots of |
565      text with lots of text with lots of text|
566       with lots of text with lots of text wit|
567                                              |
568    ]])
569    -- scrolling down, cursor moves screen line up
570    feed('5<C-Y>')
571    screen:expect([[
572      {1:<<<}th lots of text with lots of text wit|
573      h lots of text with lots of text with lo|
574      ts of text with lots of text with lots o|
575      f text with lots of text with lots of te|
576      xt with l^ots of text with lots of text w|
577                                              |
578    ]])
579    feed('<C-Y>')
580    screen:expect([[
581      Line with lots of text with lots of text|
582       with lots of text with lots of text wit|
583      h lots of text with lots of text with lo|
584      ts of text with lots of text with lots o|
585      f text wi^th lots of text with lots of te|
586                                              |
587    ]])
588    -- 'scrolloff' set to 1, scrolling up, cursor moves screen line down
589    exec('set scrolloff=1')
590    feed('10|<C-E>')
591    screen:expect([[
592      {1:<<<}th lots of text with lots of text wit|
593      h lots of^ text with lots of text with lo|
594      ts of text with lots of text with lots o|
595      f text with lots of text with lots of te|
596      xt with lots of text with lots of text w|
597                                              |
598    ]])
599    -- 'scrolloff' set to 1, scrolling down, cursor moves screen line up
600    feed('<C-E>gjgj<C-Y>')
601    screen:expect([[
602      {1:<<<}th lots of text with lots of text wit|
603      h lots of text with lots of text with lo|
604      ts of text with lots of text with lots o|
605      f text wi^th lots of text with lots of te|
606      xt with lots of text with lots of text w|
607                                              |
608    ]])
609    -- 'scrolloff' set to 2, scrolling up, cursor moves screen line down
610    exec('set scrolloff=2')
611    feed('10|<C-E>')
612    screen:expect([[
613      {1:<<<}th lots of text with lots of text wit|
614      h lots of text with lots of text with lo|
615      ts of tex^t with lots of text with lots o|
616      f text with lots of text with lots of te|
617      xt with lots of text with lots of text w|
618                                              |
619    ]])
620    -- 'scrolloff' set to 2, scrolling down, cursor moves screen line up
621    feed('<C-E>gj<C-Y>')
622    screen:expect_unchanged()
623    -- 'scrolloff' set to 0, move cursor down one line. Cursor should move properly,
624    -- and since this is a really long line, it will be put on top of the screen.
625    exec('set scrolloff=0')
626    feed('0j')
627    screen:expect([[
628      {1:<<<}th lots of text with lots of text wit|
629      h lots of text with lots of text with lo|
630      ts of text with lots of text with lots o|
631      f text with lots of text end            |
632      ^four                                    |
633                                              |
634    ]])
635    -- Test zt/zz/zb that they work properly when a long line is above it
636    feed('zt')
637    screen:expect([[
638      ^four                                    |
639      {1:~                                       }|*4
640                                              |
641    ]])
642    feed('zz')
643    screen:expect([[
644      {1:<<<}of text with lots of text with lots o|
645      f text with lots of text end            |
646      ^four                                    |
647      {1:~                                       }|*2
648                                              |
649    ]])
650    feed('zb')
651    screen:expect([[
652      {1:<<<}th lots of text with lots of text wit|
653      h lots of text with lots of text with lo|
654      ts of text with lots of text with lots o|
655      f text with lots of text end            |
656      ^four                                    |
657                                              |
658    ]])
659    -- Repeat the step and move the cursor down again.
660    -- This time, use a shorter long line that is barely long enough to span more
661    -- than one window. Note that the cursor is at the bottom this time because
662    -- Vim prefers to do so if we are scrolling a few lines only.
663    exec(
664      "call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(10)) .. ' end', 'four'])"
665    )
666    -- Currently visible lines were replaced, test that the lines and cursor
667    -- are correctly displayed.
668    screen:expect_unchanged()
669    feed('3Gztj')
670    screen:expect_unchanged()
671    -- Repeat the step but this time start it when the line is smooth-scrolled by
672    -- one line. This tests that the offset calculation is still correct and
673    -- still end up scrolling down to the next line with cursor at bottom of
674    -- screen.
675    feed('3Gzt<C-E>j')
676    screen:expect([[
677      {1:<<<}th lots of text with lots of text wit|
678      h lots of text with lots of text with lo|
679      ts of text with lots of text with lots o|
680      f text with lots of text end            |
681      fou^r                                    |
682                                              |
683    ]])
684  end)
685
686  -- oldtest: Test_smoothscroll_one_long_line()
687  it('scrolls correctly when moving the cursor', function()
688    screen:try_resize(40, 6)
689    exec([[
690      call setline(1, 'with lots of text '->repeat(7))
691      set smoothscroll scrolloff=0
692    ]])
693    local s1 = [[
694      ^with lots of text with lots of text with|
695       lots of text with lots of text with lot|
696      s of text with lots of text with lots of|
697       text                                   |
698      {1:~                                       }|
699                                              |
700    ]]
701    screen:expect(s1)
702    feed('<C-E>')
703    screen:expect([[
704      {1:<<<}ts of text with lots of text with lot|
705      ^s of text with lots of text with lots of|
706       text                                   |
707      {1:~                                       }|*2
708                                              |
709    ]])
710    feed('0')
711    screen:expect(s1)
712  end)
713
714  -- oldtest: Test_smoothscroll_long_line_showbreak()
715  it('cursor is not one screen line too far down', function()
716    screen:try_resize(40, 6)
717    -- a line that spans four screen lines
718    exec("call setline(1, 'with lots of text in one line '->repeat(6))")
719    exec('set smoothscroll scrolloff=0 showbreak=+++\\ ')
720    local s1 = [[
721      ^with lots of text in one line with lots |
722      {1:+++ }of text in one line with lots of tex|
723      {1:+++ }t in one line with lots of text in o|
724      {1:+++ }ne line with lots of text in one lin|
725      {1:+++ }e with lots of text in one line     |
726                                              |
727    ]]
728    screen:expect(s1)
729    feed('<C-E>')
730    screen:expect([[
731      {1:+++ }^of text in one line with lots of tex|
732      {1:+++ }t in one line with lots of text in o|
733      {1:+++ }ne line with lots of text in one lin|
734      {1:+++ }e with lots of text in one line     |
735      {1:~                                       }|
736                                              |
737    ]])
738    feed('0')
739    screen:expect(s1)
740  end)
741
742  -- oldtest: Test_smoothscroll_marker_over_double_width_dump()
743  it('marker is drawn over double-width char correctly', function()
744    screen:try_resize(40, 6)
745    exec([[
746      call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10))
747      setlocal smoothscroll
748    ]])
749    screen:expect([[
750      ^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
751      口口口口口口口口口口                    |
752      {1:~                                       }|*3
753                                              |
754    ]])
755    feed('<C-E>')
756    screen:expect([[
757      {1:<<<} 口口口口口口口^口                    |
758      {1:~                                       }|*4
759                                              |
760    ]])
761  end)
762
763  -- oldtest: Test_smoothscroll_zero_width()
764  it('does not divide by zero with a narrow window', function()
765    screen:try_resize(12, 2)
766    exec([[
767      call setline(1, ['a'->repeat(100)])
768      set wrap smoothscroll number laststatus=0
769      wincmd v
770      wincmd v
771      wincmd v
772      wincmd v
773    ]])
774    screen:expect([[
775      {8:  1^ }│{8: }│{8: }│{8: }│{8: }|
776                  |
777    ]])
778    feed('llllllllll<C-W>o')
779    screen:expect([[
780      {1:<<<}{8: }aa^aaaaaa|
781                  |
782    ]])
783  end)
784
785  -- oldtest: Test_smoothscroll_ins_lines()
786  it('does not unnecessarily insert lines', function()
787    screen:try_resize(40, 6)
788    exec([=[
789      set wrap smoothscroll scrolloff=0 conceallevel=2 concealcursor=nc
790      call setline(1, [
791        \'line one' .. 'with lots of text in one line '->repeat(2),
792        \'line two',
793        \'line three',
794        \'line four',
795        \'line five'
796      \])
797    ]=])
798    feed('<C-E>gjgk')
799    screen:expect([[
800      {1:<<<}lots of text in one line^             |
801      line two                                |
802      line three                              |
803      line four                               |
804      line five                               |
805                                              |
806    ]])
807  end)
808
809  -- oldtest: Test_smoothscroll_cursormoved_line()
810  it('does not place the cursor in the command line', function()
811    screen:try_resize(40, 6)
812    exec([=[
813      set smoothscroll
814      call setline(1, [
815        \'',
816        \'_'->repeat(&lines * &columns),
817        \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2)
818      \])
819      autocmd CursorMoved * eval [line('w0'), line('w$')]
820      call search('xxx')
821    ]=])
822    screen:expect([[
823      {1:<<<}_____________________________________|
824      ________________________________________|
825      ______________________________________^xx|
826      x______________________________________x|
827      xx                                      |
828                                              |
829    ]])
830  end)
831
832  -- oldtest: Test_smoothscroll_eob()
833  it('does not scroll halfway at end of buffer', function()
834    screen:try_resize(40, 10)
835    exec([[
836      set smoothscroll
837      call setline(1, ['']->repeat(100))
838      norm G
839    ]])
840    -- does not scroll halfway when scrolling to end of buffer
841    screen:expect([[
842                                              |*8
843      ^                                        |
844                                              |
845    ]])
846    exec("call setline(92, 'a'->repeat(100))")
847    feed('<C-L><C-B>G')
848    -- cursor is not placed below window
849    screen:expect([[
850      {1:<<<}aaaaaaaaaaaaaaaaa                    |
851                                              |*7
852      ^                                        |
853                                              |
854    ]])
855  end)
856
857  -- oldtest: Test_smoothscroll_incsearch()
858  it('does not reset skipcol when doing incremental search on the same word', function()
859    screen:try_resize(40, 8)
860    exec([[
861      set smoothscroll number scrolloff=0 incsearch
862      call setline(1, repeat([''], 20))
863      call setline(11, repeat('a', 100))
864      call setline(14, 'bbbb')
865    ]])
866    feed('/b')
867    screen:expect([[
868      {1:<<<}{8: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa        |
869      {8: 12 }                                    |
870      {8: 13 }                                    |
871      {8: 14 }{2:b}{10:bbb}                                |
872      {8: 15 }                                    |
873      {8: 16 }                                    |
874      {8: 17 }                                    |
875      /b^                                      |
876    ]])
877    feed('b')
878    screen:expect([[
879      {1:<<<}{8: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa        |
880      {8: 12 }                                    |
881      {8: 13 }                                    |
882      {8: 14 }{2:bb}{10:bb}                                |
883      {8: 15 }                                    |
884      {8: 16 }                                    |
885      {8: 17 }                                    |
886      /bb^                                     |
887    ]])
888    feed('b')
889    screen:expect([[
890      {1:<<<}{8: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa        |
891      {8: 12 }                                    |
892      {8: 13 }                                    |
893      {8: 14 }{2:bbb}b                                |
894      {8: 15 }                                    |
895      {8: 16 }                                    |
896      {8: 17 }                                    |
897      /bbb^                                    |
898    ]])
899    feed('b')
900    screen:expect([[
901      {1:<<<}{8: }aaaaaaaaaaaaaaaaaaaaaaaaaaaa        |
902      {8: 12 }                                    |
903      {8: 13 }                                    |
904      {8: 14 }{2:bbbb}                                |
905      {8: 15 }                                    |
906      {8: 16 }                                    |
907      {8: 17 }                                    |
908      /bbbb^                                   |
909    ]])
910  end)
911
912  -- oldtest: Test_smoothscroll_multi_skipcol()
913  it('scrolling multiple lines and stopping at non-zero skipcol', function()
914    screen:try_resize(40, 10)
915    exec([[
916      setlocal cursorline scrolloff=0 smoothscroll
917      call setline(1, repeat([''], 8))
918      call setline(3, repeat('a', 50))
919      call setline(4, repeat('a', 50))
920      call setline(7, 'bbb')
921      call setline(8, 'ccc')
922      redraw
923    ]])
924    screen:expect([[
925      {21:^                                        }|
926                                              |
927      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
928      aaaaaaaaaa                              |
929      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
930      aaaaaaaaaa                              |
931                                              |*2
932      bbb                                     |
933                                              |
934    ]])
935    feed('3<C-E>')
936    screen:expect([[
937      {1:<<<}{21:aaaaaa^a                              }|
938      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
939      aaaaaaaaaa                              |
940                                              |*2
941      bbb                                     |
942      ccc                                     |
943      {1:~                                       }|*2
944                                              |
945    ]])
946    feed('2<C-E>')
947    screen:expect([[
948      {1:<<<}{21:aaaaaa^a                              }|
949                                              |*2
950      bbb                                     |
951      ccc                                     |
952      {1:~                                       }|*4
953                                              |
954    ]])
955  end)
956
957  -- oldtest: Test_smoothscroll_zero_width_scroll_cursor_bot()
958  it('does not divide by zero in zero-width window', function()
959    screen:try_resize(40, 19)
960    exec([[
961      silent normal yy
962      silent normal 19p
963      set cpoptions+=n
964      vsplit
965      vertical resize 0
966      set foldcolumn=1
967      set number
968      set smoothscroll
969      silent normal 20G
970    ]])
971    screen:expect([[
972      {8: }│                                      |
973      {1:@}│                                      |*15
974      {1:^@}│                                      |
975      {3:< }{2:[No Name] [+]                         }|
976                                              |
977    ]])
978  end)
979
980  -- oldtest: Test_smoothscroll_cursor_top()
981  it('resets skipcol when scrolling cursor to top', function()
982    screen:try_resize(40, 12)
983    exec([[
984      set smoothscroll scrolloff=2
985      new | 11resize | wincmd j
986      call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4'])
987      exe "norm G3\<C-E>k"
988    ]])
989    screen:expect([[
990                                              |
991      {2:[No Name]                               }|
992      line1                                   |
993      line2                                   |
994      ^line3line3line3line3line3line3line3line3|
995      line3line3line3line3line3line3line3line3|
996      line3line3line3line3                    |
997      line4                                   |
998      {1:~                                       }|*2
999      {3:[No Name] [+]                           }|
1000                                              |
1001    ]])
1002  end)
1003
1004  -- oldtest: Test_smoothscroll_crash()
1005  it('does not crash with small window and cpo+=n', function()
1006    screen:try_resize(40, 12)
1007    exec([[
1008      20 new
1009      vsp
1010      put =repeat('aaaa', 20)
1011      set nu fdc=1  smoothscroll cpo+=n
1012      vert resize 0
1013      exe "norm! 0\<c-e>"
1014    ]])
1015    feed('2<C-E>')
1016    assert_alive()
1017  end)
1018
1019  -- oldtest: Test_smoothscroll_insert_bottom()
1020  it('works in Insert mode at bottom of window', function()
1021    screen:try_resize(40, 9)
1022    exec([[
1023      call setline(1, repeat([repeat('A very long line ...', 10)], 5))
1024      set wrap smoothscroll scrolloff=0
1025    ]])
1026    feed('Go123456789<CR>')
1027    screen:expect([[
1028      {1:<<<}ery long line ...A very long line ...|
1029      A very long line ...A very long line ...|*5
1030      123456789                               |
1031      ^                                        |
1032      {5:-- INSERT --}                            |
1033    ]])
1034  end)
1035
1036  -- oldtest: Test_smoothscroll_in_qf_window()
1037  it('works in quickfix window when changing quickfix list', function()
1038    screen:try_resize(60, 20)
1039    exec([[
1040      set nocompatible display=lastline
1041      copen 5
1042      setlocal number smoothscroll
1043      let g:l = [{'text': 'foo'}] + repeat([{'text': join(range(30))}], 10)
1044      call setqflist(g:l, 'r')
1045      normal! G
1046      wincmd t
1047      let g:l1 = [{'text': join(range(1000))}]
1048    ]])
1049    screen:expect([[
1050      ^                                                            |
1051      {1:~                                                           }|*11
1052      {3:[No Name]                                                   }|
1053      {1:<<<}{8: }21 22 23 24 25 26 27 28 29                              |
1054      {8: 10 }|| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
1055      {8:    }21 22 23 24 25 26 27 28 29                              |
1056      {8: 11 }|| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
1057      {8:    }21 22 23 24 25 26 27 28 29                              |
1058      {2:[Quickfix List] [-]                                         }|
1059                                                                  |
1060    ]])
1061
1062    feed([[:call setqflist([], 'r')<CR>]])
1063    local screen_empty = [[
1064      ^                                                            |
1065      {1:~                                                           }|*11
1066      {3:[No Name]                                                   }|
1067      {8:  1 }                                                        |
1068      {1:~                                                           }|*4
1069      {2:[Quickfix List] [-]                                         }|
1070      :call setqflist([], 'r')                                    |
1071    ]]
1072    screen:expect(screen_empty)
1073
1074    feed([[:call setqflist(g:l, 'r')<CR>]])
1075    local screen_l_top = [[
1076      ^                                                            |
1077      {1:~                                                           }|*11
1078      {3:[No Name]                                                   }|
1079      {8:  1 }{10:|| foo                                                  }|
1080      {8:  2 }|| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
1081      {8:    }21 22 23 24 25 26 27 28 29                              |
1082      {8:  3 }|| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
1083      {8:    }21 22 23 24 25 26 27 28 29                              |
1084      {2:[Quickfix List] [-]                                         }|
1085      :call setqflist(g:l, 'r')                                   |
1086    ]]
1087    screen:expect(screen_l_top)
1088
1089    feed([[:call setqflist(g:l1, 'r')<CR>]])
1090    local screen_l1_top = [[
1091      ^                                                            |
1092      {1:~                                                           }|*11
1093      {3:[No Name]                                                   }|
1094      {8:  1 }{10:|| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 }|
1095      {8:    }{10:21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39}|
1096      {8:    }{10: 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 5}|
1097      {8:    }{10:8 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 }|
1098      {8:    }{10:77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95}|
1099      {2:[Quickfix List] [-]                                         }|
1100      :call setqflist(g:l1, 'r')                                  |
1101    ]]
1102    screen:expect(screen_l1_top)
1103
1104    feed('<C-W>b$<C-W>t')
1105    local screen_l1_bot = [[
1106      ^                                                            |
1107      {1:~                                                           }|*11
1108      {3:[No Name]                                                   }|
1109      {1:<<<}{8: }{10: 937 938 939 940 941 942 943 944 945 946 947 948 949 950}|
1110      {8:    }{10: 951 952 953 954 955 956 957 958 959 960 961 962 963 964}|
1111      {8:    }{10: 965 966 967 968 969 970 971 972 973 974 975 976 977 978}|
1112      {8:    }{10: 979 980 981 982 983 984 985 986 987 988 989 990 991 992}|
1113      {8:    }{10: 993 994 995 996 997 998 999                            }|
1114      {2:[Quickfix List] [-]                                         }|
1115      :call setqflist(g:l1, 'r')                                  |
1116    ]]
1117    screen:expect(screen_l1_bot)
1118
1119    feed([[:call setqflist([], 'r')<CR>]])
1120    screen:expect(screen_empty)
1121
1122    feed([[:call setqflist(g:l1, 'r')<CR>]])
1123    screen:expect(screen_l1_top)
1124
1125    feed('<C-W>b$<C-W>t')
1126    screen:expect(screen_l1_bot)
1127
1128    feed([[:call setqflist(g:l, 'r')<CR>]])
1129    screen:expect(screen_l_top)
1130  end)
1131
1132  -- oldtest: Test_smoothscroll_textoff_showbreak()
1133  it('does not crash when resizing to textoff with showbreak', function()
1134    exec([[
1135      set noswapfile scrolloff=0
1136
1137      call setline(1, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
1138      set number wrap smoothscroll showbreak=>
1139      vsplit
1140
1141      let textoff = getwininfo(win_getid())[0].textoff
1142      execute "normal! 0\<C-E>"
1143      redraw
1144      execute 'vertical resize' textoff
1145      redraw
1146    ]])
1147    assert_alive()
1148  end)
1149
1150  it('works with virt_lines above and below', function()
1151    screen:try_resize(55, 7)
1152    exec([=[
1153      call setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(3))
1154      set smoothscroll
1155      let ns = nvim_create_namespace('')
1156      call nvim_buf_set_extmark(0, ns, 0, 0, {'virt_lines':[[['virt_below1']]]})
1157      call nvim_buf_set_extmark(0, ns, 1, 0, {'virt_lines':[[['virt_above1']]],'virt_lines_above':1})
1158      call nvim_buf_set_extmark(0, ns, 1, 0, {'virt_lines':[[['virt_below2']]]})
1159      call nvim_buf_set_extmark(0, ns, 2, 0, {'virt_lines':[[['virt_above2']]],'virt_lines_above':1})
1160      norm ggL
1161    ]=])
1162    screen:expect([[
1163      Line with some text with some text with some text with |
1164      some text with some text with some text with some text |
1165      virt_below1                                            |
1166      virt_above1                                            |
1167      ^Line with some text with some text with some text with |
1168      some text with some text with some text with some text |
1169                                                             |
1170    ]])
1171    feed('<C-E>')
1172    screen:expect([[
1173      {1:<<<}e text with some text with some text with some text |
1174      virt_below1                                            |
1175      virt_above1                                            |
1176      ^Line with some text with some text with some text with |
1177      some text with some text with some text with some text |
1178      virt_below2                                            |
1179                                                             |
1180    ]])
1181    feed('<C-E>')
1182    screen:expect([[
1183      virt_below1                                            |
1184      virt_above1                                            |
1185      ^Line with some text with some text with some text with |
1186      some text with some text with some text with some text |
1187      virt_below2                                            |
1188      virt_above2                                            |
1189                                                             |
1190    ]])
1191    feed('<C-E>')
1192    screen:expect([[
1193      virt_above1                                            |
1194      ^Line with some text with some text with some text with |
1195      some text with some text with some text with some text |
1196      virt_below2                                            |
1197      virt_above2                                            |
1198      Line with some text with some text with some text wi{1:@@@}|
1199                                                             |
1200    ]])
1201    feed('<C-E>')
1202    screen:expect([[
1203      ^Line with some text with some text with some text with |
1204      some text with some text with some text with some text |
1205      virt_below2                                            |
1206      virt_above2                                            |
1207      Line with some text with some text with some text with |
1208      some text with some text with some text with some text |
1209                                                             |
1210    ]])
1211    feed('<C-E>')
1212    screen:expect([[
1213      {1:<<<}e text with some text with some text with some tex^t |
1214      virt_below2                                            |
1215      virt_above2                                            |
1216      Line with some text with some text with some text with |
1217      some text with some text with some text with some text |
1218      {1:~                                                      }|
1219                                                             |
1220    ]])
1221  end)
1222
1223  it('<<< marker shows with tabline, winbar and splits', function()
1224    screen:try_resize(40, 12)
1225    screen:add_extra_attr_ids {
1226      [100] = { foreground = Screen.colors.Magenta1, bold = true },
1227    }
1228    exec([[
1229      call setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
1230      set smoothscroll scrolloff=0
1231      norm sj
1232    ]])
1233    screen:expect([[
1234      {1:<<<}e text with some text with some text |
1235      with some text with some text           |
1236      Line with some text with some text with |
1237      some text with some text with some text |
1238      with some text with some text           |
1239      {2:[No Name] [+]                           }|
1240      {1:<<<}e text with some text with some text |
1241      ^with some text with some text           |
1242      Line with some text with some text with |
1243      some text with some text with some te{1:@@@}|
1244      {3:[No Name] [+]                           }|
1245                                              |
1246    ]])
1247    exec('set showtabline=2')
1248    screen:expect([[
1249      {5: }{100:2}{5:+ [No Name] }{2:                          }|
1250      {1:<<<}e text with some text with some text |
1251      with some text with some text           |
1252      Line with some text with some text with |
1253      some text with some text with some text |
1254      with some text with some text           |
1255      {2:[No Name] [+]                           }|
1256      {1:<<<}e text with some text with some text |
1257      ^with some text with some text           |
1258      Line with some text with some text wi{1:@@@}|
1259      {3:[No Name] [+]                           }|
1260                                              |
1261    ]])
1262    exec('set winbar=winbar')
1263    feed('<C-w>k')
1264    screen:expect([[
1265      {5: }{100:2}{5:+ [No Name] }{2:                          }|
1266      {5:winbar                                  }|
1267      {1:<<<}e text with some text with some text |
1268      ^with some text with some text           |
1269      Line with some text with some text with |
1270      some text with some text with some te{1:@@@}|
1271      {3:[No Name] [+]                           }|
1272      {5:winbar                                  }|
1273      {1:<<<}e text with some text with some text |
1274      with some text with some text           |
1275      {2:[No Name] [+]                           }|
1276                                              |
1277    ]])
1278  end)
1279
1280  it('works with very long line', function()
1281    exec([[
1282      edit test/functional/fixtures/bigfile_oneline.txt
1283      setlocal smoothscroll number
1284    ]])
1285    screen:expect([[
1286      {8:  1 }^0000;<control>;Cc;0;BN;;;;;N;NULL;;;|
1287      {8:    }; 0001;<control>;Cc;0;BN;;;;;N;START|
1288      {8:    } OF HEADING;;;; 0002;<control>;Cc;0;|
1289      {8:    }BN;;;;;N;START OF TEXT;;;; 0003;<con|
1290      {8:    }trol>;Cc;0;BN;;;;;N;END OF TEXT;;;; |
1291      {8:    }0004;<control>;Cc;0;BN;;;;;N;END OF |
1292      {8:    }TRANSMISSION;;;; 0005;<control>;Cc;0|
1293      {8:    };BN;;;;;N;ENQUIRY;;;; 0006;<control>|
1294      {8:    };Cc;0;BN;;;;;N;ACKNOWLEDGE;;;; 0007;|
1295      {8:    }<control>;Cc;0;BN;;;;;N;BELL;;;; 000|
1296      {8:    }8;<control>;Cc;0;BN;;;;;N;BACKSPACE;|
1297                                              |
1298    ]])
1299    feed('j')
1300    screen:expect([[
1301      {1:<<<}{8: }CJK COMPATIBILITY IDEOGRAPH-2F91F;Lo|
1302      {8:    };0;L;243AB;;;;N;;;;; 2F920;CJK COMPA|
1303      {8:    }TIBILITY IDEOGRAPH-2F920;Lo;0;L;7228|
1304      {8:    };;;;N;;;;; 2F921;CJK COMPATIBILITY I|
1305      {8:    }DEOGRAPH-2F921;Lo;0;L;7235;;;;N;;;;;|
1306      {8:    } 2F922;CJK COMPATIBILITY IDEOGRAPH-2|
1307      {8:    }F922;Lo;0;L;7250;;;;N;;;;;          |
1308      {8:  2 }^2F923;CJK COMPATIBILITY IDEOGRAPH-2F|
1309      {8:    }923;Lo;0;L;24608;;;;N;;;;;          |
1310      {8:  3 }2F924;CJK COMPATIBILITY IDEOGRAPH-2F|
1311      {8:    }924;Lo;0;L;7280;;;;N;;;;;           |
1312                                              |
1313    ]])
1314  end)
1315
1316  it('works with very long line and scrolloff', function()
1317    screen:try_resize(40, 8)
1318    exec([[
1319      set smoothscroll scrolloff=3
1320      call setline(1, ['one', 'two long '->repeat(100), 'three', 'four', 'five', 'six'])
1321    ]])
1322    feed(':norm j721|<CR>')
1323    screen:expect([[
1324      {1:<<<}two long two long two long two long t|
1325      wo long two long two long two long two l|
1326      ong two long two long two long two long |
1327      ^two long two long two long two long two |
1328      long two long two long two long two long|
1329       two long two long two long two long two|
1330       long two long two long two long two lon|
1331      :norm j721|                             |
1332    ]])
1333    feed('gj')
1334    screen:expect([[
1335      {1:<<<}two long two long two long two long t|
1336      wo long two long two long two long two l|
1337      ong two long two long two long two long |
1338      two long two long two long two long two |
1339      ^long two long two long two long two long|
1340       two long two long two long two long two|
1341       long two long two long two long two lon|
1342      :norm j721|                             |
1343    ]])
1344    feed('gj')
1345    screen:expect([[
1346      {1:<<<}long two long two long two long two l|
1347      ong two long two long two long two long |
1348      two long two long two long two long two |
1349      long two long two long two long two long|
1350      ^ two long two long two long two long two|
1351       long two long two long two long two lon|
1352      g two long two long                     |
1353      :norm j721|                             |
1354    ]])
1355    feed('gj')
1356    screen:expect([[
1357      {1:<<<}long two long two long two long two l|
1358      ong two long two long two long two long |
1359      two long two long two long two long two |
1360      long two long two long two long two long|
1361       two long two long two long two long two|
1362      ^ long two long two long two long two lon|
1363      g two long two long                     |
1364      :norm j721|                             |
1365    ]])
1366    feed('gj')
1367    screen:expect([[
1368      {1:<<<}long two long two long two long two l|
1369      ong two long two long two long two long |
1370      two long two long two long two long two |
1371      long two long two long two long two long|
1372       two long two long two long two long two|
1373       long two long two long two long two lon|
1374      ^g two long two long                     |
1375      :norm j721|                             |
1376    ]])
1377    feed('gj')
1378    screen:expect([[
1379      {1:<<<} long two long two long two long two |
1380      long two long two long two long two long|
1381       two long two long two long two long two|
1382       long two long two long two long two lon|
1383      g two long two long                     |
1384      ^three                                   |
1385      four                                    |
1386      :norm j721|                             |
1387    ]])
1388    feed('gk')
1389    screen:expect([[
1390      {1:<<<}long two long two long two long two l|
1391      ong two long two long two long two long |
1392      two long two long two long two long two |
1393      long two long two long two long two long|
1394       two long two long two long two long two|
1395       long two long two long two long two lon|
1396      ^g two long two long                     |
1397      :norm j721|                             |
1398    ]])
1399  end)
1400end)
1401
1402describe('scrolloffpad', function()
1403  local screen
1404
1405  before_each(function()
1406    screen = Screen.new(78, 20)
1407  end)
1408
1409  -- oldtest: Test_scrolloffpad_basic()
1410  it('works', function()
1411    exec([[
1412      set scrolloff=10
1413      set scrolloffpad=5
1414      enew!
1415      call setline(1, map(range(1, 100), 'printf("line %d", v:val)'))
1416      normal! gg
1417    ]])
1418
1419    -- Enabled: scrolloffpad > 0, expect EOF centering/padding
1420    exec('normal! G')
1421    screen:expect([[
1422      line 91                                                                       |
1423      line 92                                                                       |
1424      line 93                                                                       |
1425      line 94                                                                       |
1426      line 95                                                                       |
1427      line 96                                                                       |
1428      line 97                                                                       |
1429      line 98                                                                       |
1430      line 99                                                                       |
1431      ^line 100                                                                      |
1432      {1:~                                                                             }|*9
1433                                                                                    |
1434    ]])
1435
1436    -- Beginning-of-file is unchanged (Top)
1437    exec('normal! gg')
1438    screen:expect([[
1439      ^line 1                                                                        |
1440      line 2                                                                        |
1441      line 3                                                                        |
1442      line 4                                                                        |
1443      line 5                                                                        |
1444      line 6                                                                        |
1445      line 7                                                                        |
1446      line 8                                                                        |
1447      line 9                                                                        |
1448      line 10                                                                       |
1449      line 11                                                                       |
1450      line 12                                                                       |
1451      line 13                                                                       |
1452      line 14                                                                       |
1453      line 15                                                                       |
1454      line 16                                                                       |
1455      line 17                                                                       |
1456      line 18                                                                       |
1457      line 19                                                                       |
1458                                                                                    |
1459    ]])
1460
1461    -- Gating: disable scrolloffpad, then go to EOF again
1462    -- Expect normal EOF behavior (no extra centering/padding)
1463    exec('set scrolloffpad=0')
1464    exec('normal! G')
1465    screen:expect([[
1466      line 82                                                                       |
1467      line 83                                                                       |
1468      line 84                                                                       |
1469      line 85                                                                       |
1470      line 86                                                                       |
1471      line 87                                                                       |
1472      line 88                                                                       |
1473      line 89                                                                       |
1474      line 90                                                                       |
1475      line 91                                                                       |
1476      line 92                                                                       |
1477      line 93                                                                       |
1478      line 94                                                                       |
1479      line 95                                                                       |
1480      line 96                                                                       |
1481      line 97                                                                       |
1482      line 98                                                                       |
1483      line 99                                                                       |
1484      ^line 100                                                                      |
1485                                                                                    |
1486    ]])
1487  end)
1488
1489  -- oldtest: Test_scrolloffpad_smoothscroll()
1490  it('works with smoothscroll', function()
1491    exec([[
1492      set smoothscroll scrolloff=10 scrolloffpad=1
1493      enew!
1494      call setline(1, map(range(1, 100), 'printf("line %d", v:val)'))
1495      normal! gg
1496    ]])
1497
1498    exec('normal! G')
1499    screen:expect([[
1500      line 91                                                                       |
1501      line 92                                                                       |
1502      line 93                                                                       |
1503      line 94                                                                       |
1504      line 95                                                                       |
1505      line 96                                                                       |
1506      line 97                                                                       |
1507      line 98                                                                       |
1508      line 99                                                                       |
1509      ^line 100                                                                      |
1510      {1:~                                                                             }|*9
1511                                                                                    |
1512    ]])
1513
1514    exec([[call setline(line('$'), repeat('LONG ', 30))]])
1515    exec('normal! 41|')
1516    screen:expect([[
1517      line 92                                                                       |
1518      line 93                                                                       |
1519      line 94                                                                       |
1520      line 95                                                                       |
1521      line 96                                                                       |
1522      line 97                                                                       |
1523      line 98                                                                       |
1524      line 99                                                                       |
1525      LONG LONG LONG LONG LONG LONG LONG LONG ^LONG LONG LONG LONG LONG LONG LONG LON|
1526      G LONG LONG LONG LONG LONG LONG LONG LONG LONG LONG LONG LONG LONG LONG       |
1527      {1:~                                                                             }|*9
1528                                                                                    |
1529    ]])
1530  end)
1531
1532  -- oldtest: Test_scrolloffpad_with_folds()
1533  it('works with folds', function()
1534    exec([[
1535      set scrolloff=10
1536      set scrolloffpad=1
1537
1538      enew
1539      call setline(1, map(range(1, 120), {_, v -> 'line ' . v}))
1540
1541      " Create a large fold near the end of the file.
1542      " Fold lines 60-110, leaving 111-120 visible after the fold.
1543      set foldmethod=manual
1544      set foldenable
1545      normal! gg
1546      normal! 60G
1547      normal! zf50j
1548      normal! gg
1549    ]])
1550
1551    -- Case 1: Jump to end-of-file
1552    -- With folds present, scrolloffpad should still
1553    -- keep the cursor positioned with padding below EOF
1554    exec('normal! G')
1555    local s1 = [[
1556      line 111                                                                      |
1557      line 112                                                                      |
1558      line 113                                                                      |
1559      line 114                                                                      |
1560      line 115                                                                      |
1561      line 116                                                                      |
1562      line 117                                                                      |
1563      line 118                                                                      |
1564      line 119                                                                      |
1565      ^line 120                                                                      |
1566      {1:~                                                                             }|*9
1567                                                                                    |
1568    ]]
1569    screen:expect(s1)
1570
1571    -- Case 2: Move to the folded line to ensure the fold is actually in view
1572    exec('normal! 60G')
1573    screen:expect([[
1574      line 51                                                                       |
1575      line 52                                                                       |
1576      line 53                                                                       |
1577      line 54                                                                       |
1578      line 55                                                                       |
1579      line 56                                                                       |
1580      line 57                                                                       |
1581      line 58                                                                       |
1582      line 59                                                                       |
1583      {13:^+-- 51 lines: line 60·························································}|
1584      line 111                                                                      |
1585      line 112                                                                      |
1586      line 113                                                                      |
1587      line 114                                                                      |
1588      line 115                                                                      |
1589      line 116                                                                      |
1590      line 117                                                                      |
1591      line 118                                                                      |
1592      line 119                                                                      |
1593                                                                                    |
1594    ]])
1595
1596    -- Case 3: Close the fold explicitly and go to EOF again
1597    -- Behavior should remain stable with closed folds
1598    exec('normal! zc')
1599    exec('normal! G')
1600    screen:expect(s1)
1601  end)
1602
1603  it("uses the target window's value, not the current window's", function()
1604    exec([[
1605      set scrolloff=10 scrolloffpad=0
1606      enew!
1607      call setline(1, map(range(1, 100), 'printf("line %d", v:val)'))
1608      split
1609      setlocal scrolloffpad=5
1610      normal! G
1611      wincmd j
1612      silent 1,60d
1613    ]])
1614    -- The upper window turned 'scrolloffpad' on for itself, so its own value
1615    -- decides how far its cursor is padded from the end of the buffer, even
1616    -- though the current window leaves the option at the global 0.
1617    t.eq(36, n.fn.line('w0', n.fn.win_getid(1)))
1618  end)
1619end)
1620
1621describe('scroll_cursor_halfway()', function()
1622  local screen
1623
1624  before_each(function()
1625    screen = Screen.new(40, 12)
1626  end)
1627
1628  it('weighs lines by their screen height', function()
1629    exec([[
1630      set nosmoothscroll scrolloff=0
1631      call setline(1, map(range(1, 20), '"short " .. v:val'))
1632      call append(20, 'CURSOR')
1633      call append(21, map(range(1, 8), 'repeat("x", 200)'))
1634    ]])
1635    feed('21Gzz')
1636    -- The lines below the cursor wrap to five rows each, so only one of them
1637    -- fits under the cursor once it sits on row 6 of this 11 row window.
1638    screen:expect([[
1639      short 16                                |
1640      short 17                                |
1641      short 18                                |
1642      short 19                                |
1643      short 20                                |
1644      ^CURSOR                                  |
1645      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|*5
1646                                              |
1647    ]])
1648  end)
1649end)