From 2936b342342ed1ed7e673404250616ccd2945e47 Mon Sep 17 00:00:00 2001 From: combomintopter Date: Wed, 1 Jul 2015 01:44:14 +0200 Subject: [PATCH] Fixed #9, test widgets weren't cleaned up on parse --- editor/plugins/collectTests.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/editor/plugins/collectTests.js b/editor/plugins/collectTests.js index c86907c..1013be2 100644 --- a/editor/plugins/collectTests.js +++ b/editor/plugins/collectTests.js @@ -3,7 +3,10 @@ var lineWidgets = []; Moonchild.on('parse', function(ast) { var tests = {}; - _.invoke(lineWidgets, 'clear'); // Clear widgets from the last parse. + // Tell codemirror to clear all widgets, and remove all widget references. + // At every edit, all widgets are removed and then rerendered. + _.invoke(lineWidgets, 'clear'); + lineWidgets = []; if (!options.collectTests) return; @@ -17,7 +20,7 @@ Moonchild.on('parse', function(ast) { // Find functions that have tests, and run the tests. ast.where({ 'type': 'FunctionDeclaration' }).each(function(node) { - if (node.id.name in tests) { + if (node.id.name in tests) { var loc = esLocToCm(node.loc.start); var el = createElement('div', { 'class': 'test-result' }, 'Tests'); var widget = codeMirror.addLineWidget(loc.line, el, { above: true }); @@ -31,6 +34,6 @@ Moonchild.on('parse', function(ast) { result = true; } catch(e) {} el.classList.toggle('ok', !!result); - } + } }); });