mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
vim-patch:8.2.3461: distinguish Normal and Terminal-Normal mode #15878
Problem: Cannot distinguish Normal and Terminal-Normal mode.
Solution: Make mode() return "nt" for Terminal-Normal mode. (issue vim/vim#8856)
72406a4bd2
This commit is contained in:
@@ -6864,6 +6864,8 @@ mode([expr]) Return a string that indicates the current mode.
|
|||||||
niI Normal using |i_CTRL-O| in |Insert-mode|
|
niI Normal using |i_CTRL-O| in |Insert-mode|
|
||||||
niR Normal using |i_CTRL-O| in |Replace-mode|
|
niR Normal using |i_CTRL-O| in |Replace-mode|
|
||||||
niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
|
niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
|
||||||
|
nt Normal in |terminal-emulator| (insert goes to
|
||||||
|
Terminal mode)
|
||||||
v Visual by character
|
v Visual by character
|
||||||
vs Visual by character using |v_CTRL-O| in Select mode
|
vs Visual by character using |v_CTRL-O| in Select mode
|
||||||
V Visual by line
|
V Visual by line
|
||||||
|
@@ -195,6 +195,8 @@ char *get_mode(void)
|
|||||||
|| restart_edit == 'V') {
|
|| restart_edit == 'V') {
|
||||||
buf[1] = 'i';
|
buf[1] = 'i';
|
||||||
buf[2] = (char)restart_edit;
|
buf[2] = (char)restart_edit;
|
||||||
|
} else if (curbuf->terminal) {
|
||||||
|
buf[1] = 't';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -710,6 +710,14 @@ func Test_mode()
|
|||||||
call assert_equal('c-cv', g:current_modes)
|
call assert_equal('c-cv', g:current_modes)
|
||||||
" How to test Ex mode?
|
" How to test Ex mode?
|
||||||
|
|
||||||
|
if has('terminal')
|
||||||
|
term
|
||||||
|
call feedkeys("\<C-W>N", 'xt')
|
||||||
|
call assert_equal('n', mode())
|
||||||
|
call assert_equal('nt', mode(1))
|
||||||
|
call feedkeys("aexit\<CR>", 'xt')
|
||||||
|
endif
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
iunmap <F2>
|
iunmap <F2>
|
||||||
xunmap <F2>
|
xunmap <F2>
|
||||||
|
@@ -24,11 +24,11 @@ describe(':terminal buffer', function()
|
|||||||
feed([[<C-\><C-N>]])
|
feed([[<C-\><C-N>]])
|
||||||
command('setlocal cursorline cursorlineopt=both cursorcolumn scrolloff=4 sidescrolloff=7')
|
command('setlocal cursorline cursorlineopt=both cursorcolumn scrolloff=4 sidescrolloff=7')
|
||||||
eq({ 'both', 1, 1, 4, 7 }, eval('[&l:cursorlineopt, &l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]'))
|
eq({ 'both', 1, 1, 4, 7 }, eval('[&l:cursorlineopt, &l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]'))
|
||||||
eq('n', eval('mode()'))
|
eq('nt', eval('mode(1)'))
|
||||||
|
|
||||||
-- Enter terminal-mode ("insert" mode in :terminal).
|
-- Enter terminal-mode ("insert" mode in :terminal).
|
||||||
feed('i')
|
feed('i')
|
||||||
eq('t', eval('mode()'))
|
eq('t', eval('mode(1)'))
|
||||||
eq({ 'number', 1, 0, 0, 0 }, eval('[&l:cursorlineopt, &l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]'))
|
eq({ 'number', 1, 0, 0, 0 }, eval('[&l:cursorlineopt, &l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@@ -96,19 +96,28 @@ describe(':terminal', function()
|
|||||||
eq(3, #jumps)
|
eq(3, #jumps)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('nvim_get_mode() in :terminal', function()
|
||||||
|
command(':terminal')
|
||||||
|
eq({ blocking=false, mode='nt' }, nvim('get_mode'))
|
||||||
|
feed('i')
|
||||||
|
eq({ blocking=false, mode='t' }, nvim('get_mode'))
|
||||||
|
feed([[<C-\><C-N>]])
|
||||||
|
eq({ blocking=false, mode='nt' }, nvim('get_mode'))
|
||||||
|
end)
|
||||||
|
|
||||||
it(':stopinsert RPC request exits terminal-mode #7807', function()
|
it(':stopinsert RPC request exits terminal-mode #7807', function()
|
||||||
command(':terminal')
|
command(':terminal')
|
||||||
feed('i[tui] insert-mode')
|
feed('i[tui] insert-mode')
|
||||||
eq({ blocking=false, mode='t' }, nvim('get_mode'))
|
eq({ blocking=false, mode='t' }, nvim('get_mode'))
|
||||||
command('stopinsert')
|
command('stopinsert')
|
||||||
eq({ blocking=false, mode='n' }, nvim('get_mode'))
|
eq({ blocking=false, mode='nt' }, nvim('get_mode'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it(':stopinsert in normal mode doesn\'t break insert mode #9889', function()
|
it(':stopinsert in normal mode doesn\'t break insert mode #9889', function()
|
||||||
command(':terminal')
|
command(':terminal')
|
||||||
eq({ blocking=false, mode='n' }, nvim('get_mode'))
|
eq({ blocking=false, mode='nt' }, nvim('get_mode'))
|
||||||
command(':stopinsert')
|
command(':stopinsert')
|
||||||
eq({ blocking=false, mode='n' }, nvim('get_mode'))
|
eq({ blocking=false, mode='nt' }, nvim('get_mode'))
|
||||||
feed('a')
|
feed('a')
|
||||||
eq({ blocking=false, mode='t' }, nvim('get_mode'))
|
eq({ blocking=false, mode='t' }, nvim('get_mode'))
|
||||||
end)
|
end)
|
||||||
|
@@ -33,16 +33,16 @@ describe(':terminal mouse', function()
|
|||||||
|
|
||||||
describe('when the terminal has focus', function()
|
describe('when the terminal has focus', function()
|
||||||
it('will exit focus on mouse-scroll', function()
|
it('will exit focus on mouse-scroll', function()
|
||||||
eq('t', eval('mode()'))
|
eq('t', eval('mode(1)'))
|
||||||
feed('<ScrollWheelUp><0,0>')
|
feed('<ScrollWheelUp><0,0>')
|
||||||
eq('n', eval('mode()'))
|
eq('nt', eval('mode(1)'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('will exit focus on <C-\\> + mouse-scroll', function()
|
it('will exit focus on <C-\\> + mouse-scroll', function()
|
||||||
eq('t', eval('mode()'))
|
eq('t', eval('mode(1)'))
|
||||||
feed('<C-\\>')
|
feed('<C-\\>')
|
||||||
feed('<ScrollWheelUp><0,0>')
|
feed('<ScrollWheelUp><0,0>')
|
||||||
eq('n', eval('mode()'))
|
eq('nt', eval('mode(1)'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('with mouse events enabled by the program', function()
|
describe('with mouse events enabled by the program', function()
|
||||||
@@ -94,7 +94,7 @@ describe(':terminal mouse', function()
|
|||||||
-- When the display area such as a number is clicked, it returns to the
|
-- When the display area such as a number is clicked, it returns to the
|
||||||
-- normal mode.
|
-- normal mode.
|
||||||
feed('<LeftMouse><3,0>')
|
feed('<LeftMouse><3,0>')
|
||||||
eq('n', eval('mode()'))
|
eq('nt', eval('mode(1)'))
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
{7: 11 }^line28 |
|
{7: 11 }^line28 |
|
||||||
{7: 12 }line29 |
|
{7: 12 }line29 |
|
||||||
|
@@ -111,7 +111,7 @@ describe(':terminal', function()
|
|||||||
command('terminal')
|
command('terminal')
|
||||||
feed('a<Cmd>wincmd j<CR>')
|
feed('a<Cmd>wincmd j<CR>')
|
||||||
eq(2, eval("winnr()"))
|
eq(2, eval("winnr()"))
|
||||||
eq('t', eval('mode()'))
|
eq('t', eval('mode(1)'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user