test_scroll_opt.vim 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. " Test for 'scroll', 'scrolloff', 'smoothscroll', etc.
  2. source check.vim
  3. source screendump.vim
  4. source mouse.vim
  5. func Test_reset_scroll()
  6. let scr = &l:scroll
  7. setlocal scroll=1
  8. setlocal scroll&
  9. call assert_equal(scr, &l:scroll)
  10. setlocal scroll=1
  11. setlocal scroll=0
  12. call assert_equal(scr, &l:scroll)
  13. try
  14. execute 'setlocal scroll=' . (winheight(0) + 1)
  15. " not reached
  16. call assert_false(1)
  17. catch
  18. call assert_exception('E49:')
  19. endtry
  20. split
  21. let scr = &l:scroll
  22. setlocal scroll=1
  23. setlocal scroll&
  24. call assert_equal(scr, &l:scroll)
  25. setlocal scroll=1
  26. setlocal scroll=0
  27. call assert_equal(scr, &l:scroll)
  28. quit!
  29. endfunc
  30. func Test_scolloff_even_line_count()
  31. new
  32. resize 6
  33. setlocal scrolloff=3
  34. call setline(1, range(20))
  35. normal 2j
  36. call assert_equal(1, getwininfo(win_getid())[0].topline)
  37. normal j
  38. call assert_equal(1, getwininfo(win_getid())[0].topline)
  39. normal j
  40. call assert_equal(2, getwininfo(win_getid())[0].topline)
  41. normal j
  42. call assert_equal(3, getwininfo(win_getid())[0].topline)
  43. bwipe!
  44. endfunc
  45. func Test_mouse_scroll_inactive_with_cursorbind()
  46. for scb in [0, 1]
  47. for so in [0, 1, 2]
  48. let msg = $'scb={scb} so={so}'
  49. new | only
  50. let w1 = win_getid()
  51. setlocal cursorbind
  52. let &l:scb = scb
  53. let &l:so = so
  54. call setline(1, range(101, 109))
  55. rightbelow vnew
  56. let w2 = win_getid()
  57. setlocal cursorbind
  58. let &l:scb = scb
  59. let &l:so = so
  60. call setline(1, range(101, 109))
  61. normal! $
  62. call assert_equal(3, col('.', w1), msg)
  63. call assert_equal(3, col('.', w2), msg)
  64. call Ntest_setmouse(1, 1)
  65. call feedkeys("\<ScrollWheelDown>", 'xt')
  66. call assert_equal(4, line('w0', w1), msg)
  67. call assert_equal(4 + so, line('.', w1), msg)
  68. call assert_equal(1, line('w0', w2), msg)
  69. call assert_equal(1, line('.', w2), msg)
  70. call feedkeys("\<ScrollWheelDown>", 'xt')
  71. call assert_equal(7, line('w0', w1), msg)
  72. call assert_equal(7 + so, line('.', w1), msg)
  73. call assert_equal(1, line('w0', w2), msg)
  74. call assert_equal(1, line('.', w2), msg)
  75. call feedkeys("\<ScrollWheelUp>", 'xt')
  76. call assert_equal(4, line('w0', w1), msg)
  77. call assert_equal(7 + so, line('.', w1), msg)
  78. call assert_equal(1, line('w0', w2), msg)
  79. call assert_equal(1, line('.', w2), msg)
  80. call feedkeys("\<ScrollWheelUp>", 'xt')
  81. call assert_equal(1, line('w0', w1), msg)
  82. call assert_equal(7 + so, line('.', w1), msg)
  83. call assert_equal(1, line('w0', w2), msg)
  84. call assert_equal(1, line('.', w2), msg)
  85. normal! 0
  86. call assert_equal(1, line('.', w1), msg)
  87. call assert_equal(1, col('.', w1), msg)
  88. call assert_equal(1, line('.', w2), msg)
  89. call assert_equal(1, col('.', w2), msg)
  90. bwipe!
  91. bwipe!
  92. endfor
  93. endfor
  94. endfunc
  95. func Test_CtrlE_CtrlY_stop_at_end()
  96. enew
  97. call setline(1, ['one', 'two'])
  98. set number
  99. exe "normal \<C-Y>"
  100. call assert_equal([" 1 one "], ScreenLines(1, 10))
  101. exe "normal \<C-E>\<C-E>\<C-E>"
  102. call assert_equal([" 2 two "], ScreenLines(1, 10))
  103. bwipe!
  104. set nonumber
  105. endfunc
  106. func Test_smoothscroll_CtrlE_CtrlY()
  107. CheckScreendump
  108. let lines =<< trim END
  109. vim9script
  110. setline(1, [
  111. 'line one',
  112. 'word '->repeat(20),
  113. 'line three',
  114. 'long word '->repeat(7),
  115. 'line',
  116. 'line',
  117. 'line',
  118. ])
  119. set smoothscroll
  120. :5
  121. END
  122. call writefile(lines, 'XSmoothScroll', 'D')
  123. let buf = RunVimInTerminal('-S XSmoothScroll', #{rows: 12, cols: 40})
  124. call term_sendkeys(buf, "\<C-E>")
  125. call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
  126. call term_sendkeys(buf, "\<C-E>")
  127. call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
  128. call term_sendkeys(buf, "\<C-E>")
  129. call VerifyScreenDump(buf, 'Test_smoothscroll_3', {})
  130. call term_sendkeys(buf, "\<C-E>")
  131. call VerifyScreenDump(buf, 'Test_smoothscroll_4', {})
  132. call term_sendkeys(buf, "\<C-Y>")
  133. call VerifyScreenDump(buf, 'Test_smoothscroll_5', {})
  134. call term_sendkeys(buf, "\<C-Y>")
  135. call VerifyScreenDump(buf, 'Test_smoothscroll_6', {})
  136. call term_sendkeys(buf, "\<C-Y>")
  137. call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
  138. call term_sendkeys(buf, "\<C-Y>")
  139. call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
  140. if has('folding')
  141. call term_sendkeys(buf, ":set foldmethod=indent\<CR>")
  142. " move the cursor so we can reuse the same dumps
  143. call term_sendkeys(buf, "5G")
  144. call term_sendkeys(buf, "\<C-E>")
  145. call VerifyScreenDump(buf, 'Test_smoothscroll_1', {})
  146. call term_sendkeys(buf, "\<C-E>")
  147. call VerifyScreenDump(buf, 'Test_smoothscroll_2', {})
  148. call term_sendkeys(buf, "7G")
  149. call term_sendkeys(buf, "\<C-Y>")
  150. call VerifyScreenDump(buf, 'Test_smoothscroll_7', {})
  151. call term_sendkeys(buf, "\<C-Y>")
  152. call VerifyScreenDump(buf, 'Test_smoothscroll_8', {})
  153. endif
  154. call StopVimInTerminal(buf)
  155. endfunc
  156. func Test_smoothscroll_multibyte()
  157. CheckScreendump
  158. let lines =<< trim END
  159. set scrolloff=0 smoothscroll
  160. call setline(1, [repeat('ϛ', 45), repeat('2', 36)])
  161. exe "normal G35l\<C-E>k"
  162. END
  163. call writefile(lines, 'XSmoothMultibyte', 'D')
  164. let buf = RunVimInTerminal('-S XSmoothMultibyte', #{rows: 6, cols: 40})
  165. call VerifyScreenDump(buf, 'Test_smoothscroll_multi_1', {})
  166. call StopVimInTerminal(buf)
  167. endfunc
  168. func Test_smoothscroll_number()
  169. CheckScreendump
  170. let lines =<< trim END
  171. vim9script
  172. setline(1, [
  173. 'one ' .. 'word '->repeat(20),
  174. 'two ' .. 'long word '->repeat(7),
  175. 'line',
  176. 'line',
  177. 'line',
  178. ])
  179. set smoothscroll
  180. set splitkeep=topline
  181. set number cpo+=n
  182. :3
  183. def g:DoRel()
  184. set number relativenumber scrolloff=0
  185. :%del
  186. setline(1, [
  187. 'one',
  188. 'very long text '->repeat(12),
  189. 'three',
  190. ])
  191. exe "normal 2Gzt\<C-E>"
  192. enddef
  193. END
  194. call writefile(lines, 'XSmoothNumber', 'D')
  195. let buf = RunVimInTerminal('-S XSmoothNumber', #{rows: 12, cols: 40})
  196. call VerifyScreenDump(buf, 'Test_smooth_number_1', {})
  197. call term_sendkeys(buf, "\<C-E>")
  198. call VerifyScreenDump(buf, 'Test_smooth_number_2', {})
  199. call term_sendkeys(buf, "\<C-E>")
  200. call VerifyScreenDump(buf, 'Test_smooth_number_3', {})
  201. call term_sendkeys(buf, ":set cpo-=n\<CR>")
  202. call VerifyScreenDump(buf, 'Test_smooth_number_4', {})
  203. call term_sendkeys(buf, "\<C-Y>")
  204. call VerifyScreenDump(buf, 'Test_smooth_number_5', {})
  205. call term_sendkeys(buf, "\<C-Y>")
  206. call VerifyScreenDump(buf, 'Test_smooth_number_6', {})
  207. call term_sendkeys(buf, ":botright split\<CR>gg")
  208. call VerifyScreenDump(buf, 'Test_smooth_number_7', {})
  209. call term_sendkeys(buf, "\<C-E>")
  210. call VerifyScreenDump(buf, 'Test_smooth_number_8', {})
  211. call term_sendkeys(buf, "\<C-E>")
  212. call VerifyScreenDump(buf, 'Test_smooth_number_9', {})
  213. call term_sendkeys(buf, ":close\<CR>")
  214. call term_sendkeys(buf, ":call DoRel()\<CR>")
  215. call VerifyScreenDump(buf, 'Test_smooth_number_10', {})
  216. call StopVimInTerminal(buf)
  217. endfunc
  218. func Test_smoothscroll_list()
  219. CheckScreendump
  220. let lines =<< trim END
  221. vim9script
  222. set smoothscroll scrolloff=0
  223. set list
  224. setline(1, [
  225. 'one',
  226. 'very long text '->repeat(12),
  227. 'three',
  228. ])
  229. exe "normal 2Gzt\<C-E>"
  230. END
  231. call writefile(lines, 'XSmoothList', 'D')
  232. let buf = RunVimInTerminal('-S XSmoothList', #{rows: 8, cols: 40})
  233. call VerifyScreenDump(buf, 'Test_smooth_list_1', {})
  234. call term_sendkeys(buf, ":set listchars+=precedes:#\<CR>")
  235. call VerifyScreenDump(buf, 'Test_smooth_list_2', {})
  236. call StopVimInTerminal(buf)
  237. endfunc
  238. func Test_smoothscroll_diff_mode()
  239. CheckScreendump
  240. let lines =<< trim END
  241. vim9script
  242. var text = 'just some text here'
  243. setline(1, text)
  244. set smoothscroll
  245. diffthis
  246. new
  247. setline(1, text)
  248. set smoothscroll
  249. diffthis
  250. END
  251. call writefile(lines, 'XSmoothDiff', 'D')
  252. let buf = RunVimInTerminal('-S XSmoothDiff', #{rows: 8})
  253. call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
  254. call term_sendkeys(buf, "\<C-Y>")
  255. call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
  256. call term_sendkeys(buf, "\<C-E>")
  257. call VerifyScreenDump(buf, 'Test_smooth_diff_1', {})
  258. call StopVimInTerminal(buf)
  259. endfunc
  260. func Test_smoothscroll_diff_change_line()
  261. CheckScreendump
  262. let lines =<< trim END
  263. set diffopt+=followwrap smoothscroll
  264. call setline(1, repeat(' abc', &columns))
  265. call setline(2, 'bar')
  266. call setline(3, repeat(' abc', &columns))
  267. vnew
  268. call setline(1, repeat(' abc', &columns))
  269. call setline(2, 'foo')
  270. call setline(3, 'bar')
  271. call setline(4, repeat(' abc', &columns))
  272. windo exe "normal! 2gg5\<C-E>"
  273. windo diffthis
  274. END
  275. call writefile(lines, 'XSmoothDiffChangeLine', 'D')
  276. let buf = RunVimInTerminal('-S XSmoothDiffChangeLine', #{rows: 20, columns: 55})
  277. call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_1', {})
  278. call term_sendkeys(buf, "Abar")
  279. call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_2', {})
  280. call term_sendkeys(buf, "\<Esc>")
  281. call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_3', {})
  282. call term_sendkeys(buf, "yyp")
  283. call VerifyScreenDump(buf, 'Test_smooth_diff_change_line_4', {})
  284. call StopVimInTerminal(buf)
  285. endfunc
  286. func Test_smoothscroll_wrap_scrolloff_zero()
  287. CheckScreendump
  288. let lines =<< trim END
  289. vim9script
  290. setline(1, ['Line' .. (' with some text'->repeat(7))]->repeat(7))
  291. set smoothscroll scrolloff=0
  292. :3
  293. END
  294. call writefile(lines, 'XSmoothWrap', 'D')
  295. let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 8, cols: 40})
  296. call VerifyScreenDump(buf, 'Test_smooth_wrap_1', {})
  297. " moving cursor down - whole bottom line shows
  298. call term_sendkeys(buf, "j")
  299. call VerifyScreenDump(buf, 'Test_smooth_wrap_2', {})
  300. call term_sendkeys(buf, "\<C-E>j")
  301. call VerifyScreenDump(buf, 'Test_smooth_wrap_3', {})
  302. call term_sendkeys(buf, "G")
  303. call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
  304. call term_sendkeys(buf, "4\<C-Y>G")
  305. call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})
  306. " moving cursor up right after the <<< marker - no need to show whole line
  307. call term_sendkeys(buf, "2gj3l2k")
  308. call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})
  309. " moving cursor up where the <<< marker is - whole top line shows
  310. call term_sendkeys(buf, "2j02k")
  311. call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {})
  312. call StopVimInTerminal(buf)
  313. endfunc
  314. func Test_smoothscroll_wrap_long_line()
  315. CheckScreendump
  316. let lines =<< trim END
  317. vim9script
  318. setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(30)) .. ' end', 'four'])
  319. set smoothscroll scrolloff=0
  320. normal 3G10|zt
  321. END
  322. call writefile(lines, 'XSmoothWrap', 'D')
  323. let buf = RunVimInTerminal('-S XSmoothWrap', #{rows: 6, cols: 40})
  324. call VerifyScreenDump(buf, 'Test_smooth_long_1', {})
  325. " scrolling up, cursor moves screen line down
  326. call term_sendkeys(buf, "\<C-E>")
  327. call VerifyScreenDump(buf, 'Test_smooth_long_2', {})
  328. call term_sendkeys(buf, "5\<C-E>")
  329. call VerifyScreenDump(buf, 'Test_smooth_long_3', {})
  330. " scrolling down, cursor moves screen line up
  331. call term_sendkeys(buf, "5\<C-Y>")
  332. call VerifyScreenDump(buf, 'Test_smooth_long_4', {})
  333. call term_sendkeys(buf, "\<C-Y>")
  334. call VerifyScreenDump(buf, 'Test_smooth_long_5', {})
  335. " 'scrolloff' set to 1, scrolling up, cursor moves screen line down
  336. call term_sendkeys(buf, ":set scrolloff=1\<CR>")
  337. call term_sendkeys(buf, "10|\<C-E>")
  338. call VerifyScreenDump(buf, 'Test_smooth_long_6', {})
  339. " 'scrolloff' set to 1, scrolling down, cursor moves screen line up
  340. call term_sendkeys(buf, "\<C-E>")
  341. call term_sendkeys(buf, "gjgj")
  342. call term_sendkeys(buf, "\<C-Y>")
  343. call VerifyScreenDump(buf, 'Test_smooth_long_7', {})
  344. " 'scrolloff' set to 2, scrolling up, cursor moves screen line down
  345. call term_sendkeys(buf, ":set scrolloff=2\<CR>")
  346. call term_sendkeys(buf, "10|\<C-E>")
  347. call VerifyScreenDump(buf, 'Test_smooth_long_8', {})
  348. " 'scrolloff' set to 2, scrolling down, cursor moves screen line up
  349. call term_sendkeys(buf, "\<C-E>")
  350. call term_sendkeys(buf, "gj")
  351. call term_sendkeys(buf, "\<C-Y>")
  352. call VerifyScreenDump(buf, 'Test_smooth_long_9', {})
  353. " 'scrolloff' set to 0, move cursor down one line.
  354. " Cursor should move properly, and since this is a really long line, it will
  355. " be put on top of the screen.
  356. call term_sendkeys(buf, ":set scrolloff=0\<CR>")
  357. call term_sendkeys(buf, "0j")
  358. call VerifyScreenDump(buf, 'Test_smooth_long_10', {})
  359. " Test zt/zz/zb that they work properly when a long line is above it
  360. call term_sendkeys(buf, "zt")
  361. call VerifyScreenDump(buf, 'Test_smooth_long_11', {})
  362. call term_sendkeys(buf, "zz")
  363. call VerifyScreenDump(buf, 'Test_smooth_long_12', {})
  364. call term_sendkeys(buf, "zb")
  365. call VerifyScreenDump(buf, 'Test_smooth_long_13', {})
  366. " Repeat the step and move the cursor down again.
  367. " This time, use a shorter long line that is barely long enough to span more
  368. " than one window. Note that the cursor is at the bottom this time because
  369. " Vim prefers to do so if we are scrolling a few lines only.
  370. call term_sendkeys(buf, ":call setline(1, ['one', 'two', 'Line' .. (' with lots of text'->repeat(10)) .. ' end', 'four'])\<CR>")
  371. " Currently visible lines were replaced, test that the lines and cursor
  372. " are correctly displayed.
  373. call VerifyScreenDump(buf, 'Test_smooth_long_14', {})
  374. call term_sendkeys(buf, "3Gzt")
  375. call term_sendkeys(buf, "j")
  376. call VerifyScreenDump(buf, 'Test_smooth_long_15', {})
  377. " Repeat the step but this time start it when the line is smooth-scrolled by
  378. " one line. This tests that the offset calculation is still correct and
  379. " still end up scrolling down to the next line with cursor at bottom of
  380. " screen.
  381. call term_sendkeys(buf, "3Gzt")
  382. call term_sendkeys(buf, "\<C-E>j")
  383. call VerifyScreenDump(buf, 'Test_smooth_long_16', {})
  384. call StopVimInTerminal(buf)
  385. endfunc
  386. func Test_smoothscroll_one_long_line()
  387. CheckScreendump
  388. let lines =<< trim END
  389. vim9script
  390. setline(1, 'with lots of text '->repeat(7))
  391. set smoothscroll scrolloff=0
  392. END
  393. call writefile(lines, 'XSmoothOneLong', 'D')
  394. let buf = RunVimInTerminal('-S XSmoothOneLong', #{rows: 6, cols: 40})
  395. call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
  396. call term_sendkeys(buf, "\<C-E>")
  397. call VerifyScreenDump(buf, 'Test_smooth_one_long_2', {})
  398. call term_sendkeys(buf, "0")
  399. call VerifyScreenDump(buf, 'Test_smooth_one_long_1', {})
  400. call StopVimInTerminal(buf)
  401. endfunc
  402. func Test_smoothscroll_long_line_showbreak()
  403. CheckScreendump
  404. let lines =<< trim END
  405. vim9script
  406. # a line that spans four screen lines
  407. setline(1, 'with lots of text in one line '->repeat(6))
  408. set smoothscroll scrolloff=0 showbreak=+++\
  409. END
  410. call writefile(lines, 'XSmoothLongShowbreak', 'D')
  411. let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40})
  412. call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
  413. call term_sendkeys(buf, "\<C-E>")
  414. call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {})
  415. call term_sendkeys(buf, "0")
  416. call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})
  417. call StopVimInTerminal(buf)
  418. endfunc
  419. " Check that 'smoothscroll' marker is drawn over double-width char correctly.
  420. " Run with multiple encodings.
  421. func Test_smoothscroll_marker_over_double_width()
  422. " Run this in a separate Vim instance to avoid messing up.
  423. let after =<< trim [CODE]
  424. scriptencoding utf-8
  425. call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10))
  426. setlocal smoothscroll
  427. redraw
  428. exe "norm \<C-E>"
  429. redraw
  430. " Check the chars one by one. Don't check the whole line concatenated.
  431. call assert_equal('<', screenstring(1, 1))
  432. call assert_equal('<', screenstring(1, 2))
  433. call assert_equal('<', screenstring(1, 3))
  434. call assert_equal(' ', screenstring(1, 4))
  435. call assert_equal('口', screenstring(1, 5))
  436. call assert_equal('口', screenstring(1, 7))
  437. call assert_equal('口', screenstring(1, 9))
  438. call assert_equal('口', screenstring(1, 11))
  439. call assert_equal('口', screenstring(1, 13))
  440. call assert_equal('口', screenstring(1, 15))
  441. call writefile(v:errors, 'Xresult')
  442. qall!
  443. [CODE]
  444. let encodings = ['utf-8', 'cp932', 'cp936', 'cp949', 'cp950']
  445. if !has('win32')
  446. let encodings += ['euc-jp']
  447. endif
  448. if has('nvim')
  449. let encodings = ['utf-8']
  450. endif
  451. for enc in encodings
  452. let msg = 'enc=' .. enc
  453. if RunVim([], after, $'--clean --cmd "set encoding={enc}"')
  454. call assert_equal([], readfile('Xresult'), msg)
  455. endif
  456. call delete('Xresult')
  457. endfor
  458. endfunc
  459. " Same as the test above, but check the text actually shown on screen.
  460. " Only run with UTF-8 encoding.
  461. func Test_smoothscroll_marker_over_double_width_dump()
  462. CheckScreendump
  463. let lines =<< trim END
  464. call setline(1, 'a'->repeat(&columns) .. '口'->repeat(10))
  465. setlocal smoothscroll
  466. END
  467. call writefile(lines, 'XSmoothMarkerOverDoubleWidth', 'D')
  468. let buf = RunVimInTerminal('-S XSmoothMarkerOverDoubleWidth', #{rows: 6, cols: 40})
  469. call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_1', {})
  470. call term_sendkeys(buf, "\<C-E>")
  471. call VerifyScreenDump(buf, 'Test_smooth_marker_over_double_width_2', {})
  472. call StopVimInTerminal(buf)
  473. endfunc
  474. func s:check_col_calc(win_col, win_line, buf_col)
  475. call assert_equal(a:win_col, wincol())
  476. call assert_equal(a:win_line, winline())
  477. call assert_equal(a:buf_col, col('.'))
  478. endfunc
  479. " Test that if the current cursor is on a smooth scrolled line, we correctly
  480. " reposition it. Also check that we don't miscalculate the values by checking
  481. " the consistency between wincol() and col('.') as they are calculated
  482. " separately in code.
  483. func Test_smoothscroll_cursor_position()
  484. call NewWindow(10, 20)
  485. setl smoothscroll wrap
  486. call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
  487. call s:check_col_calc(1, 1, 1)
  488. exe "normal \<C-E>"
  489. " Move down another line to avoid blocking the <<< display
  490. call s:check_col_calc(1, 2, 41)
  491. exe "normal \<C-Y>"
  492. call s:check_col_calc(1, 3, 41)
  493. " Test "g0/g<Home>"
  494. exe "normal gg\<C-E>"
  495. norm $gkg0
  496. call s:check_col_calc(4, 1, 24)
  497. " Test moving the cursor behind the <<< display with 'virtualedit'
  498. set virtualedit=all
  499. exe "normal \<C-E>gkh"
  500. call s:check_col_calc(3, 2, 23)
  501. set virtualedit&
  502. normal gg3l
  503. exe "normal \<C-E>"
  504. " Move down only 1 line when we are out of the range of the <<< display
  505. call s:check_col_calc(4, 1, 24)
  506. exe "normal \<C-Y>"
  507. call s:check_col_calc(4, 2, 24)
  508. normal ggg$
  509. exe "normal \<C-E>"
  510. call s:check_col_calc(20, 1, 40)
  511. exe "normal \<C-Y>"
  512. call s:check_col_calc(20, 2, 40)
  513. normal gg
  514. " Test number, where we have indented lines
  515. setl number
  516. call s:check_col_calc(5, 1, 1)
  517. exe "normal \<C-E>"
  518. " Move down only 1 line when the <<< display is on the number column
  519. call s:check_col_calc(5, 1, 17)
  520. exe "normal \<C-Y>"
  521. call s:check_col_calc(5, 2, 17)
  522. normal ggg$
  523. exe "normal \<C-E>"
  524. call s:check_col_calc(20, 1, 32)
  525. exe "normal \<C-Y>"
  526. call s:check_col_calc(20, 2, 32)
  527. normal gg
  528. setl numberwidth=1
  529. " Move down another line when numberwidth is too short to cover the whole
  530. " <<< display
  531. call s:check_col_calc(3, 1, 1)
  532. exe "normal \<C-E>"
  533. call s:check_col_calc(3, 2, 37)
  534. exe "normal \<C-Y>"
  535. call s:check_col_calc(3, 3, 37)
  536. normal ggl
  537. " Only move 1 line down when we are just past the <<< display
  538. call s:check_col_calc(4, 1, 2)
  539. exe "normal \<C-E>"
  540. call s:check_col_calc(4, 1, 20)
  541. exe "normal \<C-Y>"
  542. call s:check_col_calc(4, 2, 20)
  543. normal gg
  544. setl numberwidth&
  545. " Test number + showbreak, so test that the additional indentation works
  546. setl number showbreak=+++
  547. call s:check_col_calc(5, 1, 1)
  548. exe "normal \<C-E>"
  549. call s:check_col_calc(8, 1, 17)
  550. exe "normal \<C-Y>"
  551. call s:check_col_calc(8, 2, 17)
  552. normal gg
  553. " Test number + cpo+=n mode, where wrapped lines aren't indented
  554. setl number cpo+=n showbreak=
  555. call s:check_col_calc(5, 1, 1)
  556. exe "normal \<C-E>"
  557. call s:check_col_calc(1, 2, 37)
  558. exe "normal \<C-Y>"
  559. call s:check_col_calc(1, 3, 37)
  560. normal gg
  561. " Test list + listchars "precedes", where there is always 1 overlap
  562. " regardless of number and cpo-=n.
  563. setl number list listchars=precedes:< cpo-=n
  564. call s:check_col_calc(5, 1, 1)
  565. exe "normal 3|\<C-E>h"
  566. call s:check_col_calc(6, 1, 18)
  567. norm h
  568. call s:check_col_calc(5, 2, 17)
  569. normal gg
  570. bwipe!
  571. endfunc
  572. func Test_smoothscroll_cursor_scrolloff()
  573. call NewWindow(10, 20)
  574. setl smoothscroll wrap
  575. setl scrolloff=3
  576. " 120 chars are 6 screen lines
  577. call setline(1, "abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST")
  578. call setline(2, "below")
  579. call s:check_col_calc(1, 1, 1)
  580. " CTRL-E shows "<<<DEFG...", cursor move four lines down
  581. exe "normal \<C-E>"
  582. call s:check_col_calc(1, 4, 81)
  583. " cursor on start of second line, "gk" moves into first line, skipcol doesn't
  584. " change
  585. exe "normal G0gk"
  586. call s:check_col_calc(1, 5, 101)
  587. " move cursor left one window width worth, scrolls one screen line
  588. exe "normal 20h"
  589. call s:check_col_calc(1, 5, 81)
  590. " move cursor left one window width worth, scrolls one screen line
  591. exe "normal 20h"
  592. call s:check_col_calc(1, 4, 61)
  593. " cursor on last line, "gk" should not cause a scroll
  594. set scrolloff=0
  595. normal G0
  596. call s:check_col_calc(1, 7, 1)
  597. normal gk
  598. call s:check_col_calc(1, 6, 101)
  599. bwipe!
  600. endfunc
  601. " Test that mouse picking is still accurate when we have smooth scrolled lines
  602. func Test_smoothscroll_mouse_pos()
  603. CheckNotGui
  604. CheckUnix
  605. let save_mouse = &mouse
  606. "let save_term = &term
  607. "let save_ttymouse = &ttymouse
  608. set mouse=a "term=xterm ttymouse=xterm2
  609. call NewWindow(10, 20)
  610. setl smoothscroll wrap
  611. " First line will wrap to 3 physical lines. 2nd/3rd lines are short lines.
  612. call setline(1, ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "line 2", "line 3"])
  613. func s:check_mouse_click(row, col, buf_row, buf_col)
  614. call MouseLeftClick(a:row, a:col)
  615. call assert_equal(a:col, wincol())
  616. call assert_equal(a:row, winline())
  617. call assert_equal(a:buf_row, line('.'))
  618. call assert_equal(a:buf_col, col('.'))
  619. endfunc
  620. " Check that clicking without scroll works first.
  621. call s:check_mouse_click(3, 5, 1, 45)
  622. call s:check_mouse_click(4, 1, 2, 1)
  623. call s:check_mouse_click(4, 6, 2, 6)
  624. call s:check_mouse_click(5, 1, 3, 1)
  625. call s:check_mouse_click(5, 6, 3, 6)
  626. " Smooth scroll, and checks that this didn't mess up mouse clicking
  627. exe "normal \<C-E>"
  628. call s:check_mouse_click(2, 5, 1, 45)
  629. call s:check_mouse_click(3, 1, 2, 1)
  630. call s:check_mouse_click(3, 6, 2, 6)
  631. call s:check_mouse_click(4, 1, 3, 1)
  632. call s:check_mouse_click(4, 6, 3, 6)
  633. exe "normal \<C-E>"
  634. call s:check_mouse_click(1, 5, 1, 45)
  635. call s:check_mouse_click(2, 1, 2, 1)
  636. call s:check_mouse_click(2, 6, 2, 6)
  637. call s:check_mouse_click(3, 1, 3, 1)
  638. call s:check_mouse_click(3, 6, 3, 6)
  639. " Make a new first line 11 physical lines tall so it's taller than window
  640. " height, to test overflow calculations with really long lines wrapping.
  641. normal gg
  642. call setline(1, "12345678901234567890"->repeat(11))
  643. exe "normal 6\<C-E>"
  644. call s:check_mouse_click(5, 1, 1, 201)
  645. call s:check_mouse_click(6, 1, 2, 1)
  646. call s:check_mouse_click(7, 1, 3, 1)
  647. let &mouse = save_mouse
  648. "let &term = save_term
  649. "let &ttymouse = save_ttymouse
  650. bwipe!
  651. endfunc
  652. " this was dividing by zero
  653. func Test_smoothscroll_zero_width()
  654. CheckScreendump
  655. let lines =<< trim END
  656. winsize 0 0
  657. vsplit
  658. vsplit
  659. vsplit
  660. vsplit
  661. vsplit
  662. sil norm H
  663. set wrap
  664. set smoothscroll
  665. set number
  666. END
  667. call writefile(lines, 'XSmoothScrollZero', 'D')
  668. let buf = RunVimInTerminal('-u NONE -i NONE -n -m -X -Z -e -s -S XSmoothScrollZero', #{rows: 6, cols: 60, wait_for_ruler: 0})
  669. call VerifyScreenDump(buf, 'Test_smoothscroll_zero_1', {})
  670. call term_sendkeys(buf, ":sil norm \<C-V>\<C-W>\<C-V>\<C-N>\<CR>")
  671. call VerifyScreenDump(buf, 'Test_smoothscroll_zero_2', {})
  672. call StopVimInTerminal(buf)
  673. endfunc
  674. " this was unnecessarily inserting lines
  675. func Test_smoothscroll_ins_lines()
  676. CheckScreendump
  677. let lines =<< trim END
  678. set wrap
  679. set smoothscroll
  680. set scrolloff=0
  681. set conceallevel=2
  682. call setline(1, [
  683. \'line one' .. 'with lots of text in one line '->repeat(2),
  684. \'line two',
  685. \'line three',
  686. \'line four',
  687. \'line five'
  688. \])
  689. END
  690. call writefile(lines, 'XSmoothScrollInsLines', 'D')
  691. let buf = RunVimInTerminal('-S XSmoothScrollInsLines', #{rows: 6, cols: 40})
  692. call term_sendkeys(buf, "\<C-E>gjgk")
  693. call VerifyScreenDump(buf, 'Test_smooth_ins_lines', {})
  694. call StopVimInTerminal(buf)
  695. endfunc
  696. " this placed the cursor in the command line
  697. func Test_smoothscroll_cursormoved_line()
  698. CheckScreendump
  699. let lines =<< trim END
  700. set smoothscroll
  701. call setline(1, [
  702. \'',
  703. \'_'->repeat(&lines * &columns),
  704. \(('_')->repeat(&columns - 2) .. 'xxx')->repeat(2)
  705. \])
  706. autocmd CursorMoved * eval [line('w0'), line('w$')]
  707. call search('xxx')
  708. END
  709. call writefile(lines, 'XSmoothCursorMovedLine', 'D')
  710. let buf = RunVimInTerminal('-S XSmoothCursorMovedLine', #{rows: 6})
  711. call VerifyScreenDump(buf, 'Test_smooth_cursormoved_line', {})
  712. call StopVimInTerminal(buf)
  713. endfunc
  714. func Test_smoothscroll_eob()
  715. CheckScreendump
  716. let lines =<< trim END
  717. set smoothscroll
  718. call setline(1, ['']->repeat(100))
  719. norm G
  720. END
  721. call writefile(lines, 'XSmoothEob', 'D')
  722. let buf = RunVimInTerminal('-S XSmoothEob', #{rows: 10})
  723. " does not scroll halfway when scrolling to end of buffer
  724. call VerifyScreenDump(buf, 'Test_smooth_eob_1', {})
  725. " cursor is not placed below window
  726. call term_sendkeys(buf, ":call setline(92, 'a'->repeat(100))\<CR>\<C-L>\<C-B>G")
  727. call VerifyScreenDump(buf, 'Test_smooth_eob_2', {})
  728. call StopVimInTerminal(buf)
  729. endfunc
  730. " skipcol should not reset when doing incremental search on the same word
  731. func Test_smoothscroll_incsearch()
  732. CheckScreendump
  733. let lines =<< trim END
  734. set smoothscroll number scrolloff=0 incsearch
  735. call setline(1, repeat([''], 20))
  736. call setline(11, repeat('a', 100))
  737. call setline(14, 'bbbb')
  738. END
  739. call writefile(lines, 'XSmoothIncsearch', 'D')
  740. let buf = RunVimInTerminal('-S XSmoothIncsearch', #{rows: 8, cols: 40})
  741. call term_sendkeys(buf, "/b")
  742. call VerifyScreenDump(buf, 'Test_smooth_incsearch_1', {})
  743. call term_sendkeys(buf, "b")
  744. call VerifyScreenDump(buf, 'Test_smooth_incsearch_2', {})
  745. call term_sendkeys(buf, "b")
  746. call VerifyScreenDump(buf, 'Test_smooth_incsearch_3', {})
  747. call term_sendkeys(buf, "b")
  748. call VerifyScreenDump(buf, 'Test_smooth_incsearch_4', {})
  749. call term_sendkeys(buf, "\<CR>")
  750. call StopVimInTerminal(buf)
  751. endfunc
  752. " Test scrolling multiple lines and stopping at non-zero skipcol.
  753. func Test_smoothscroll_multi_skipcol()
  754. CheckScreendump
  755. let lines =<< trim END
  756. setlocal cursorline scrolloff=0 smoothscroll
  757. call setline(1, repeat([''], 8))
  758. call setline(3, repeat('a', 50))
  759. call setline(4, repeat('a', 50))
  760. call setline(7, 'bbb')
  761. call setline(8, 'ccc')
  762. redraw
  763. END
  764. call writefile(lines, 'XSmoothMultiSkipcol', 'D')
  765. let buf = RunVimInTerminal('-S XSmoothMultiSkipcol', #{rows: 10, cols: 40})
  766. call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_1', {})
  767. call term_sendkeys(buf, "3\<C-E>")
  768. call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_2', {})
  769. call term_sendkeys(buf, "2\<C-E>")
  770. call VerifyScreenDump(buf, 'Test_smooth_multi_skipcol_3', {})
  771. call StopVimInTerminal(buf)
  772. endfunc
  773. " this was dividing by zero bug in scroll_cursor_bot
  774. func Test_smoothscroll_zero_width_scroll_cursor_bot()
  775. CheckScreendump
  776. let lines =<< trim END
  777. silent normal yy
  778. silent normal 19p
  779. set cpoptions+=n
  780. vsplit
  781. vertical resize 0
  782. set foldcolumn=1
  783. set number
  784. set smoothscroll
  785. silent normal 20G
  786. END
  787. call writefile(lines, 'XSmoothScrollZeroBot', 'D')
  788. let buf = RunVimInTerminal('-u NONE -S XSmoothScrollZeroBot', #{rows: 19})
  789. call VerifyScreenDump(buf, 'Test_smoothscroll_zero_bot', {})
  790. call StopVimInTerminal(buf)
  791. endfunc
  792. " scroll_cursor_top() should reset skipcol when it changes topline
  793. func Test_smoothscroll_cursor_top()
  794. CheckScreendump
  795. let lines =<< trim END
  796. set smoothscroll scrolloff=2
  797. new | 11resize | wincmd j
  798. call setline(1, ['line1', 'line2', 'line3'->repeat(20), 'line4'])
  799. exe "norm G3\<C-E>k"
  800. END
  801. call writefile(lines, 'XSmoothScrollCursorTop', 'D')
  802. let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCursorTop', #{rows: 12, cols: 40})
  803. call VerifyScreenDump(buf, 'Test_smoothscroll_cursor_top', {})
  804. call StopVimInTerminal(buf)
  805. endfunc
  806. " Division by zero, shouldn't crash
  807. func Test_smoothscroll_crash()
  808. CheckScreendump
  809. let lines =<< trim END
  810. 20 new
  811. vsp
  812. put =repeat('aaaa', 20)
  813. set nu fdc=1 smoothscroll cpo+=n
  814. vert resize 0
  815. exe "norm! 0\<c-e>"
  816. END
  817. call writefile(lines, 'XSmoothScrollCrash', 'D')
  818. let buf = RunVimInTerminal('-u NONE -S XSmoothScrollCrash', #{rows: 12, cols: 40})
  819. call term_sendkeys(buf, "2\<C-E>\<C-L>")
  820. call StopVimInTerminal(buf)
  821. endfunc
  822. func Test_smoothscroll_insert_bottom()
  823. CheckScreendump
  824. let lines =<< trim END
  825. call setline(1, repeat([repeat('A very long line ...', 10)], 5))
  826. set wrap smoothscroll scrolloff=0
  827. END
  828. call writefile(lines, 'XSmoothScrollInsertBottom', 'D')
  829. let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInsertBottom', #{rows: 9, cols: 40})
  830. call term_sendkeys(buf, "Go123456789\<CR>")
  831. call VerifyScreenDump(buf, 'Test_smoothscroll_insert_bottom', {})
  832. call StopVimInTerminal(buf)
  833. endfunc
  834. func Test_smoothscroll_in_qf_window()
  835. CheckFeature quickfix
  836. CheckScreendump
  837. let lines =<< trim END
  838. set nocompatible display=lastline
  839. copen 5
  840. setlocal number smoothscroll
  841. let g:l = [{'text': 'foo'}] + repeat([{'text': join(range(30))}], 10)
  842. call setqflist(g:l, 'r')
  843. normal! G
  844. wincmd t
  845. let g:l1 = [{'text': join(range(1000))}]
  846. END
  847. call writefile(lines, 'XSmoothScrollInQfWindow', 'D')
  848. let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInQfWindow', #{rows: 20, cols: 60})
  849. call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_1', {})
  850. call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>")
  851. call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {})
  852. call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>")
  853. call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {})
  854. call term_sendkeys(buf, ":call setqflist(g:l1, 'r')\<CR>")
  855. call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_4', {})
  856. call term_sendkeys(buf, "\<C-W>b$\<C-W>t")
  857. call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_5', {})
  858. call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>")
  859. call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {})
  860. call term_sendkeys(buf, ":call setqflist(g:l1, 'r')\<CR>")
  861. call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_4', {})
  862. call term_sendkeys(buf, "\<C-W>b$\<C-W>t")
  863. call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_5', {})
  864. call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>")
  865. call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {})
  866. call StopVimInTerminal(buf)
  867. endfunc
  868. func Test_smoothscroll_in_zero_width_window()
  869. set cpo+=n number smoothscroll
  870. set winwidth=99999 winminwidth=0
  871. vsplit
  872. call assert_equal(0, winwidth(winnr('#')))
  873. call win_execute(win_getid(winnr('#')), "norm! \<C-Y>")
  874. only!
  875. set winwidth& winminwidth&
  876. set cpo-=n nonumber nosmoothscroll
  877. endfunc
  878. func Test_smoothscroll_textoff_small_winwidth()
  879. set smoothscroll number
  880. call setline(1, 'llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch')
  881. vsplit
  882. let textoff = getwininfo(win_getid())[0].textoff
  883. execute 'vertical resize' textoff + 1
  884. redraw
  885. call assert_equal(0, winsaveview().skipcol)
  886. execute "normal! 0\<C-E>"
  887. redraw
  888. call assert_equal(1, winsaveview().skipcol)
  889. execute 'vertical resize' textoff - 1
  890. " This caused a signed integer overflow.
  891. redraw
  892. call assert_equal(1, winsaveview().skipcol)
  893. execute 'vertical resize' textoff
  894. " This caused an infinite loop.
  895. redraw
  896. call assert_equal(1, winsaveview().skipcol)
  897. %bw!
  898. set smoothscroll& number&
  899. endfunc
  900. func Test_smoothscroll_page()
  901. call NewWindow(10, 40)
  902. setlocal smoothscroll
  903. call setline(1, 'abcde '->repeat(150))
  904. exe "norm! \<C-F>"
  905. call assert_equal(400, winsaveview().skipcol)
  906. exe "norm! \<C-F>"
  907. call assert_equal(800, winsaveview().skipcol)
  908. exe "norm! \<C-F>"
  909. call assert_equal(880, winsaveview().skipcol)
  910. exe "norm! \<C-B>"
  911. call assert_equal(480, winsaveview().skipcol)
  912. exe "norm! \<C-B>"
  913. call assert_equal(80, winsaveview().skipcol)
  914. exe "norm! \<C-B>"
  915. call assert_equal(0, winsaveview().skipcol)
  916. " Half-page scrolling does not go beyond end of buffer and moves the cursor.
  917. " Even with 'nostartofline', the correct amount of lines is scrolled.
  918. setl nostartofline
  919. exe "norm! 15|\<C-D>"
  920. call assert_equal(200, winsaveview().skipcol)
  921. call assert_equal(215, col('.'))
  922. exe "norm! \<C-D>"
  923. call assert_equal(400, winsaveview().skipcol)
  924. call assert_equal(415, col('.'))
  925. exe "norm! \<C-D>"
  926. call assert_equal(520, winsaveview().skipcol)
  927. call assert_equal(615, col('.'))
  928. exe "norm! \<C-D>"
  929. call assert_equal(520, winsaveview().skipcol)
  930. call assert_equal(815, col('.'))
  931. exe "norm! \<C-D>"
  932. call assert_equal(520, winsaveview().skipcol)
  933. call assert_equal(895, col('.'))
  934. exe "norm! \<C-U>"
  935. call assert_equal(320, winsaveview().skipcol)
  936. call assert_equal(695, col('.'))
  937. exe "norm! \<C-U>"
  938. call assert_equal(120, winsaveview().skipcol)
  939. call assert_equal(495, col('.'))
  940. exe "norm! \<C-U>"
  941. call assert_equal(0, winsaveview().skipcol)
  942. call assert_equal(295, col('.'))
  943. exe "norm! \<C-U>"
  944. call assert_equal(0, winsaveview().skipcol)
  945. call assert_equal(95, col('.'))
  946. exe "norm! \<C-U>"
  947. call assert_equal(0, winsaveview().skipcol)
  948. call assert_equal(15, col('.'))
  949. bwipe!
  950. endfunc
  951. func Test_smoothscroll_next_topline()
  952. call NewWindow(10, 40)
  953. setlocal smoothscroll
  954. call setline(1, ['abcde '->repeat(150)]->repeat(2))
  955. " Scrolling a screenline that causes the cursor to move to the next buffer
  956. " line should not skip part of that line to bring the cursor into view.
  957. exe "norm! 22\<C-E>"
  958. call assert_equal(880, winsaveview().skipcol)
  959. exe "norm! \<C-E>"
  960. redraw
  961. call assert_equal(0, winsaveview().skipcol)
  962. " Also when scrolling back.
  963. exe "norm! G\<C-Y>"
  964. redraw
  965. call assert_equal(880, winsaveview().skipcol)
  966. " Cursor in correct place when not in the first screenline of a buffer line.
  967. exe "norm! gg4gj20\<C-D>\<C-D>"
  968. redraw
  969. call assert_equal(2, line('w0'))
  970. " Cursor does not end up above topline, adjusting topline later.
  971. setlocal nu cpo+=n
  972. exe "norm! G$g013\<C-Y>"
  973. redraw
  974. call assert_equal(2, line('.'))
  975. call assert_equal(0, winsaveview().skipcol)
  976. set cpo-=n
  977. bwipe!
  978. endfunc
  979. func Test_smoothscroll_long_line_zb()
  980. call NewWindow(10, 40)
  981. call setline(1, 'abcde '->repeat(150))
  982. " Also works without 'smoothscroll' when last line of buffer doesn't fit.
  983. " Used to set topline to buffer line count plus one, causing an empty screen.
  984. norm zb
  985. redraw
  986. call assert_equal(1, winsaveview().topline)
  987. " Moving cursor to bottom works on line that doesn't fit with 'smoothscroll'.
  988. " Skipcol was adjusted later for cursor being on not visible part of line.
  989. setlocal smoothscroll
  990. norm zb
  991. redraw
  992. call assert_equal(520, winsaveview().skipcol)
  993. bwipe!
  994. endfunc
  995. func Test_smooth_long_scrolloff()
  996. CheckScreendump
  997. let lines =<< trim END
  998. set smoothscroll scrolloff=3
  999. call setline(1, ['one', 'two long '->repeat(100), 'three', 'four', 'five', 'six'])
  1000. END
  1001. call writefile(lines, 'XSmoothLongScrolloff', 'D')
  1002. let buf = RunVimInTerminal('-u NONE -S XSmoothLongScrolloff', #{rows: 8, cols: 40})
  1003. call term_sendkeys(buf, ":norm j721|\<CR>")
  1004. call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_1', {})
  1005. call term_sendkeys(buf, "gj")
  1006. call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_2', {})
  1007. call term_sendkeys(buf, "gj")
  1008. call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_3', {})
  1009. call term_sendkeys(buf, "gj")
  1010. call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_4', {})
  1011. call term_sendkeys(buf, "gj")
  1012. call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_5', {})
  1013. call term_sendkeys(buf, "gj")
  1014. call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_6', {})
  1015. call term_sendkeys(buf, "gk")
  1016. call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_7', {})
  1017. call StopVimInTerminal(buf)
  1018. endfunc
  1019. " vim: shiftwidth=2 sts=2 expandtab