diff --git a/app.go b/app.go index f3e5f80c..2f6f48ef 100644 --- a/app.go +++ b/app.go @@ -477,9 +477,13 @@ func (app *app) loop() { } if ev.Has(fsnotify.Write) || ev.Has(fsnotify.Chmod) { - app.nav.watcherWrites[ev.Name] = true + if !app.nav.watcherWrites[ev.Name] { + app.nav.watcherWrites[ev.Name] = true + app.nav.watcherTimer.Stop() + app.nav.watcherTimer.Reset(10 * time.Millisecond) + } } - case <-app.nav.watcherTicker.C: + case <-app.nav.watcherTimer.C: for path := range app.nav.watcherWrites { app.updateFile(path, true) currFile, err := app.nav.currFile() diff --git a/nav.go b/nav.go index 072381cd..51a2ce52 100644 --- a/nav.go +++ b/nav.go @@ -468,7 +468,7 @@ type nav struct { watcher *fsnotify.Watcher watcherEvents <-chan fsnotify.Event watcherWrites map[string]bool - watcherTicker *time.Ticker + watcherTimer *time.Timer } func (nav *nav) loadDirInternal(path string) *dir { @@ -607,7 +607,7 @@ func newNav(height int) *nav { jumpList: make([]string, 0), jumpListInd: -1, watcherWrites: make(map[string]bool), - watcherTicker: new(time.Ticker), + watcherTimer: time.NewTimer(0), } return nav @@ -2084,7 +2084,6 @@ func (nav *nav) startWatcher() { nav.watcher = watcher nav.watcherEvents = watcher.Events - nav.watcherTicker = time.NewTicker(10 * time.Millisecond) } func (nav *nav) stopWatcher() { @@ -2096,7 +2095,6 @@ func (nav *nav) stopWatcher() { nav.watcher = nil nav.watcherEvents = nil - nav.watcherTicker.Stop() } func (nav *nav) setWatches() {