From 403d822174a1e1061312bc245ba8d76eccca742a Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Thu, 15 Jun 2017 14:09:49 +0100 Subject: [PATCH] Alter labels debouncer to handle transitions between docs --- .../aceEditor/labels/LabelsManager.coffee | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/labels/LabelsManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/labels/LabelsManager.coffee index 07b60b08b9..a5d2c10625 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/labels/LabelsManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/labels/LabelsManager.coffee @@ -11,7 +11,7 @@ define [ class LabelsManager constructor: (@$scope, @editor, @element, @Labels) -> - @loadLabelsTimeout = null + @debouncer = {} # DocId => Timeout onChange = (change) => if change.remote @@ -36,13 +36,20 @@ define [ currentDocId = @$scope.docId @Labels.loadDocLabelsFromServer(currentDocId) + loadDocLabelsFromServer: (docId) -> + @Labels.loadDocLabelsFromServer(docId) + scheduleLoadCurrentDocLabelsFromServer: () -> # De-bounce loading labels with a timeout - if @loadLabelsTimeout - clearTimeout(@loadLabelsTimeout) - @loadLabelsTimeout = setTimeout( + currentDocId = @$scope.docId + existingTimeout = @debouncer[currentDocId] + if existingTimeout? + clearTimeout(existingTimeout) + delete @debouncer[currentDocId] + @debouncer[currentDocId] = setTimeout( () => - @loadCurrentDocLabelsFromServer() + @loadDocLabelsFromServer(currentDocId) + delete @debouncer[currentDocId] , 1000 , this )