From 442cd0672b567cce56dd45e731ec1cc3b71b7cf4 Mon Sep 17 00:00:00 2001 From: Joe Hermaszewski Date: Fri, 20 Nov 2015 18:47:20 +0000 Subject: 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 `` 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 --- src/nvim/ex_getln.c | 8 ++++++++ src/nvim/terminal.c | 8 ++++++++ 2 files changed, 16 insertions(+) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 52292128d8..cbaf15e38d 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -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 diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 119ee2c5b3..adf3f725a2 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -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: -- cgit