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'
|
java: 'ace/mode/java'
|
||||||
html: 'ace/mode/html'
|
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) ->
|
module.exports.initializeACE = (el, codeLanguage) ->
|
||||||
contents = $(el).text().trim()
|
contents = $(el).text().trim()
|
||||||
editor = ace.edit el
|
editor = ace.edit el
|
||||||
|
|
|
@ -23,6 +23,7 @@ module.exports = class Problem
|
||||||
raw: text,
|
raw: text,
|
||||||
text: text,
|
text: text,
|
||||||
type: @aetherProblem.level ? 'error'
|
type: @aetherProblem.level ? 'error'
|
||||||
|
createdBy: 'aether'
|
||||||
|
|
||||||
buildMarkerRange: ->
|
buildMarkerRange: ->
|
||||||
return unless @aetherProblem.range
|
return unless @aetherProblem.range
|
||||||
|
|
|
@ -53,6 +53,7 @@ module.exports = class SpellPaletteEntryView extends CocoView
|
||||||
oldEditor.destroy() for oldEditor in @aceEditors
|
oldEditor.destroy() for oldEditor in @aceEditors
|
||||||
@aceEditors = []
|
@aceEditors = []
|
||||||
aceEditors = @aceEditors
|
aceEditors = @aceEditors
|
||||||
|
# Initialize Ace for each popover code snippet
|
||||||
popover?.$tip?.find('.docs-ace').each ->
|
popover?.$tip?.find('.docs-ace').each ->
|
||||||
aceEditor = utils.initializeACE @, codeLanguage
|
aceEditor = utils.initializeACE @, codeLanguage
|
||||||
aceEditors.push aceEditor
|
aceEditors.push aceEditor
|
||||||
|
|
|
@ -21,6 +21,7 @@ module.exports = class SpellView extends CocoView
|
||||||
controlsEnabled: true
|
controlsEnabled: true
|
||||||
eventsSuppressed: true
|
eventsSuppressed: true
|
||||||
writable: true
|
writable: true
|
||||||
|
languagesThatUseWorkers: ['html']
|
||||||
|
|
||||||
keyBindings:
|
keyBindings:
|
||||||
'default': null
|
'default': null
|
||||||
|
@ -78,6 +79,7 @@ module.exports = class SpellView extends CocoView
|
||||||
@lockDefaultCode()
|
@lockDefaultCode()
|
||||||
_.defer @onAllLoaded # Needs to happen after the code generating this view is complete
|
_.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: ->
|
createACE: ->
|
||||||
# Test themes and settings here: http://ace.ajax.org/build/kitchen-sink.html
|
# Test themes and settings here: http://ace.ajax.org/build/kitchen-sink.html
|
||||||
aceConfig = me.get('aceConfig') ? {}
|
aceConfig = me.get('aceConfig') ? {}
|
||||||
|
@ -85,7 +87,7 @@ module.exports = class SpellView extends CocoView
|
||||||
@ace = ace.edit @$el.find('.ace')[0]
|
@ace = ace.edit @$el.find('.ace')[0]
|
||||||
@aceSession = @ace.getSession()
|
@aceSession = @ace.getSession()
|
||||||
@aceDoc = @aceSession.getDocument()
|
@aceDoc = @aceSession.getDocument()
|
||||||
@aceSession.setUseWorker false
|
@aceSession.setUseWorker @spell.language in @languagesThatUseWorkers
|
||||||
@aceSession.setMode utils.aceEditModes[@spell.language]
|
@aceSession.setMode utils.aceEditModes[@spell.language]
|
||||||
@aceSession.setWrapLimitRange null
|
@aceSession.setWrapLimitRange null
|
||||||
@aceSession.setUseWrapMode true
|
@aceSession.setUseWrapMode true
|
||||||
|
@ -789,10 +791,12 @@ module.exports = class SpellView extends CocoView
|
||||||
else
|
else
|
||||||
finishUpdatingAether(aether)
|
finishUpdatingAether(aether)
|
||||||
|
|
||||||
|
# Clear annotations and highlights generated by Aether, but not by the ACE worker
|
||||||
clearAetherDisplay: ->
|
clearAetherDisplay: ->
|
||||||
problem.destroy() for problem in @problems
|
problem.destroy() for problem in @problems
|
||||||
@problems = []
|
@problems = []
|
||||||
@aceSession.setAnnotations []
|
nonAetherAnnotations = _.reject @aceSession.getAnnotations(), (annotation) -> annotation.createdBy is 'aether'
|
||||||
|
@aceSession.setAnnotations nonAetherAnnotations
|
||||||
@highlightCurrentLine {} # This'll remove all highlights
|
@highlightCurrentLine {} # This'll remove all highlights
|
||||||
|
|
||||||
displayAether: (aether, isCast=false) ->
|
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'}
|
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.
|
problem.destroy() for problem in @problems # Just in case another problem was added since clearAetherDisplay() ran.
|
||||||
@problems = []
|
@problems = []
|
||||||
annotations = []
|
annotations = @aceSession.getAnnotations()
|
||||||
seenProblemKeys = {}
|
seenProblemKeys = {}
|
||||||
for aetherProblem, problemIndex in aether.getAllProblems()
|
for aetherProblem, problemIndex in aether.getAllProblems()
|
||||||
continue if key = aetherProblem.userInfo?.key and key of seenProblemKeys
|
continue if key = aetherProblem.userInfo?.key and key of seenProblemKeys
|
||||||
|
|
Loading…
Reference in a new issue