Turn on Ace HTML worker for syntax errors

This commit is contained in:
phoenixeliot 2016-07-19 11:29:57 -07:00
parent cb1021e013
commit 58284dff33
4 changed files with 11 additions and 3 deletions

View file

@ -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

View file

@ -23,6 +23,7 @@ module.exports = class Problem
raw: text,
text: text,
type: @aetherProblem.level ? 'error'
createdBy: 'aether'
buildMarkerRange: ->
return unless @aetherProblem.range

View file

@ -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

View file

@ -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