mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge PR #3715 'Enable focus events in cmdline and terminal modes'
This commit is contained in:
commit
97cee2c2e3
@ -1448,6 +1448,14 @@ static int command_line_handle_key(CommandLineState *s)
|
|||||||
}
|
}
|
||||||
return command_line_not_changed(s);
|
return command_line_not_changed(s);
|
||||||
|
|
||||||
|
case K_FOCUSGAINED: // Neovim has been given focus
|
||||||
|
apply_autocmds(EVENT_FOCUSGAINED, NULL, NULL, false, curbuf);
|
||||||
|
return command_line_not_changed(s);
|
||||||
|
|
||||||
|
case K_FOCUSLOST: // Neovim has lost focus
|
||||||
|
apply_autocmds(EVENT_FOCUSLOST, NULL, NULL, false, curbuf);
|
||||||
|
return command_line_not_changed(s);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Normal character with no special meaning. Just set mod_mask
|
// Normal character with no special meaning. Just set mod_mask
|
||||||
// to 0x0 so that typing Shift-Space in the GUI doesn't enter
|
// to 0x0 so that typing Shift-Space in the GUI doesn't enter
|
||||||
|
@ -402,6 +402,14 @@ static int terminal_execute(VimState *state, int key)
|
|||||||
TerminalState *s = (TerminalState *)state;
|
TerminalState *s = (TerminalState *)state;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
|
case K_FOCUSGAINED: // Neovim has been given focus
|
||||||
|
apply_autocmds(EVENT_FOCUSGAINED, NULL, NULL, false, curbuf);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case K_FOCUSLOST: // Neovim has lost focus
|
||||||
|
apply_autocmds(EVENT_FOCUSLOST, NULL, NULL, false, curbuf);
|
||||||
|
break;
|
||||||
|
|
||||||
case K_LEFTMOUSE:
|
case K_LEFTMOUSE:
|
||||||
case K_LEFTDRAG:
|
case K_LEFTDRAG:
|
||||||
case K_LEFTRELEASE:
|
case K_LEFTRELEASE:
|
||||||
|
@ -5,6 +5,7 @@ local helpers = require('test.functional.helpers')
|
|||||||
local thelpers = require('test.functional.terminal.helpers')
|
local thelpers = require('test.functional.terminal.helpers')
|
||||||
local feed = thelpers.feed_data
|
local feed = thelpers.feed_data
|
||||||
local execute = helpers.execute
|
local execute = helpers.execute
|
||||||
|
local nvim_dir = helpers.nvim_dir
|
||||||
|
|
||||||
describe('tui', function()
|
describe('tui', function()
|
||||||
local screen
|
local screen
|
||||||
@ -148,32 +149,6 @@ describe('tui', function()
|
|||||||
-- TERMINAL -- |
|
-- TERMINAL -- |
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('can handle focus events', function()
|
|
||||||
execute('autocmd FocusGained * echo "gained"')
|
|
||||||
execute('autocmd FocusLost * echo "lost"')
|
|
||||||
feed('\x1b[I')
|
|
||||||
screen:expect([[
|
|
||||||
{1: } |
|
|
||||||
~ |
|
|
||||||
~ |
|
|
||||||
~ |
|
|
||||||
[No Name] |
|
|
||||||
gained |
|
|
||||||
-- TERMINAL -- |
|
|
||||||
]])
|
|
||||||
|
|
||||||
feed('\x1b[O')
|
|
||||||
screen:expect([[
|
|
||||||
{1: } |
|
|
||||||
~ |
|
|
||||||
~ |
|
|
||||||
~ |
|
|
||||||
[No Name] |
|
|
||||||
lost |
|
|
||||||
-- TERMINAL -- |
|
|
||||||
]])
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('tui with non-tty file descriptors', function()
|
describe('tui with non-tty file descriptors', function()
|
||||||
@ -199,3 +174,112 @@ describe('tui with non-tty file descriptors', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('tui focus event handling', function()
|
||||||
|
before_each(function()
|
||||||
|
helpers.clear()
|
||||||
|
screen = thelpers.screen_setup(0, '["'..helpers.nvim_prog..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile"]')
|
||||||
|
execute('autocmd FocusGained * echo "gained"')
|
||||||
|
execute('autocmd FocusLost * echo "lost"')
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('can handle focus events in normal mode', function()
|
||||||
|
feed('\x1b[I')
|
||||||
|
screen:expect([[
|
||||||
|
{1: } |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
[No Name] |
|
||||||
|
gained |
|
||||||
|
-- TERMINAL -- |
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('\x1b[O')
|
||||||
|
screen:expect([[
|
||||||
|
{1: } |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
[No Name] |
|
||||||
|
lost |
|
||||||
|
-- TERMINAL -- |
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('can handle focus events in insert mode', function()
|
||||||
|
execute('set noshowmode')
|
||||||
|
feed('i')
|
||||||
|
feed('\x1b[I')
|
||||||
|
screen:expect([[
|
||||||
|
{1: } |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
[No Name] |
|
||||||
|
gained |
|
||||||
|
-- TERMINAL -- |
|
||||||
|
]])
|
||||||
|
feed('\x1b[O')
|
||||||
|
screen:expect([[
|
||||||
|
{1: } |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
[No Name] |
|
||||||
|
lost |
|
||||||
|
-- TERMINAL -- |
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('can handle focus events in cmdline mode', function()
|
||||||
|
feed(':')
|
||||||
|
feed('\x1b[I')
|
||||||
|
screen:expect([[
|
||||||
|
|
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
[No Name] |
|
||||||
|
g{1:a}ined |
|
||||||
|
-- TERMINAL -- |
|
||||||
|
]])
|
||||||
|
feed('\x1b[O')
|
||||||
|
screen:expect([[
|
||||||
|
|
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
[No Name] |
|
||||||
|
l{1:o}st |
|
||||||
|
-- TERMINAL -- |
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('can handle focus events in terminal mode', function()
|
||||||
|
execute('set shell='..nvim_dir..'/shell-test')
|
||||||
|
execute('set laststatus=0')
|
||||||
|
execute('set noshowmode')
|
||||||
|
execute('terminal')
|
||||||
|
feed('\x1b[I')
|
||||||
|
screen:expect([[
|
||||||
|
ready $ |
|
||||||
|
[Process exited 0]{1: } |
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
gained |
|
||||||
|
-- TERMINAL -- |
|
||||||
|
]])
|
||||||
|
feed('\x1b[O')
|
||||||
|
screen:expect([[
|
||||||
|
ready $ |
|
||||||
|
[Process exited 0]{1: } |
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
lost |
|
||||||
|
-- TERMINAL -- |
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user