2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2015-03-25 05:14:47 -07:00
|
|
|
local thelpers = require('test.functional.terminal.helpers')
|
2017-02-26 19:10:55 -07:00
|
|
|
local clear, eq, eval = helpers.clear, helpers.eq, helpers.eval
|
2022-01-22 14:58:32 -07:00
|
|
|
local feed, nvim, command = helpers.feed, helpers.nvim, helpers.command
|
2015-03-25 05:14:47 -07:00
|
|
|
local feed_data = thelpers.feed_data
|
2022-11-21 17:13:30 -07:00
|
|
|
local is_os = helpers.is_os
|
2022-11-13 06:52:19 -07:00
|
|
|
local skip = helpers.skip
|
2015-03-25 05:14:47 -07:00
|
|
|
|
2018-04-28 16:39:21 -07:00
|
|
|
describe(':terminal mouse', function()
|
2015-03-25 05:14:47 -07:00
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
nvim('set_option', 'statusline', '==========')
|
2022-01-22 14:58:32 -07:00
|
|
|
command('highlight StatusLine cterm=NONE')
|
|
|
|
command('highlight StatusLineNC cterm=NONE')
|
|
|
|
command('highlight VertSplit cterm=NONE')
|
2015-03-25 05:14:47 -07:00
|
|
|
screen = thelpers.screen_setup()
|
|
|
|
local lines = {}
|
|
|
|
for i = 1, 30 do
|
|
|
|
table.insert(lines, 'line'..tostring(i))
|
|
|
|
end
|
|
|
|
table.insert(lines, '')
|
|
|
|
feed_data(lines)
|
|
|
|
screen:expect([[
|
|
|
|
line26 |
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
{1: } |
|
2016-08-09 08:01:56 -07:00
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('when the terminal has focus', function()
|
2017-02-26 19:10:55 -07:00
|
|
|
it('will exit focus on mouse-scroll', function()
|
2021-10-09 18:15:46 -07:00
|
|
|
eq('t', eval('mode(1)'))
|
2017-02-26 19:10:55 -07:00
|
|
|
feed('<ScrollWheelUp><0,0>')
|
2021-10-09 18:15:46 -07:00
|
|
|
eq('nt', eval('mode(1)'))
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
|
2022-01-22 14:58:32 -07:00
|
|
|
it('will exit focus and trigger Normal mode mapping on mouse click', function()
|
|
|
|
command('let g:got_leftmouse = 0')
|
|
|
|
command('nnoremap <LeftMouse> <Cmd>let g:got_leftmouse = 1<CR>')
|
|
|
|
eq('t', eval('mode(1)'))
|
|
|
|
eq(0, eval('g:got_leftmouse'))
|
|
|
|
feed('<LeftMouse>')
|
|
|
|
eq('nt', eval('mode(1)'))
|
|
|
|
eq(1, eval('g:got_leftmouse'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('will exit focus and trigger Normal mode mapping on mouse click with modifier', function()
|
|
|
|
command('let g:got_ctrl_leftmouse = 0')
|
|
|
|
command('nnoremap <C-LeftMouse> <Cmd>let g:got_ctrl_leftmouse = 1<CR>')
|
|
|
|
eq('t', eval('mode(1)'))
|
|
|
|
eq(0, eval('g:got_ctrl_leftmouse'))
|
|
|
|
feed('<C-LeftMouse>')
|
|
|
|
eq('nt', eval('mode(1)'))
|
|
|
|
eq(1, eval('g:got_ctrl_leftmouse'))
|
|
|
|
end)
|
|
|
|
|
2017-02-26 19:10:55 -07:00
|
|
|
it('will exit focus on <C-\\> + mouse-scroll', function()
|
2021-10-09 18:15:46 -07:00
|
|
|
eq('t', eval('mode(1)'))
|
2015-04-05 10:20:08 -07:00
|
|
|
feed('<C-\\>')
|
2017-02-26 19:10:55 -07:00
|
|
|
feed('<ScrollWheelUp><0,0>')
|
2021-10-09 18:15:46 -07:00
|
|
|
eq('nt', eval('mode(1)'))
|
2015-04-05 10:20:08 -07:00
|
|
|
end)
|
|
|
|
|
2021-12-09 09:44:09 -07:00
|
|
|
it('does not leave terminal mode on left-release', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
skip(is_os('win'))
|
2021-12-09 09:44:09 -07:00
|
|
|
feed('<LeftRelease>')
|
|
|
|
eq('t', eval('mode(1)'))
|
|
|
|
end)
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
describe('with mouse events enabled by the program', function()
|
|
|
|
before_each(function()
|
|
|
|
thelpers.enable_mouse()
|
|
|
|
thelpers.feed_data('mouse enabled\n')
|
|
|
|
screen:expect([[
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
mouse enabled |
|
|
|
|
{1: } |
|
2016-08-09 08:01:56 -07:00
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2021-12-26 15:08:16 -07:00
|
|
|
it('will forward mouse press, drag and release to the program', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
skip(is_os('win'))
|
2015-03-25 05:14:47 -07:00
|
|
|
feed('<LeftMouse><1,2>')
|
|
|
|
screen:expect([[
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
mouse enabled |
|
|
|
|
"#{1: } |
|
2016-08-09 08:01:56 -07:00
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
2021-12-26 15:08:16 -07:00
|
|
|
feed('<LeftDrag><2,2>')
|
|
|
|
screen:expect([[
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
mouse enabled |
|
|
|
|
@##{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
|
|
|
feed('<LeftDrag><3,2>')
|
|
|
|
screen:expect([[
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
mouse enabled |
|
|
|
|
@$#{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
|
|
|
feed('<LeftRelease><3,2>')
|
|
|
|
screen:expect([[
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
mouse enabled |
|
|
|
|
#$#{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('will forward mouse scroll to the program', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
skip(is_os('win'))
|
2017-02-26 19:10:55 -07:00
|
|
|
feed('<ScrollWheelUp><0,0>')
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
mouse enabled |
|
|
|
|
`!!{1: } |
|
2021-12-26 15:08:16 -07:00
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('dragging and scrolling do not interfere with each other', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
skip(is_os('win'))
|
2021-12-26 15:08:16 -07:00
|
|
|
feed('<LeftMouse><1,2>')
|
|
|
|
screen:expect([[
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
mouse enabled |
|
|
|
|
"#{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
|
|
|
feed('<ScrollWheelUp><1,2>')
|
|
|
|
screen:expect([[
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
mouse enabled |
|
|
|
|
`"#{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
|
|
|
feed('<LeftDrag><2,2>')
|
|
|
|
screen:expect([[
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
mouse enabled |
|
|
|
|
@##{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
|
|
|
feed('<ScrollWheelUp><2,2>')
|
|
|
|
screen:expect([[
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
mouse enabled |
|
|
|
|
`##{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
|
|
|
feed('<LeftRelease><2,2>')
|
|
|
|
screen:expect([[
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
mouse enabled |
|
|
|
|
###{1: } |
|
2016-08-09 08:01:56 -07:00
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
2020-04-21 06:44:39 -07:00
|
|
|
|
|
|
|
it('will forward mouse clicks to the program with the correct even if set nu', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
skip(is_os('win'))
|
2022-01-22 14:58:32 -07:00
|
|
|
command('set number')
|
2020-04-21 06:44:39 -07:00
|
|
|
-- When the display area such as a number is clicked, it returns to the
|
|
|
|
-- normal mode.
|
|
|
|
feed('<LeftMouse><3,0>')
|
2021-10-09 18:15:46 -07:00
|
|
|
eq('nt', eval('mode(1)'))
|
2020-04-21 06:44:39 -07:00
|
|
|
screen:expect([[
|
|
|
|
{7: 11 }^line28 |
|
|
|
|
{7: 12 }line29 |
|
|
|
|
{7: 13 }line30 |
|
|
|
|
{7: 14 }mouse enabled |
|
|
|
|
{7: 15 }rows: 6, cols: 46 |
|
|
|
|
{7: 16 }{2: } |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
-- If click on the coordinate (0,1) of the region of the terminal
|
|
|
|
-- (i.e. the coordinate (4,1) of vim), 'CSI !"' is sent to the terminal.
|
|
|
|
feed('i<LeftMouse><4,1>')
|
|
|
|
screen:expect([[
|
|
|
|
{7: 11 }line28 |
|
|
|
|
{7: 12 }line29 |
|
|
|
|
{7: 13 }line30 |
|
|
|
|
{7: 14 }mouse enabled |
|
|
|
|
{7: 15 }rows: 6, cols: 46 |
|
|
|
|
{7: 16 } !"{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
|
|
|
end)
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('with a split window and other buffer', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
skip(is_os('win'))
|
2015-03-25 05:14:47 -07:00
|
|
|
before_each(function()
|
|
|
|
feed('<c-\\><c-n>:vsp<cr>')
|
|
|
|
screen:expect([[
|
2018-02-08 16:44:24 -07:00
|
|
|
line28 │line28 |
|
|
|
|
line29 │line29 |
|
|
|
|
line30 │line30 |
|
2018-04-16 13:25:23 -07:00
|
|
|
rows: 5, cols: 25 │rows: 5, cols: 25 |
|
2018-02-08 16:44:24 -07:00
|
|
|
{2:^ } │{2: } |
|
2015-03-25 05:14:47 -07:00
|
|
|
========== ========== |
|
2017-02-26 02:21:44 -07:00
|
|
|
:vsp |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
feed(':enew | set number<cr>')
|
|
|
|
screen:expect([[
|
2019-01-26 04:37:38 -07:00
|
|
|
{7: 1 }^ │line29 |
|
2018-02-08 16:44:24 -07:00
|
|
|
{4:~ }│line30 |
|
2018-04-16 13:25:23 -07:00
|
|
|
{4:~ }│rows: 5, cols: 25 |
|
2019-01-26 04:37:38 -07:00
|
|
|
{4:~ }│rows: 5, cols: 24 |
|
2018-02-08 16:44:24 -07:00
|
|
|
{4:~ }│{2: } |
|
2015-03-25 05:14:47 -07:00
|
|
|
========== ========== |
|
|
|
|
:enew | set number |
|
|
|
|
]])
|
|
|
|
feed('30iline\n<esc>')
|
|
|
|
screen:expect([[
|
2019-01-26 04:37:38 -07:00
|
|
|
{7: 27 }line │line29 |
|
|
|
|
{7: 28 }line │line30 |
|
|
|
|
{7: 29 }line │rows: 5, cols: 25 |
|
|
|
|
{7: 30 }line │rows: 5, cols: 24 |
|
2018-02-08 16:44:24 -07:00
|
|
|
{7: 31 }^ │{2: } |
|
2015-03-25 05:14:47 -07:00
|
|
|
========== ========== |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
feed('<c-w>li')
|
|
|
|
screen:expect([[
|
2019-01-26 04:37:38 -07:00
|
|
|
{7: 27 }line │line29 |
|
|
|
|
{7: 28 }line │line30 |
|
|
|
|
{7: 29 }line │rows: 5, cols: 25 |
|
|
|
|
{7: 30 }line │rows: 5, cols: 24 |
|
2018-02-08 16:44:24 -07:00
|
|
|
{7: 31 } │{1: } |
|
2015-03-25 05:14:47 -07:00
|
|
|
========== ========== |
|
2016-08-09 08:01:56 -07:00
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
2019-01-26 04:37:38 -07:00
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
-- enabling mouse won't affect interaction with other windows
|
|
|
|
thelpers.enable_mouse()
|
|
|
|
thelpers.feed_data('mouse enabled\n')
|
|
|
|
screen:expect([[
|
2019-01-26 04:37:38 -07:00
|
|
|
{7: 27 }line │line30 |
|
|
|
|
{7: 28 }line │rows: 5, cols: 25 |
|
|
|
|
{7: 29 }line │rows: 5, cols: 24 |
|
2018-02-08 16:44:24 -07:00
|
|
|
{7: 30 }line │mouse enabled |
|
|
|
|
{7: 31 } │{1: } |
|
2015-03-25 05:14:47 -07:00
|
|
|
========== ========== |
|
2016-08-09 08:01:56 -07:00
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('wont lose focus if another window is scrolled', function()
|
2020-04-21 06:44:39 -07:00
|
|
|
feed('<ScrollWheelUp><4,0><ScrollWheelUp><4,0>')
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
2019-01-26 04:37:38 -07:00
|
|
|
{7: 21 }line │line30 |
|
|
|
|
{7: 22 }line │rows: 5, cols: 25 |
|
|
|
|
{7: 23 }line │rows: 5, cols: 24 |
|
2018-02-08 16:44:24 -07:00
|
|
|
{7: 24 }line │mouse enabled |
|
|
|
|
{7: 25 }line │{1: } |
|
2015-03-25 05:14:47 -07:00
|
|
|
========== ========== |
|
2016-08-09 08:01:56 -07:00
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
2020-04-21 06:44:39 -07:00
|
|
|
feed('<S-ScrollWheelDown><4,0>')
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
2019-01-26 04:37:38 -07:00
|
|
|
{7: 26 }line │line30 |
|
|
|
|
{7: 27 }line │rows: 5, cols: 25 |
|
|
|
|
{7: 28 }line │rows: 5, cols: 24 |
|
2018-02-08 16:44:24 -07:00
|
|
|
{7: 29 }line │mouse enabled |
|
|
|
|
{7: 30 }line │{1: } |
|
2015-03-25 05:14:47 -07:00
|
|
|
========== ========== |
|
2016-08-09 08:01:56 -07:00
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('will lose focus if another window is clicked', function()
|
|
|
|
feed('<LeftMouse><5,1>')
|
|
|
|
screen:expect([[
|
2019-01-26 04:37:38 -07:00
|
|
|
{7: 27 }line │line30 |
|
|
|
|
{7: 28 }l^ine │rows: 5, cols: 25 |
|
|
|
|
{7: 29 }line │rows: 5, cols: 24 |
|
2018-02-08 16:44:24 -07:00
|
|
|
{7: 30 }line │mouse enabled |
|
|
|
|
{7: 31 } │{2: } |
|
2015-03-25 05:14:47 -07:00
|
|
|
========== ========== |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
2019-01-26 04:37:38 -07:00
|
|
|
|
|
|
|
it('handles terminal size when switching buffers', function()
|
|
|
|
nvim('set_option', 'hidden', true)
|
|
|
|
feed('<c-\\><c-n><c-w><c-w>')
|
|
|
|
screen:expect([[
|
|
|
|
{7: 27 }line │line30 |
|
|
|
|
{7: 28 }line │rows: 5, cols: 25 |
|
|
|
|
{7: 29 }line │rows: 5, cols: 24 |
|
|
|
|
{7: 30 }line │mouse enabled |
|
|
|
|
{7: 31 }^ │{2: } |
|
|
|
|
========== ========== |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
feed(':bn<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
rows: 5, cols: 25 │rows: 5, cols: 25 |
|
|
|
|
rows: 5, cols: 24 │rows: 5, cols: 24 |
|
|
|
|
mouse enabled │mouse enabled |
|
|
|
|
rows: 5, cols: 25 │rows: 5, cols: 25 |
|
|
|
|
{2:^ } │{2: } |
|
|
|
|
========== ========== |
|
|
|
|
:bn |
|
|
|
|
]])
|
|
|
|
feed(':bn<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
{7: 27 }line │rows: 5, cols: 24 |
|
|
|
|
{7: 28 }line │mouse enabled |
|
|
|
|
{7: 29 }line │rows: 5, cols: 25 |
|
|
|
|
{7: 30 }line │rows: 5, cols: 24 |
|
|
|
|
{7: 31 }^ │{2: } |
|
|
|
|
========== ========== |
|
|
|
|
:bn |
|
|
|
|
]])
|
|
|
|
end)
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|