From e1cc614da7ef92ad1c1d5bab7ec101455fda8354 Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Wed, 6 May 2020 12:01:35 +0200 Subject: [PATCH] Merge pull request #2800 from overleaf/jpa-force-flush-onblur [frontend] EditorManager: flush the documents as the editor looses focus GitOrigin-RevId: 9157eba091e21c80202448b6c28c22dddd8cb687 --- services/web/frontend/js/ide/editor/EditorManager.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services/web/frontend/js/ide/editor/EditorManager.js b/services/web/frontend/js/ide/editor/EditorManager.js index ab8eb8913c..c9047c3876 100644 --- a/services/web/frontend/js/ide/editor/EditorManager.js +++ b/services/web/frontend/js/ide/editor/EditorManager.js @@ -75,6 +75,15 @@ define([ this.$scope.$on('flush-changes', () => { return Document.flushAll() }) + window.addEventListener('blur', () => { + // The browser may put the tab into sleep as it looses focus. + // Flushing the documents should help with keeping the documents in + // sync: we can use any new version of the doc that the server may + // present us. There should be no need to insert local changes into + // the doc history as the user comes back. + sl_console.log('[EditorManager] forcing flush onblur') + Document.flushAll() + }) this.$scope.$watch('editor.wantTrackChanges', value => { if (value == null) {