From da0ed94488262cb0cdd958c9aafe5ec2f055304d Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 8 Apr 2014 10:51:22 +0100 Subject: [PATCH] Make inconsistency check more reliable and less likely to trigger a false positive --- .../web/public/coffee/editor/Document.coffee | 19 +++++++++++++++---- .../coffee/ide/SavingAreaManager.coffee | 4 +++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/services/web/public/coffee/editor/Document.coffee b/services/web/public/coffee/editor/Document.coffee index 62987c07e5..b477d41422 100644 --- a/services/web/public/coffee/editor/Document.coffee +++ b/services/web/public/coffee/editor/Document.coffee @@ -20,6 +20,7 @@ define [ @joined = false @wantToBeJoined = false @_checkConsistency = _.bind(@_checkConsistency, @) + @inconsistentCount = 0 @_bindToEditorEvents() @_bindToSocketEvents() @@ -34,10 +35,20 @@ define [ editorDoc?.off "change", @_checkConsistency _checkConsistency: () -> - editorValue = @ace?.getValue() - sharejsValue = @doc?.getSnapshot() - if editorValue != sharejsValue - @_onError "error", new Error("Editor text does not match server text") + # We've been seeing a lot of errors when I think there shouldn't be + # any, which may be related to this check happening before the change is + # applied. If we use a timeout, hopefully we can reduce this. + setTimeout () => + editorValue = @ace?.getValue() + sharejsValue = @doc?.getSnapshot() + if editorValue != sharejsValue + @inconsistentCount++ + else + @inconsistentCount = 0 + + if @inconsistentCount >= 3 + @_onError new Error("Editor text does not match server text") + , 0 getSnapshot: () -> @doc?.getSnapshot() diff --git a/services/web/public/coffee/ide/SavingAreaManager.coffee b/services/web/public/coffee/ide/SavingAreaManager.coffee index 9006eced0a..285995a3ef 100644 --- a/services/web/public/coffee/ide/SavingAreaManager.coffee +++ b/services/web/public/coffee/ide/SavingAreaManager.coffee @@ -13,7 +13,9 @@ define [ @warnAboutUnsavedChanges() pollSavedStatus: () -> - saved = @ide.editor.document.pollSavedStatus() + doc = @ide.editor.document + return if !doc? + saved = doc.pollSavedStatus() if saved @unsavedSeconds = 0 else