SmallSense__SmalltalkEditSupport.st
changeset 160 89a001a355b4
parent 159 289c7ef539af
child 176 df6d3225d1e4
--- a/SmallSense__SmalltalkEditSupport.st	Wed Jan 22 21:54:51 2014 +0000
+++ b/SmallSense__SmalltalkEditSupport.st	Wed Jan 29 10:41:11 2014 +0000
@@ -213,14 +213,13 @@
     ].
 
     key == $[ ifTrue:[
-        self keyPressOpenBracket.
-        ^ true.
+        ^ self keyPressOpenBracket.
     ].
 
     ^ false.
 
     "Created: / 07-03-2010 / 09:36:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 22-01-2014 / 21:35:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 29-01-2014 / 10:31:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 keyPressDoubleColon
@@ -246,7 +245,22 @@
     "Created: / 22-10-2013 / 11:01:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-keyPressOpenBracket    
+keyPressOpenBracket
+    "Opening `[` has been pressed. Complete closing bracket and position
+     cursor in between them, but only of there's no other text on current line"
+
+    | line |
+
+    line := textView listAt: textView cursorLine.
+    line notNil ifTrue:[ 
+        line := line string.  
+        line size > textView cursorCol ifTrue: [
+            line size downTo: textView cursorCol - 1 do:[:i |
+                (line at:i) == Character space ifFalse:[ ^ false ].
+            ]
+        ].
+    ].
+
     RBFormatter spaceAfterBlockStart ifTrue:[
         RBFormatter spaceBeforeBlockEnd ifTrue:[
             self electricInsert:'[  ]' advanceCursorBy: 2.
@@ -260,8 +274,10 @@
             self electricInsert:'[]' advanceCursorBy: 1.
         ].
     ].
+    ^ true.
 
     "Created: / 22-01-2014 / 21:35:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 29-01-2014 / 10:30:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 keyPressReturn