From 8bee2ff19d8d3a94d6d8e1912c46cb33f8481a5b Mon Sep 17 00:00:00 2001 From: BK1603 Date: Thu, 25 Jun 2020 04:09:52 +0530 Subject: Update file on focus gained --- src/nvim/aucmd.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/aucmd.c b/src/nvim/aucmd.c index a9a7d834a4..de11ae8a65 100644 --- a/src/nvim/aucmd.c +++ b/src/nvim/aucmd.c @@ -8,6 +8,8 @@ #include "nvim/ui.h" #include "nvim/aucmd.h" #include "nvim/eval.h" +#include "nvim/ex_getln.h" +#include "nvim/buffer.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "aucmd.c.generated.h" @@ -50,12 +52,46 @@ void aucmd_schedule_focusgained(bool gained) static void do_autocmd_focusgained(bool gained) { static bool recursive = false; + static Timestamp last_time = (time_t)0; + bool need_redraw = false; if (recursive) { return; // disallow recursion } recursive = true; - apply_autocmds((gained ? EVENT_FOCUSGAINED : EVENT_FOCUSLOST), - NULL, NULL, false, curbuf); + need_redraw |= apply_autocmds((gained ? EVENT_FOCUSGAINED : EVENT_FOCUSLOST), + 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; } -- cgit From ae183990ee94ce48b3aec28e83de094df1ef880c Mon Sep 17 00:00:00 2001 From: BK1603 Date: Thu, 2 Jul 2020 23:56:55 +0530 Subject: clarified the reason for wait --- src/nvim/aucmd.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/aucmd.c b/src/nvim/aucmd.c index de11ae8a65..18404c4cd5 100644 --- a/src/nvim/aucmd.c +++ b/src/nvim/aucmd.c @@ -63,10 +63,12 @@ static void do_autocmd_focusgained(bool gained) 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). + // Only do this when not done within the last two seconds as: + // 1. Some filesystems have modification time granularity in seconds. Fat32 + // has a granularity of 2 seconds. + // 2. We could get multiple notifications in a row. - if (gained && last_time + (Timestamp)1500 < os_now()) { + if (gained && last_time + (Timestamp)2000 < os_now()) { need_redraw = check_timestamps(true); last_time = os_now(); } -- cgit From 435344034d984a1b7af21ecaf9a7c107758a051c Mon Sep 17 00:00:00 2001 From: BK1603 Date: Fri, 3 Jul 2020 14:14:08 +0530 Subject: removed whitespace --- src/nvim/aucmd.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/nvim/aucmd.c b/src/nvim/aucmd.c index 18404c4cd5..32c77fa288 100644 --- a/src/nvim/aucmd.c +++ b/src/nvim/aucmd.c @@ -67,7 +67,6 @@ static void do_autocmd_focusgained(bool gained) // 1. Some filesystems have modification time granularity in seconds. Fat32 // has a granularity of 2 seconds. // 2. We could get multiple notifications in a row. - if (gained && last_time + (Timestamp)2000 < os_now()) { need_redraw = check_timestamps(true); last_time = os_now(); -- cgit