diff options
author | Matthieu Coudron <mattator@gmail.com> | 2020-07-04 15:27:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-04 15:27:32 +0200 |
commit | bd5f0e9695cb21c8b97f844ce21432ee8d06b7ed (patch) | |
tree | 0e498107e4b50079d81558af471628a6d1e089d2 /src | |
parent | f137307dcee02ee287f77b986281232b42d36a86 (diff) | |
parent | bab77d122fa6230dabb54b7b8d2554cbc89da6e3 (diff) | |
download | rneovim-bd5f0e9695cb21c8b97f844ce21432ee8d06b7ed.tar.gz rneovim-bd5f0e9695cb21c8b97f844ce21432ee8d06b7ed.tar.bz2 rneovim-bd5f0e9695cb21c8b97f844ce21432ee8d06b7ed.zip |
Merge pull request #12531 from BK1603/autoread-tui
Autoread now works in TUI too. The checktimestamp test is run at most once every 2 seconds not to poll too much and also because it doesn't make sense on some filesystems. A solution based on filesystem notifications should arrive soon.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/aucmd.c | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/nvim/aucmd.c b/src/nvim/aucmd.c index a9a7d834a4..32c77fa288 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,47 @@ 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 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)2000 < 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; } |