From 58284dff338efe328c2a38af8f3df2581b8abd2f Mon Sep 17 00:00:00 2001 From: phoenixeliot Date: Tue, 19 Jul 2016 11:29:57 -0700 Subject: [PATCH] Turn on Ace HTML worker for syntax errors --- app/core/utils.coffee | 2 ++ app/views/play/level/tome/Problem.coffee | 1 + app/views/play/level/tome/SpellPaletteEntryView.coffee | 1 + app/views/play/level/tome/SpellView.coffee | 10 +++++++--- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/core/utils.coffee b/app/core/utils.coffee index ca921ba82..166db035e 100644 --- a/app/core/utils.coffee +++ b/app/core/utils.coffee @@ -297,6 +297,8 @@ module.exports.aceEditModes = aceEditModes = java: 'ace/mode/java' html: 'ace/mode/html' +# These ACEs are used for displaying code snippets statically, like in SpellPaletteEntryView popovers +# and have short lifespans module.exports.initializeACE = (el, codeLanguage) -> contents = $(el).text().trim() editor = ace.edit el diff --git a/app/views/play/level/tome/Problem.coffee b/app/views/play/level/tome/Problem.coffee index a42addd5d..9b5b22fa8 100644 --- a/app/views/play/level/tome/Problem.coffee +++ b/app/views/play/level/tome/Problem.coffee @@ -23,6 +23,7 @@ module.exports = class Problem raw: text, text: text, type: @aetherProblem.level ? 'error' + createdBy: 'aether' buildMarkerRange: -> return unless @aetherProblem.range diff --git a/app/views/play/level/tome/SpellPaletteEntryView.coffee b/app/views/play/level/tome/SpellPaletteEntryView.coffee index c6332828c..1b400b673 100644 --- a/app/views/play/level/tome/SpellPaletteEntryView.coffee +++ b/app/views/play/level/tome/SpellPaletteEntryView.coffee @@ -53,6 +53,7 @@ module.exports = class SpellPaletteEntryView extends CocoView oldEditor.destroy() for oldEditor in @aceEditors @aceEditors = [] aceEditors = @aceEditors + # Initialize Ace for each popover code snippet popover?.$tip?.find('.docs-ace').each -> aceEditor = utils.initializeACE @, codeLanguage aceEditors.push aceEditor diff --git a/app/views/play/level/tome/SpellView.coffee b/app/views/play/level/tome/SpellView.coffee index bda7f943c..f288a12d1 100644 --- a/app/views/play/level/tome/SpellView.coffee +++ b/app/views/play/level/tome/SpellView.coffee @@ -21,6 +21,7 @@ module.exports = class SpellView extends CocoView controlsEnabled: true eventsSuppressed: true writable: true + languagesThatUseWorkers: ['html'] keyBindings: 'default': null @@ -78,6 +79,7 @@ module.exports = class SpellView extends CocoView @lockDefaultCode() _.defer @onAllLoaded # Needs to happen after the code generating this view is complete + # This ACE is used for the code editor, and is only instantiated once per level. createACE: -> # Test themes and settings here: http://ace.ajax.org/build/kitchen-sink.html aceConfig = me.get('aceConfig') ? {} @@ -85,7 +87,7 @@ module.exports = class SpellView extends CocoView @ace = ace.edit @$el.find('.ace')[0] @aceSession = @ace.getSession() @aceDoc = @aceSession.getDocument() - @aceSession.setUseWorker false + @aceSession.setUseWorker @spell.language in @languagesThatUseWorkers @aceSession.setMode utils.aceEditModes[@spell.language] @aceSession.setWrapLimitRange null @aceSession.setUseWrapMode true @@ -789,10 +791,12 @@ module.exports = class SpellView extends CocoView else finishUpdatingAether(aether) + # Clear annotations and highlights generated by Aether, but not by the ACE worker clearAetherDisplay: -> problem.destroy() for problem in @problems @problems = [] - @aceSession.setAnnotations [] + nonAetherAnnotations = _.reject @aceSession.getAnnotations(), (annotation) -> annotation.createdBy is 'aether' + @aceSession.setAnnotations nonAetherAnnotations @highlightCurrentLine {} # This'll remove all highlights displayAether: (aether, isCast=false) -> @@ -800,7 +804,7 @@ module.exports = class SpellView extends CocoView isCast = isCast or not _.isEmpty(aether.metrics) or _.some aether.getAllProblems(), {type: 'runtime'} problem.destroy() for problem in @problems # Just in case another problem was added since clearAetherDisplay() ran. @problems = [] - annotations = [] + annotations = @aceSession.getAnnotations() seenProblemKeys = {} for aetherProblem, problemIndex in aether.getAllProblems() continue if key = aetherProblem.userInfo?.key and key of seenProblemKeys