mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 17:06:30 +00:00
Update file on focus gained
This commit is contained in:
@@ -8,6 +8,8 @@
|
|||||||
#include "nvim/ui.h"
|
#include "nvim/ui.h"
|
||||||
#include "nvim/aucmd.h"
|
#include "nvim/aucmd.h"
|
||||||
#include "nvim/eval.h"
|
#include "nvim/eval.h"
|
||||||
|
#include "nvim/ex_getln.h"
|
||||||
|
#include "nvim/buffer.h"
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "aucmd.c.generated.h"
|
# include "aucmd.c.generated.h"
|
||||||
@@ -50,12 +52,46 @@ void aucmd_schedule_focusgained(bool gained)
|
|||||||
static void do_autocmd_focusgained(bool gained)
|
static void do_autocmd_focusgained(bool gained)
|
||||||
{
|
{
|
||||||
static bool recursive = false;
|
static bool recursive = false;
|
||||||
|
static Timestamp last_time = (time_t)0;
|
||||||
|
bool need_redraw = false;
|
||||||
|
|
||||||
if (recursive) {
|
if (recursive) {
|
||||||
return; // disallow recursion
|
return; // disallow recursion
|
||||||
}
|
}
|
||||||
recursive = true;
|
recursive = true;
|
||||||
apply_autocmds((gained ? EVENT_FOCUSGAINED : EVENT_FOCUSLOST),
|
need_redraw |= apply_autocmds((gained ? EVENT_FOCUSGAINED : EVENT_FOCUSLOST),
|
||||||
NULL, NULL, false, curbuf);
|
NULL, NULL, false, curbuf);
|
||||||
|
|
||||||
|
// When activated: Check if any file was modified outside of Vim.
|
||||||
|
// Only do this when not done within the last two seconds (could get
|
||||||
|
// several events in a row).
|
||||||
|
|
||||||
|
if (gained && last_time + (Timestamp)1500 < os_now()) {
|
||||||
|
need_redraw = check_timestamps(true);
|
||||||
|
last_time = os_now();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (need_redraw) {
|
||||||
|
// Something was executed, make sure the cursor is put back where it
|
||||||
|
// belongs.
|
||||||
|
need_wait_return = false;
|
||||||
|
|
||||||
|
if (State & CMDLINE) {
|
||||||
|
redrawcmdline();
|
||||||
|
} else if ((State & NORMAL) || (State & INSERT)) {
|
||||||
|
if (must_redraw != 0) {
|
||||||
|
update_screen(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
setcursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (need_maketitle) {
|
||||||
|
maketitle();
|
||||||
|
}
|
||||||
|
|
||||||
recursive = false;
|
recursive = false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user