mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Turn on Ace HTML worker for syntax errors
This commit is contained in:
parent
cb1021e013
commit
58284dff33
4 changed files with 11 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -23,6 +23,7 @@ module.exports = class Problem
|
|||
raw: text,
|
||||
text: text,
|
||||
type: @aetherProblem.level ? 'error'
|
||||
createdBy: 'aether'
|
||||
|
||||
buildMarkerRange: ->
|
||||
return unless @aetherProblem.range
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue