screenpos_spec.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local clear, eq, api = n.clear, t.eq, n.api
  4. local command, fn = n.command, n.fn
  5. local feed = n.feed
  6. before_each(clear)
  7. describe('screenpos() function', function()
  8. it('works in floating window with border', function()
  9. local opts = {
  10. relative = 'editor',
  11. height = 8,
  12. width = 12,
  13. row = 6,
  14. col = 8,
  15. anchor = 'NW',
  16. style = 'minimal',
  17. border = 'none',
  18. focusable = 1,
  19. }
  20. local float = api.nvim_open_win(api.nvim_create_buf(false, true), false, opts)
  21. command('redraw')
  22. eq({ row = 7, col = 9, endcol = 9, curscol = 9 }, fn.screenpos(float, 1, 1))
  23. -- only left border
  24. opts.border = { '', '', '', '', '', '', '', '|' }
  25. api.nvim_win_set_config(float, opts)
  26. command('redraw')
  27. eq({ row = 7, col = 10, endcol = 10, curscol = 10 }, fn.screenpos(float, 1, 1))
  28. -- only top border
  29. opts.border = { '', '_', '', '', '', '', '', '' }
  30. api.nvim_win_set_config(float, opts)
  31. command('redraw')
  32. eq({ row = 8, col = 9, endcol = 9, curscol = 9 }, fn.screenpos(float, 1, 1))
  33. -- both left and top border
  34. opts.border = 'single'
  35. api.nvim_win_set_config(float, opts)
  36. command('redraw')
  37. eq({ row = 8, col = 10, endcol = 10, curscol = 10 }, fn.screenpos(float, 1, 1))
  38. end)
  39. it('works for folded line with virt_lines attached to line above', function()
  40. api.nvim_buf_set_lines(0, 0, -1, true, { 'aaa', 'bbb', 'ccc', 'ddd' })
  41. local ns = api.nvim_create_namespace('')
  42. api.nvim_buf_set_extmark(
  43. 0,
  44. ns,
  45. 0,
  46. 0,
  47. { virt_lines = { { { 'abb' } }, { { 'acc' } }, { { 'add' } } } }
  48. )
  49. command('2,3fold')
  50. eq({ row = 5, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1))
  51. eq({ row = 5, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1))
  52. eq({ row = 6, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1))
  53. feed('<C-E>')
  54. eq({ row = 4, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1))
  55. eq({ row = 4, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1))
  56. eq({ row = 5, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1))
  57. feed('<C-E>')
  58. eq({ row = 3, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1))
  59. eq({ row = 3, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1))
  60. eq({ row = 4, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1))
  61. feed('<C-E>')
  62. eq({ row = 2, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1))
  63. eq({ row = 2, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1))
  64. eq({ row = 3, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1))
  65. feed('<C-E>')
  66. eq({ row = 1, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 2, 1))
  67. eq({ row = 1, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 3, 1))
  68. eq({ row = 2, col = 1, endcol = 1, curscol = 1 }, fn.screenpos(0, 4, 1))
  69. end)
  70. end)