test_scrollbind.vim 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. " Test for 'scrollbind' causing an unexpected scroll of one of the windows.
  2. func Test_scrollbind()
  3. " We don't want the status line to cause problems:
  4. set laststatus=0
  5. let totalLines = &lines * 20
  6. let middle = totalLines / 2
  7. new | only
  8. for i in range(1, totalLines)
  9. call setline(i, 'LINE ' . i)
  10. endfor
  11. exe string(middle)
  12. normal zt
  13. normal M
  14. aboveleft vert new
  15. for i in range(1, totalLines)
  16. call setline(i, 'line ' . i)
  17. endfor
  18. exe string(middle)
  19. normal zt
  20. normal M
  21. " Execute the following two commands at once to reproduce the problem.
  22. setl scb | wincmd p
  23. setl scb
  24. wincmd w
  25. let topLineLeft = line('w0')
  26. wincmd p
  27. let topLineRight = line('w0')
  28. setl noscrollbind
  29. wincmd p
  30. setl noscrollbind
  31. call assert_equal(0, topLineLeft - topLineRight)
  32. endfunc
  33. " Test for 'scrollbind'
  34. func Test_scrollbind_opt()
  35. new | only
  36. set noscrollbind
  37. set scrollopt=ver,jump scrolloff=2 nowrap noequalalways splitbelow
  38. " Insert the text used for the test
  39. append
  40. start of window 1
  41. . line 01 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 01
  42. . line 02 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02
  43. . line 03 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 03
  44. . line 04 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 04
  45. . line 05 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 05
  46. . line 06 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 06
  47. . line 07 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 07
  48. . line 08 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 08
  49. . line 09 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 09
  50. . line 10 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 10
  51. . line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11
  52. . line 12 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 12
  53. . line 13 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 13
  54. . line 14 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 14
  55. . line 15 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 15
  56. end of window 1
  57. start of window 2
  58. . line 01 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 01
  59. . line 02 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 02
  60. . line 03 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 03
  61. . line 04 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 04
  62. . line 05 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 05
  63. . line 06 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 06
  64. . line 07 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 07
  65. . line 08 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 08
  66. . line 09 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 09
  67. . line 10 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 10
  68. . line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11
  69. . line 12 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 12
  70. . line 13 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 13
  71. . line 14 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 14
  72. . line 15 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 15
  73. . line 16 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 16
  74. end of window 2
  75. .
  76. " Test using two windows open to one buffer, one extra empty window
  77. split
  78. new
  79. wincmd t
  80. resize 8
  81. call search('^start of window 1$')
  82. normal zt
  83. set scrollbind
  84. wincmd j
  85. resize 7
  86. call search('^start of window 2$')
  87. normal zt
  88. set scrollbind
  89. " -- start of tests --
  90. " Test scrolling down
  91. normal L5jHyy
  92. wincmd b | normal pr0
  93. wincmd t | normal Hyy
  94. wincmd b | normal pr1
  95. wincmd t | normal L6jHyy
  96. wincmd b | normal pr2
  97. wincmd k | normal Hyy
  98. wincmd b | normal pr3
  99. " Test scrolling up
  100. wincmd t | normal H4k
  101. wincmd j | normal H
  102. wincmd t | normal Hyy
  103. wincmd b | normal pr4
  104. wincmd k | normal Hyy
  105. wincmd b | normal pr5
  106. wincmd k | normal 3k
  107. wincmd t | normal H
  108. wincmd j | normal Hyy
  109. wincmd b | normal pr6
  110. wincmd t | normal Hyy
  111. wincmd b | normal pr7
  112. " Test horizontal scrolling
  113. set scrollopt+=hor
  114. normal gg"zyyG"zpG
  115. wincmd t | normal 015zly$
  116. wincmd b | normal p"zpG
  117. wincmd k | normal y$
  118. wincmd b | normal p"zpG
  119. wincmd k | normal 10jH7zhg0y$
  120. wincmd b | normal p"zpG
  121. wincmd t | normal Hg0y$
  122. wincmd b | normal p"zpG
  123. set scrollopt-=hor
  124. wincmd b
  125. call assert_equal([
  126. \ '',
  127. \ '0 line 05 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 05',
  128. \ '1 line 05 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 05',
  129. \ '2 line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11',
  130. \ '3 line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11',
  131. \ '4 line 06 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 06',
  132. \ '5 line 06 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 06',
  133. \ '6 line 02 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 02',
  134. \ '7 line 02 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02',
  135. \ '56789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02',
  136. \ 'UTSRQPONMLKJIHGREDCBA9876543210 02',
  137. \ '. line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11',
  138. \ '. line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11',
  139. \ ''], getline(1, '$'))
  140. enew!
  141. " ****** tests using two different buffers *****
  142. wincmd t | wincmd j | close
  143. wincmd t | set noscrollbind
  144. /start of window 2$/,/^end of window 2$/y
  145. new
  146. wincmd t | wincmd j | normal 4"zpGp
  147. wincmd t
  148. call search('^start of window 1$')
  149. normal zt
  150. set scrollbind
  151. wincmd j
  152. call search('^start of window 2$')
  153. normal zt
  154. set scrollbind
  155. " -- start of tests --
  156. " Test scrolling down
  157. normal L5jHyy
  158. wincmd b | normal pr0
  159. wincmd t | normal Hyy
  160. wincmd b | normal pr1
  161. wincmd t | normal L6jHyy
  162. wincmd b | normal pr2
  163. wincmd k | normal Hyy
  164. wincmd b | normal pr3
  165. " Test scrolling up
  166. wincmd t | normal H4k
  167. wincmd j | normal H
  168. wincmd t | normal Hyy
  169. wincmd b | normal pr4
  170. wincmd k | normal Hyy
  171. wincmd b | normal pr5
  172. wincmd k | normal 3k
  173. wincmd t | normal H
  174. wincmd j | normal Hyy
  175. wincmd b | normal pr6
  176. wincmd t | normal Hyy
  177. wincmd b | normal pr7
  178. " Test horizontal scrolling
  179. set scrollopt+=hor
  180. normal gg"zyyG"zpG
  181. wincmd t | normal 015zly$
  182. wincmd b | normal p"zpG
  183. wincmd k | normal y$
  184. wincmd b | normal p"zpG
  185. wincmd k | normal 10jH7zhg0y$
  186. wincmd b | normal p"zpG
  187. wincmd t | normal Hg0y$
  188. wincmd b | normal p"zpG
  189. set scrollopt-=hor
  190. wincmd b
  191. call assert_equal([
  192. \ '',
  193. \ '0 line 05 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 05',
  194. \ '1 line 05 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 05',
  195. \ '2 line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11',
  196. \ '3 line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11',
  197. \ '4 line 06 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 06',
  198. \ '5 line 06 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 06',
  199. \ '6 line 02 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 02',
  200. \ '7 line 02 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02',
  201. \ '56789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02',
  202. \ 'UTSRQPONMLKJIHGREDCBA9876543210 02',
  203. \ '. line 10 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 10',
  204. \ '. line 10 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 10',
  205. \ ''], getline(1, '$'))
  206. enew!
  207. " Test 'syncbind'
  208. wincmd t | set noscrollbind | normal ggL
  209. wincmd j | set noscrollbind | normal ggL
  210. set scrollbind
  211. wincmd t | set scrollbind | normal G
  212. wincmd j | normal G
  213. syncbind
  214. normal Hk
  215. wincmd t | normal H
  216. wincmd j | normal Hyy
  217. wincmd b | normal p
  218. wincmd t | normal yy
  219. wincmd b | normal p
  220. wincmd t | set noscrollbind | normal ggL
  221. wincmd j | set noscrollbind
  222. normal ggL
  223. set scrollbind
  224. wincmd t | set scrollbind
  225. wincmd t | normal G
  226. wincmd j | normal G
  227. wincmd t | syncbind | normal Hk
  228. wincmd j | normal H
  229. wincmd t | normal Hyy
  230. wincmd b | normal p
  231. wincmd t | wincmd j | normal yy
  232. wincmd b | normal p
  233. wincmd t | normal H3k
  234. wincmd j | normal H
  235. wincmd t | normal Hyy
  236. wincmd b | normal p
  237. wincmd t | wincmd j | normal yy
  238. wincmd b | normal p
  239. wincmd b
  240. call assert_equal([
  241. \ '',
  242. \ '. line 16 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 16',
  243. \ 'start of window 2',
  244. \ 'start of window 2',
  245. \ '. line 16 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 16',
  246. \ '. line 15 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 15',
  247. \ '. line 12 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 12',
  248. \ ], getline(1, '$'))
  249. enew!
  250. new | only!
  251. set scrollbind& scrollopt& scrolloff& wrap& equalalways& splitbelow&
  252. endfunc