window_cmd_spec.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. local n = require('test.functional.testnvim')()
  2. local Screen = require('test.functional.ui.screen')
  3. local clear = n.clear
  4. local exec = n.exec
  5. local exec_lua = n.exec_lua
  6. local command = n.command
  7. local feed = n.feed
  8. -- oldtest: Test_window_cmd_ls0_split_scrolling()
  9. it('scrolling with laststatus=0 and :botright split', function()
  10. clear('--cmd', 'set ruler')
  11. local screen = Screen.new(40, 10)
  12. exec([[
  13. set laststatus=0
  14. call setline(1, range(1, 100))
  15. normal! G
  16. ]])
  17. command('botright split')
  18. screen:expect([[
  19. 97 |
  20. 98 |
  21. 99 |
  22. 100 |
  23. {2:[No Name] [+] 100,1 Bot}|
  24. 97 |
  25. 98 |
  26. 99 |
  27. ^100 |
  28. 100,1 Bot |
  29. ]])
  30. end)
  31. describe('splitkeep', function()
  32. local screen
  33. before_each(function()
  34. clear('--cmd', 'set splitkeep=screen')
  35. screen = Screen.new()
  36. end)
  37. -- oldtest: Test_splitkeep_cursor()
  38. it('does not adjust cursor in window that did not change size', function()
  39. screen:try_resize(75, 8)
  40. -- FIXME: bottom window is different without the "vsplit | close"
  41. exec([[
  42. vsplit | close
  43. set scrolloff=5
  44. set splitkeep=screen
  45. autocmd CursorMoved * wincmd p | wincmd p
  46. call setline(1, range(1, 200))
  47. func CursorEqualize()
  48. call cursor(100, 1)
  49. wincmd =
  50. endfunc
  51. wincmd s
  52. call CursorEqualize()
  53. ]])
  54. screen:expect([[
  55. 99 |
  56. ^100 |
  57. 101 |
  58. {3:[No Name] [+] }|
  59. 5 |
  60. 6 |
  61. {2:[No Name] [+] }|
  62. |
  63. ]])
  64. feed('j')
  65. screen:expect([[
  66. 100 |
  67. ^101 |
  68. 102 |
  69. {3:[No Name] [+] }|
  70. 5 |
  71. 6 |
  72. {2:[No Name] [+] }|
  73. |
  74. ]])
  75. command('set scrolloff=0')
  76. feed('G')
  77. screen:expect([[
  78. 198 |
  79. 199 |
  80. ^200 |
  81. {3:[No Name] [+] }|
  82. 5 |
  83. 6 |
  84. {2:[No Name] [+] }|
  85. |
  86. ]])
  87. end)
  88. -- oldtest: Test_splitkeep_callback()
  89. it('does not scroll when split in callback', function()
  90. exec([[
  91. call setline(1, range(&lines))
  92. function C1(a, b, c)
  93. split | wincmd p
  94. endfunction
  95. function C2(a, b, c)
  96. close | split
  97. endfunction
  98. ]])
  99. exec_lua([[
  100. vim.api.nvim_set_keymap("n", "j", "", { callback = function()
  101. vim.cmd("call jobstart([&sh, &shcf, 'true'], { 'on_exit': 'C1' })")
  102. end
  103. })]])
  104. exec_lua([[
  105. vim.api.nvim_set_keymap("n", "t", "", { callback = function()
  106. vim.api.nvim_set_current_win(
  107. vim.api.nvim_open_win(vim.api.nvim_create_buf(false, {}), false, {
  108. width = 10,
  109. relative = "cursor",
  110. height = 4,
  111. row = 0,
  112. col = 0,
  113. }))
  114. vim.cmd("call termopen([&sh, &shcf, 'true'], { 'on_exit': 'C2' })")
  115. end
  116. })]])
  117. feed('j')
  118. screen:expect([[
  119. 0 |
  120. 1 |
  121. 2 |
  122. 3 |
  123. 4 |
  124. 5 |
  125. {2:[No Name] [+] }|
  126. ^7 |
  127. 8 |
  128. 9 |
  129. 10 |
  130. 11 |
  131. {3:[No Name] [+] }|
  132. |
  133. ]])
  134. feed(':quit<CR>Ht')
  135. screen:expect([[
  136. ^0 |
  137. 1 |
  138. 2 |
  139. 3 |
  140. 4 |
  141. 5 |
  142. {3:[No Name] [+] }|
  143. 7 |
  144. 8 |
  145. 9 |
  146. 10 |
  147. 11 |
  148. {2:[No Name] [+] }|
  149. :quit |
  150. ]])
  151. feed(':set sb<CR>:quit<CR>Gj')
  152. screen:expect([[
  153. 1 |
  154. 2 |
  155. 3 |
  156. 4 |
  157. ^5 |
  158. {3:[No Name] [+] }|
  159. 7 |
  160. 8 |
  161. 9 |
  162. 10 |
  163. 11 |
  164. 12 |
  165. {2:[No Name] [+] }|
  166. :quit |
  167. ]])
  168. feed(':quit<CR>Gt')
  169. screen:expect([[
  170. 1 |
  171. 2 |
  172. 3 |
  173. 4 |
  174. 5 |
  175. {2:[No Name] [+] }|
  176. 7 |
  177. 8 |
  178. 9 |
  179. 10 |
  180. 11 |
  181. ^12 |
  182. {3:[No Name] [+] }|
  183. :quit |
  184. ]])
  185. end)
  186. -- oldtest: Test_splitkeep_fold()
  187. it('does not scroll when window has closed folds', function()
  188. exec([[
  189. set commentstring=/*%s*/
  190. set splitkeep=screen
  191. set foldmethod=marker
  192. set number
  193. let line = 1
  194. for n in range(1, &lines)
  195. call setline(line, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
  196. \ 'after fold'])
  197. let line += 8
  198. endfor
  199. ]])
  200. feed('L:wincmd s<CR>')
  201. screen:expect([[
  202. {8: 1 }{13:+-- 7 lines: int FuncName() {···················}|
  203. {8: 8 }after fold |
  204. {8: 9 }{13:+-- 7 lines: int FuncName() {···················}|
  205. {8: 16 }after fold |
  206. {8: 17 }{13:+-- 7 lines: int FuncName() {···················}|
  207. {8: 24 }^after fold |
  208. {3:[No Name] [+] }|
  209. {8: 32 }after fold |
  210. {8: 33 }{13:+-- 7 lines: int FuncName() {···················}|
  211. {8: 40 }after fold |
  212. {8: 41 }{13:+-- 7 lines: int FuncName() {···················}|
  213. {8: 48 }after fold |
  214. {2:[No Name] [+] }|
  215. :wincmd s |
  216. ]])
  217. feed(':quit<CR>')
  218. screen:expect([[
  219. {8: 1 }{13:+-- 7 lines: int FuncName() {···················}|
  220. {8: 8 }after fold |
  221. {8: 9 }{13:+-- 7 lines: int FuncName() {···················}|
  222. {8: 16 }after fold |
  223. {8: 17 }{13:+-- 7 lines: int FuncName() {···················}|
  224. {8: 24 }after fold |
  225. {8: 25 }{13:+-- 7 lines: int FuncName() {···················}|
  226. {8: 32 }after fold |
  227. {8: 33 }{13:+-- 7 lines: int FuncName() {···················}|
  228. {8: 40 }after fold |
  229. {8: 41 }{13:+-- 7 lines: int FuncName() {···················}|
  230. {8: 48 }after fold |
  231. {8: 49 }{13:^+-- 7 lines: int FuncName() {···················}|
  232. :quit |
  233. ]])
  234. feed('H:below split<CR>')
  235. screen:expect([[
  236. {8: 1 }{13:+-- 7 lines: int FuncName() {···················}|
  237. {8: 8 }after fold |
  238. {8: 9 }{13:+-- 7 lines: int FuncName() {···················}|
  239. {8: 16 }after fold |
  240. {8: 17 }{13:+-- 7 lines: int FuncName() {···················}|
  241. {2:[No Name] [+] }|
  242. {8: 25 }{13:^+-- 7 lines: int FuncName() {···················}|
  243. {8: 32 }after fold |
  244. {8: 33 }{13:+-- 7 lines: int FuncName() {···················}|
  245. {8: 40 }after fold |
  246. {8: 41 }{13:+-- 7 lines: int FuncName() {···················}|
  247. {8: 48 }after fold |
  248. {3:[No Name] [+] }|
  249. :below split |
  250. ]])
  251. feed(':wincmd k<CR>:quit<CR>')
  252. screen:expect([[
  253. {8: 1 }{13:+-- 7 lines: int FuncName() {···················}|
  254. {8: 8 }after fold |
  255. {8: 9 }{13:+-- 7 lines: int FuncName() {···················}|
  256. {8: 16 }after fold |
  257. {8: 17 }{13:+-- 7 lines: int FuncName() {···················}|
  258. {8: 24 }after fold |
  259. {8: 25 }{13:^+-- 7 lines: int FuncName() {···················}|
  260. {8: 32 }after fold |
  261. {8: 33 }{13:+-- 7 lines: int FuncName() {···················}|
  262. {8: 40 }after fold |
  263. {8: 41 }{13:+-- 7 lines: int FuncName() {···················}|
  264. {8: 48 }after fold |
  265. {8: 49 }{13:+-- 7 lines: int FuncName() {···················}|
  266. :quit |
  267. ]])
  268. end)
  269. -- oldtest: Test_splitkeep_status()
  270. it('does not scroll when split in callback', function()
  271. exec([[
  272. call setline(1, ['a', 'b', 'c'])
  273. set nomodified
  274. set splitkeep=screen
  275. let win = winnr()
  276. wincmd s
  277. wincmd j
  278. ]])
  279. feed(':call win_move_statusline(win, 1)<CR>')
  280. screen:expect([[
  281. a |
  282. b |
  283. c |
  284. {1:~ }|*4
  285. {2:[No Name] }|
  286. ^a |
  287. b |
  288. c |
  289. {1:~ }|
  290. {3:[No Name] }|
  291. |
  292. ]])
  293. end)
  294. -- oldtest: Test_splitkeep_skipcol()
  295. it('skipcol is not reset unnecessarily and is copied to new window', function()
  296. screen:try_resize(40, 12)
  297. exec([[
  298. set splitkeep=topline smoothscroll splitbelow scrolloff=0
  299. call setline(1, 'with lots of text in one line '->repeat(6))
  300. norm 2
  301. wincmd s
  302. ]])
  303. screen:expect([[
  304. {1:<<<}e line with lots of text in one line |
  305. with lots of text in one line with lots |
  306. of text in one line |
  307. {1:~ }|
  308. {2:[No Name] [+] }|
  309. {1:<<<}e line with lots of text in one line |
  310. ^with lots of text in one line with lots |
  311. of text in one line |
  312. {1:~ }|*2
  313. {3:[No Name] [+] }|
  314. |
  315. ]])
  316. end)
  317. end)