SmallSense__EditSupport.st
changeset 137 12232e62cf54
parent 135 f40d2ac07f38
child 139 bf1538a4e7ce
--- a/SmallSense__EditSupport.st	Tue Oct 22 12:14:07 2013 +0100
+++ b/SmallSense__EditSupport.st	Tue Oct 22 17:25:26 2013 +0100
@@ -86,13 +86,34 @@
 !
 
 insertElectric: text
-    self insertDo:[textView insertStringAtCursor: text].
+    self insertElectric:text advanceCursorBy:nil.
 
     "Created: / 22-10-2013 / 11:08:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+insertElectric:text advanceCursorBy:offsetOrNil 
+    "Insert given text. If offsetOrNil is not nil, then
+     move cursor by `offsetOrNil` character after **beggining** of
+     inserted text."
+    
+    self 
+        insertDo:[
+            offsetOrNil isNil ifTrue:[
+                textView insertStringAtCursor:text
+            ] ifFalse:[
+                | col |
+
+                col := textView cursorCol.
+                textView insertStringAtCursor:text.
+                textView cursorCol:col + offsetOrNil.
+            ].
+        ].
+
+    "Created: / 22-10-2013 / 11:56:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 insertElectricBlockOpenedBy: openText closedBy: closeText
-    | line col indent |
+    | lineNr indent lines autoIndent |
 
     textView completionSupport notNil ifTrue:[
         textView completionSupport 
@@ -102,15 +123,31 @@
 
     indent := self indentAtCursorLine.
 
-    textView undoableDo:[
-        textView insertStringAtCursor: (openText ? '') , Character cr , Character cr, (String new:indent withAll:Character space) , closeText , Character cr.
-        line := textView cursorLine - 1.
-        col := textView cursorCol  + 3.
-        textView cursorLine: line col: col.
+    autoIndent :=  textView autoIndent.
+    textView autoIndent: false. 
+    [
+        textView undoableDo:[
+            lineNr :=  textView cursorLine.
+            lines := Array 
+                        with: openText ? ''
+                        with: '' 
+                        with: ((String new:indent withAll:Character space) , closeText ).
+            textView 
+                insertLines: lines
+                withCR: false.
+            textView cursorLine: lineNr + 1 col: indent + 5. 
+
+    "/        textView insertStringAtCursor: (openText ? '') , Character cr , Character cr,  , closeText , Character cr.
+    "/        line := textView cursorLine - 1.
+    "/        col := textView cursorCol  + 3.
+    "/        textView cursorLine: line col: col.
+        ].
+    ] ensure:[
+        textView autoIndent: autoIndent 
     ].
 
     "Created: / 25-07-2013 / 10:41:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 22-10-2013 / 03:16:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 22-10-2013 / 17:10:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 insertElectricSnippet    
@@ -260,7 +297,7 @@
             [ token := scanner nextToken.token ~~ #EOF ] whileTrue:[
                 tokens 
                     nextPut: token; 
-                    nextPut: scanner tokenName; 
+                    nextPut: (scanner tokenName notNil ifTrue:[scanner tokenName] ifFalse:[ scanner tokenValue printString ]); 
                     nextPut: scanner tokenStartPosition;
                     nextPut: (tokenLastEndPosition := scanner tokenEndPosition).
             ].
@@ -274,7 +311,7 @@
     ].
 
     "Created: / 22-10-2013 / 00:31:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 22-10-2013 / 02:16:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 22-10-2013 / 12:01:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 scanLineAtCursor