Fixed Comment Out My Code for infinite loops for #1788

Fixed the issue for incorrect comments by correcting the syntax per language
This commit is contained in:
divyanshu013 2015-02-04 21:48:01 +05:30
parent 031a32ce44
commit 929c89d2ac
2 changed files with 14 additions and 9 deletions

View file

@ -783,17 +783,14 @@ module.exports = class SpellView extends CocoView
if @_singleLineCommentRegex
@_singleLineCommentRegex.lastIndex = 0
return @_singleLineCommentRegex
commentStarts =
javascript: '//'
python: '#'
coffeescript: '#'
clojure: ';'
lua: '--'
io: '//'
commentStart = commentStarts[@spell.language] or '//'
@_singleLineCommentRegex = new RegExp "[ \t]*#{commentStart}[^\"'\n]*", 'g'
@_singleLineCommentRegex
commentOutMyCode: ->
prefix = if @spell.language is 'javascript' then 'return; ' else 'return '
comment = prefix + commentStarts[@spell.language]
preload: ->
# Send this code over to the God for preloading, but don't change the cast state.
oldSource = @spell.source
@ -1093,3 +1090,11 @@ module.exports = class SpellView extends CocoView
@debugView?.destroy()
$(window).off 'resize', @onWindowResize
super()
commentStarts =
javascript: '//'
python: '#'
coffeescript: '#'
clojure: ';'
lua: '--'
io: '//'

View file

@ -80,7 +80,7 @@ module.exports = class TomeView extends CocoView
onCommentMyCode: (e) ->
for spellKey, spell of @spells when spell.canWrite()
console.log 'Commenting out', spellKey
commentedSource = 'return; // Commented out to stop infinite loop.\n' + spell.getSource()
commentedSource = spell.view.commentOutMyCode() + 'Commented out to stop infinite loop.\n' + spell.getSource()
spell.view.updateACEText commentedSource
spell.view.recompile false
@cast()