From 364f40274dca83878a82a873dbf3dc2ec26fbcfa Mon Sep 17 00:00:00 2001
From: Rishi <rishiloyola98245@gmail.com>
Date: Mon, 22 Dec 2014 18:06:32 +0530
Subject: [PATCH 1/2] Update SpellView.coffee

hey i made changes. due to some error in downloading your data base i cannot test it. but check it . i think it will work .
---
 app/views/play/level/tome/SpellView.coffee | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/app/views/play/level/tome/SpellView.coffee b/app/views/play/level/tome/SpellView.coffee
index 2527c72a4..dc6613f59 100644
--- a/app/views/play/level/tome/SpellView.coffee
+++ b/app/views/play/level/tome/SpellView.coffee
@@ -215,7 +215,23 @@ module.exports = class SpellView extends CocoView
     addCommand
       name: 'disable-spaces'
       bindKey: 'Space'
-      exec: => @ace.execCommand 'insertstring', ' ' unless LevelOptions[@options.level.get('slug')]?.disableSpaces
+      exec: =>
+        cursor = @ace.getCursorPosition()
+          sentance = @aceDoc.getLine(cursor.row)
+          
+      commentStarts =
+      javascript: '//'
+      python: '#'
+      coffeescript: '#'
+      clojure: ';'
+      lua: '--'
+      io: '//'
+    commentStart = commentStarts[@spell.language] or '//'
+    if(flg=/#{commentStart}/.test sentance)
+    @ace.execCommand 'insertstring', ' '
+    else
+    @ace.execCommand 'insertstring', ' ' unless LevelOptions[@options.level.get('slug')]?.disableSpaces
+    
     addCommand
       name: 'throttle-backspaces'
       bindKey: 'Backspace'

From b116321deb3ea2d208f136c166e43147e30218b1 Mon Sep 17 00:00:00 2001
From: Nick Winter <livelily@gmail.com>
Date: Wed, 24 Dec 2014 12:37:25 -0800
Subject: [PATCH 2/2] Tested and cleaned up comment detection for space
 disablement sensitivity.

---
 app/views/play/level/tome/SpellView.coffee | 28 +++++++---------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/app/views/play/level/tome/SpellView.coffee b/app/views/play/level/tome/SpellView.coffee
index dc6613f59..9331b20f9 100644
--- a/app/views/play/level/tome/SpellView.coffee
+++ b/app/views/play/level/tome/SpellView.coffee
@@ -216,22 +216,10 @@ module.exports = class SpellView extends CocoView
       name: 'disable-spaces'
       bindKey: 'Space'
       exec: =>
-        cursor = @ace.getCursorPosition()
-          sentance = @aceDoc.getLine(cursor.row)
-          
-      commentStarts =
-      javascript: '//'
-      python: '#'
-      coffeescript: '#'
-      clojure: ';'
-      lua: '--'
-      io: '//'
-    commentStart = commentStarts[@spell.language] or '//'
-    if(flg=/#{commentStart}/.test sentance)
-    @ace.execCommand 'insertstring', ' '
-    else
-    @ace.execCommand 'insertstring', ' ' unless LevelOptions[@options.level.get('slug')]?.disableSpaces
-    
+        return @ace.execCommand 'insertstring', ' ' unless LevelOptions[@options.level.get('slug')]?.disableSpaces
+        line = @aceDoc.getLine @ace.getCursorPosition().row
+        return @ace.execCommand 'insertstring', ' ' if @singleLineCommentRegex().test line
+
     addCommand
       name: 'throttle-backspaces'
       bindKey: 'Backspace'
@@ -797,7 +785,9 @@ module.exports = class SpellView extends CocoView
         @recompile()
 
   singleLineCommentRegex: ->
-    return @_singleLineCommentRegex if @_singleLineCommentRegex
+    if @_singleLineCommentRegex
+      @_singleLineCommentRegex.lastIndex = 0
+      return @_singleLineCommentRegex
     commentStarts =
       javascript: '//'
       python: '#'
@@ -806,8 +796,8 @@ module.exports = class SpellView extends CocoView
       lua: '--'
       io: '//'
     commentStart = commentStarts[@spell.language] or '//'
-    @_singleLineCommentRegexp ?= new RegExp "[ \t]*#{commentStart}[^\"'\n]*", 'g'
-    @_singleLineCommentRegexp
+    @_singleLineCommentRegex = new RegExp "[ \t]*#{commentStart}[^\"'\n]*", 'g'
+    @_singleLineCommentRegex
 
   preload: ->
     # Send this code over to the God for preloading, but don't change the cast state.