nitlight_aas: register and clean line widgets.
authorJean Privat <jean@pryen.org>
Thu, 23 Jun 2016 18:15:51 +0000 (14:15 -0400)
committerJean Privat <jean@pryen.org>
Thu, 23 Jun 2016 18:15:51 +0000 (14:15 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/examples/nitlight_as_a_service.nit

index 7007b70..808837a 100644 (file)
@@ -85,12 +85,18 @@ class HLCode
                res.add """
        function nitmessage() {
                editor.operation(function(){
+                       for (var i = 0; i < widgets.length; ++i)
+                             editor.removeLineWidget(widgets[i]);
+                       widgets.length = 0;
+"""
+
                for m in source.messages do
                        res.add """
                        var l = document.createElement("div");
                        l.className = "lint-error"
                        l.innerHTML = "<span class='glyphicon glyphicon-warning-sign lint-error-icon'></span> {{{m.text.html_escape}}}";
                        var w = editor.addLineWidget({{{m.location.line_start-1}}}, l);
+                       widgets.push(w);
 """
                end
                res.add """});}"""
@@ -161,6 +167,7 @@ class HighlightAction
                        page.add "function nitmessage()\{\}"
                end
                page.add """
+               var widgets = [];
                nitmessage();
 
                </script>