tabline_spec.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local clear, command, eq = n.clear, n.command, t.eq
  5. local insert = n.insert
  6. local api = n.api
  7. local assert_alive = n.assert_alive
  8. describe('ui/ext_tabline', function()
  9. local screen
  10. local event_tabs, event_curtab, event_curbuf, event_buffers
  11. before_each(function()
  12. clear()
  13. screen = Screen.new(25, 5, { rgb = true, ext_tabline = true })
  14. function screen:_handle_tabline_update(curtab, tabs, curbuf, buffers)
  15. event_curtab = curtab
  16. event_tabs = tabs
  17. event_curbuf = curbuf
  18. event_buffers = buffers
  19. end
  20. end)
  21. it('publishes UI events', function()
  22. command('tabedit another-tab')
  23. local expected_tabs = {
  24. { tab = 1, name = '[No Name]' },
  25. { tab = 2, name = 'another-tab' },
  26. }
  27. screen:expect {
  28. grid = [[
  29. ^ |
  30. {1:~ }|*3
  31. |
  32. ]],
  33. condition = function()
  34. eq(2, event_curtab)
  35. eq(expected_tabs, event_tabs)
  36. end,
  37. }
  38. command('tabNext')
  39. screen:expect {
  40. grid = [[
  41. ^ |
  42. {1:~ }|*3
  43. |
  44. ]],
  45. condition = function()
  46. eq(1, event_curtab)
  47. eq(expected_tabs, event_tabs)
  48. end,
  49. }
  50. end)
  51. it('buffer UI events', function()
  52. local expected_buffers_initial = {
  53. { buffer = 1, name = '[No Name]' },
  54. }
  55. screen:expect {
  56. grid = [[
  57. ^ |
  58. {1:~ }|*3
  59. |
  60. ]],
  61. condition = function()
  62. eq(1, event_curbuf)
  63. eq(expected_buffers_initial, event_buffers)
  64. end,
  65. }
  66. command('badd another-buffer')
  67. command('bnext')
  68. local expected_buffers = {
  69. { buffer = 1, name = '[No Name]' },
  70. { buffer = 2, name = 'another-buffer' },
  71. }
  72. screen:expect {
  73. grid = [[
  74. ^ |
  75. {1:~ }|*3
  76. |
  77. ]],
  78. condition = function()
  79. eq(2, event_curbuf)
  80. eq(expected_buffers, event_buffers)
  81. end,
  82. }
  83. end)
  84. end)
  85. describe('tabline', function()
  86. local screen
  87. before_each(function()
  88. clear()
  89. screen = Screen.new(42, 5)
  90. end)
  91. it('redraws when tabline option is set', function()
  92. command('set tabline=asdf')
  93. command('set showtabline=2')
  94. screen:expect {
  95. grid = [[
  96. {2:asdf }|
  97. ^ |
  98. {1:~ }|*2
  99. |
  100. ]],
  101. }
  102. command('set tabline=jkl')
  103. screen:expect {
  104. grid = [[
  105. {2:jkl }|
  106. ^ |
  107. {1:~ }|*2
  108. |
  109. ]],
  110. }
  111. end)
  112. it('combines highlight attributes', function()
  113. screen:set_default_attr_ids({
  114. [1] = { foreground = Screen.colors.Blue1, bold = true }, -- StatusLine
  115. [2] = { bold = true, italic = true }, -- StatusLine
  116. [3] = { bold = true, italic = true, foreground = Screen.colors.Red }, -- NonText combined with StatusLine
  117. })
  118. command('hi TabLineFill gui=bold,italic')
  119. command('hi Identifier guifg=red')
  120. command('set tabline=Test%#Identifier#here')
  121. command('set showtabline=2')
  122. screen:expect {
  123. grid = [[
  124. {2:Test}{3:here }|
  125. ^ |
  126. {1:~ }|*2
  127. |
  128. ]],
  129. }
  130. end)
  131. it('click definitions do not leak memory #21765', function()
  132. command('set tabline=%@MyClickFunc@MyClickText%T')
  133. command('set showtabline=2')
  134. command('redrawtabline')
  135. end)
  136. it('clicks work with truncated double-width label #24187', function()
  137. insert('tab1')
  138. command('tabnew')
  139. insert('tab2')
  140. command('tabprev')
  141. api.nvim_set_option_value('tabline', '%1T口口%2Ta' .. ('b'):rep(38) .. '%999Xc', {})
  142. screen:expect {
  143. grid = [[
  144. {2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
  145. tab^1 |
  146. {1:~ }|*2
  147. |
  148. ]],
  149. }
  150. assert_alive()
  151. api.nvim_input_mouse('left', 'press', '', 0, 0, 1)
  152. screen:expect {
  153. grid = [[
  154. {2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
  155. tab^2 |
  156. {1:~ }|*2
  157. |
  158. ]],
  159. }
  160. api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
  161. screen:expect {
  162. grid = [[
  163. {2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
  164. tab^1 |
  165. {1:~ }|*2
  166. |
  167. ]],
  168. }
  169. api.nvim_input_mouse('left', 'press', '', 0, 0, 39)
  170. screen:expect {
  171. grid = [[
  172. {2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
  173. tab^2 |
  174. {1:~ }|*2
  175. |
  176. ]],
  177. }
  178. api.nvim_input_mouse('left', 'press', '', 0, 0, 40)
  179. screen:expect {
  180. grid = [[
  181. tab^1 |
  182. {1:~ }|*3
  183. |
  184. ]],
  185. }
  186. end)
  187. it('middle-click closes tab', function()
  188. command('tabnew')
  189. command('tabnew')
  190. command('tabnew')
  191. command('tabprev')
  192. eq({ 3, 4 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
  193. api.nvim_input_mouse('middle', 'press', '', 0, 0, 1)
  194. eq({ 2, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
  195. api.nvim_input_mouse('middle', 'press', '', 0, 0, 20)
  196. eq({ 2, 2 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
  197. api.nvim_input_mouse('middle', 'press', '', 0, 0, 1)
  198. eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
  199. end)
  200. it('does not show floats with focusable=false', function()
  201. screen:set_default_attr_ids({
  202. [1] = { background = Screen.colors.Plum1 },
  203. [2] = { underline = true, background = Screen.colors.LightGrey },
  204. [3] = { bold = true },
  205. [4] = { reverse = true },
  206. [5] = { bold = true, foreground = Screen.colors.Blue1 },
  207. [6] = { foreground = Screen.colors.Fuchsia, bold = true },
  208. [7] = { foreground = Screen.colors.SeaGreen, bold = true },
  209. })
  210. command('tabnew')
  211. api.nvim_open_win(0, false, {
  212. focusable = false,
  213. relative = 'editor',
  214. height = 1,
  215. width = 1,
  216. row = 0,
  217. col = 0,
  218. })
  219. screen:expect {
  220. grid = [[
  221. {1: }{2:[No Name] }{3: [No Name] }{4: }{2:X}|
  222. ^ |
  223. {5:~ }|*2
  224. |
  225. ]],
  226. }
  227. command('tabs')
  228. screen:expect {
  229. grid = [[
  230. {6:Tab page 1} |
  231. # [No Name] |
  232. {6:Tab page 2} |
  233. > [No Name] |
  234. {7:Press ENTER or type command to continue}^ |
  235. ]],
  236. }
  237. end)
  238. end)