mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
e61228a214
Before calling "attach" a screen object is just a dummy container for (row, col) values whose purpose is to be sent as part of the "attach" function call anyway. Just create the screen in an attached state directly. Keep the complete (row, col, options) config together. It is still completely valid to later detach and re-attach as needed, including to another session.
277 lines
6.0 KiB
Lua
277 lines
6.0 KiB
Lua
local t = require('test.testutil')
|
|
local n = require('test.functional.testnvim')()
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
local clear, feed, insert = n.clear, n.feed, n.insert
|
|
local command = n.command
|
|
local retry = t.retry
|
|
|
|
describe('ui mode_change event', function()
|
|
local screen
|
|
|
|
before_each(function()
|
|
clear()
|
|
screen = Screen.new(25, 4, { rgb = true })
|
|
end)
|
|
|
|
it('works in normal mode', function()
|
|
screen:expect {
|
|
grid = [[
|
|
^ |
|
|
{1:~ }|*2
|
|
|
|
|
]],
|
|
mode = 'normal',
|
|
}
|
|
|
|
feed('d')
|
|
screen:expect {
|
|
grid = [[
|
|
^ |
|
|
{1:~ }|*2
|
|
|
|
|
]],
|
|
mode = 'operator',
|
|
}
|
|
|
|
feed('<esc>')
|
|
screen:expect {
|
|
grid = [[
|
|
^ |
|
|
{1:~ }|*2
|
|
|
|
|
]],
|
|
mode = 'normal',
|
|
}
|
|
end)
|
|
|
|
-- oldtest: Test_mouse_shape_after_failed_change()
|
|
it('is restored to Normal mode after failed "c"', function()
|
|
screen:try_resize(50, 4)
|
|
command('set nomodifiable')
|
|
|
|
feed('c')
|
|
screen:expect {
|
|
grid = [[
|
|
^ |
|
|
{1:~ }|*2
|
|
|
|
|
]],
|
|
mode = 'operator',
|
|
}
|
|
|
|
feed('c')
|
|
screen:expect {
|
|
grid = [[
|
|
^ |
|
|
{1:~ }|*2
|
|
{9:E21: Cannot make changes, 'modifiable' is off} |
|
|
]],
|
|
mode = 'normal',
|
|
}
|
|
end)
|
|
|
|
-- oldtest: Test_mouse_shape_after_cancelling_gr()
|
|
it('is restored to Normal mode after cancelling "gr"', function()
|
|
feed('gr')
|
|
screen:expect {
|
|
grid = [[
|
|
^ |
|
|
{1:~ }|*2
|
|
|
|
|
]],
|
|
mode = 'replace',
|
|
}
|
|
|
|
feed('<Esc>')
|
|
screen:expect {
|
|
grid = [[
|
|
^ |
|
|
{1:~ }|*2
|
|
|
|
|
]],
|
|
mode = 'normal',
|
|
}
|
|
end)
|
|
|
|
it('works in insert mode', function()
|
|
feed('i')
|
|
screen:expect {
|
|
grid = [[
|
|
^ |
|
|
{1:~ }|*2
|
|
{5:-- INSERT --} |
|
|
]],
|
|
mode = 'insert',
|
|
}
|
|
|
|
feed('word<esc>')
|
|
screen:expect {
|
|
grid = [[
|
|
wor^d |
|
|
{1:~ }|*2
|
|
|
|
|
]],
|
|
mode = 'normal',
|
|
}
|
|
|
|
local matchtime = 0
|
|
command('set showmatch')
|
|
retry(nil, nil, function()
|
|
matchtime = matchtime + 1
|
|
local screen_timeout = 1000 * matchtime -- fail faster for retry.
|
|
|
|
command('set matchtime=' .. matchtime) -- tenths of seconds
|
|
feed('a(stuff')
|
|
screen:expect {
|
|
grid = [[
|
|
word(stuff^ |
|
|
{1:~ }|*2
|
|
{5:-- INSERT --} |
|
|
]],
|
|
mode = 'insert',
|
|
timeout = screen_timeout,
|
|
}
|
|
|
|
feed(')')
|
|
screen:expect {
|
|
grid = [[
|
|
word^(stuff) |
|
|
{1:~ }|*2
|
|
{5:-- INSERT --} |
|
|
]],
|
|
mode = 'showmatch',
|
|
timeout = screen_timeout,
|
|
}
|
|
|
|
screen:expect {
|
|
grid = [[
|
|
word(stuff)^ |
|
|
{1:~ }|*2
|
|
{5:-- INSERT --} |
|
|
]],
|
|
mode = 'insert',
|
|
timeout = screen_timeout,
|
|
}
|
|
end)
|
|
end)
|
|
|
|
it('works in replace mode', function()
|
|
feed('R')
|
|
screen:expect {
|
|
grid = [[
|
|
^ |
|
|
{1:~ }|*2
|
|
{5:-- REPLACE --} |
|
|
]],
|
|
mode = 'replace',
|
|
}
|
|
|
|
feed('word<esc>')
|
|
screen:expect {
|
|
grid = [[
|
|
wor^d |
|
|
{1:~ }|*2
|
|
|
|
|
]],
|
|
mode = 'normal',
|
|
}
|
|
end)
|
|
|
|
it('works in cmdline mode', function()
|
|
feed(':')
|
|
screen:expect {
|
|
grid = [[
|
|
|
|
|
{1:~ }|*2
|
|
:^ |
|
|
]],
|
|
mode = 'cmdline_normal',
|
|
}
|
|
|
|
feed('x<left>')
|
|
screen:expect {
|
|
grid = [[
|
|
|
|
|
{1:~ }|*2
|
|
:^x |
|
|
]],
|
|
mode = 'cmdline_insert',
|
|
}
|
|
|
|
feed('<insert>')
|
|
screen:expect {
|
|
grid = [[
|
|
|
|
|
{1:~ }|*2
|
|
:^x |
|
|
]],
|
|
mode = 'cmdline_replace',
|
|
}
|
|
|
|
feed('<right>')
|
|
screen:expect {
|
|
grid = [[
|
|
|
|
|
{1:~ }|*2
|
|
:x^ |
|
|
]],
|
|
mode = 'cmdline_normal',
|
|
}
|
|
|
|
feed('<esc>')
|
|
screen:expect {
|
|
grid = [[
|
|
^ |
|
|
{1:~ }|*2
|
|
|
|
|
]],
|
|
mode = 'normal',
|
|
}
|
|
end)
|
|
|
|
it('works in visual mode', function()
|
|
insert('text')
|
|
feed('v')
|
|
screen:expect {
|
|
grid = [[
|
|
tex^t |
|
|
{1:~ }|*2
|
|
{5:-- VISUAL --} |
|
|
]],
|
|
mode = 'visual',
|
|
}
|
|
|
|
feed('<esc>')
|
|
screen:expect {
|
|
grid = [[
|
|
tex^t |
|
|
{1:~ }|*2
|
|
|
|
|
]],
|
|
mode = 'normal',
|
|
}
|
|
|
|
command('set selection=exclusive')
|
|
feed('v')
|
|
screen:expect {
|
|
grid = [[
|
|
tex^t |
|
|
{1:~ }|*2
|
|
{5:-- VISUAL --} |
|
|
]],
|
|
mode = 'visual_select',
|
|
}
|
|
|
|
feed('<esc>')
|
|
screen:expect {
|
|
grid = [[
|
|
tex^t |
|
|
{1:~ }|*2
|
|
|
|
|
]],
|
|
mode = 'normal',
|
|
}
|
|
end)
|
|
end)
|