mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
Enable focus events in cmdline and terminal modes
This change adds switch cases for K_FOCUSGAINED and K_FOCUSLOST to the input handling functions in ex_getln.c and terminal.c. The handling is identical to what's found in edit.c (just calling apply_autocmds). If one enters cmdline-mode by feeding `:` and sends a focuslost event (by leaving the window for example) the text `<FocusLost>` will be inserted into the command line. There is similar behaviour in terminal mode. This patch corrects this behavior to fire the apropriate autocmd instead. Fixes #3714
This commit is contained in:

committed by
Marco Hinz

parent
321db59ca1
commit
442cd0672b
@@ -1448,6 +1448,14 @@ static int command_line_handle_key(CommandLineState *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:
|
||||
// Normal character with no special meaning. Just set mod_mask
|
||||
// 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;
|
||||
|
||||
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_LEFTDRAG:
|
||||
case K_LEFTRELEASE:
|
||||
|
@@ -5,6 +5,7 @@ local helpers = require('test.functional.helpers')
|
||||
local thelpers = require('test.functional.terminal.helpers')
|
||||
local feed = thelpers.feed_data
|
||||
local execute = helpers.execute
|
||||
local nvim_dir = helpers.nvim_dir
|
||||
|
||||
describe('tui', function()
|
||||
local screen
|
||||
@@ -150,8 +151,11 @@ describe('tui', function()
|
||||
end)
|
||||
|
||||
it('can handle focus events', function()
|
||||
execute('set noshowmode')
|
||||
execute('autocmd FocusGained * echo "gained"')
|
||||
execute('autocmd FocusLost * echo "lost"')
|
||||
|
||||
-- In normal mode
|
||||
feed('\x1b[I')
|
||||
screen:expect([[
|
||||
{1: } |
|
||||
@@ -173,6 +177,79 @@ describe('tui', function()
|
||||
lost |
|
||||
-- TERMINAL -- |
|
||||
]])
|
||||
|
||||
-- In insert mode
|
||||
feed('i')
|
||||
feed('\x1b[I')
|
||||
screen:expect([[
|
||||
{1: } |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
[No Name] |
|
||||
gained |
|
||||
-- TERMINAL -- |
|
||||
]])
|
||||
feed('\x1b[O')
|
||||
screen:expect([[
|
||||
{1: } |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
[No Name] |
|
||||
lost |
|
||||
-- TERMINAL -- |
|
||||
]])
|
||||
|
||||
-- In command-line mode
|
||||
feed('\x1b')
|
||||
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 -- |
|
||||
]])
|
||||
|
||||
-- In terminal mode
|
||||
execute('set shell='..nvim_dir..'/shell-test')
|
||||
execute('set laststatus=0')
|
||||
feed('\x1b')
|
||||
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)
|
||||
|
||||
|
Reference in New Issue
Block a user