SmallSense__EditSupport.st
changeset 159 289c7ef539af
parent 157 c71d2e62ece2
child 164 3c5e63dbdb3b
--- a/SmallSense__EditSupport.st	Wed Jan 22 12:52:34 2014 +0000
+++ b/SmallSense__EditSupport.st	Wed Jan 22 21:54:51 2014 +0000
@@ -72,40 +72,51 @@
 
 !EditSupport methodsFor:'editing'!
 
-insertDo: aBlock
+electricDeleteCharacterAtCol: col 
+    textView deleteCharAtLine: textView cursorLine col: col
+
+    "Created: / 22-01-2014 / 21:17:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+electricDeleteCharacterAtLine:line col: col 
+    textView deleteCharAtLine: line col: col
+
+    "Created: / 22-01-2014 / 21:16:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+electricDo:aBlock 
     textView completionSupport notNil ifTrue:[
-        textView completionSupport 
+        (textView completionSupport)
             stopCompletionProcess;
             closeCompletionView.
-    ].  
+    ].
     textView hasSelection ifTrue:[
-        textView undoableDo:[
-            textView deleteSelection
-        ].
+        textView undoableDo:[ textView deleteSelection ].
     ].
-    textView undoableDo: [
-         aBlock value.
-    ].
+    textView undoableDo:[ aBlock value. ].
     backspaceIsUndo := true.
 
     "Created: / 17-09-2013 / 23:15:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 22-10-2013 / 03:15:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-insertElectric: text
-    self insertElectric:text advanceCursorBy:nil.
+electricInsert:text 
+    self electricInsert:text advanceCursorBy:nil.
 
     "Created: / 22-10-2013 / 11:08:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-insertElectric:stringOrLines advanceCursorBy:offsetOrNil 
-    ^ self insertElectric:stringOrLines advanceCursorBy:offsetOrNil ignoreKeystrokes: nil
+electricInsert:stringOrLines advanceCursorBy:offsetOrNil 
+    ^ self 
+            electricInsert:stringOrLines
+            advanceCursorBy:offsetOrNil
+            ignoreKeystrokes:nil
 
     "Created: / 22-10-2013 / 11:56:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 19-01-2014 / 20:29:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-insertElectric:stringOrLines advanceCursorBy:offsetOrNil ignoreKeystrokes: ignoreKeystrokeSequence 
+electricInsert:stringOrLines advanceCursorBy:offsetOrNil ignoreKeystrokes:ignoreKeystrokeSequence 
     "Insert given stringOrLines. If offsetOrNil is not nil, then
      move cursor by `offsetOrNil` after the **begining** of
      inserted text. If `ignoreKeystrokeSequence` is not nil and not empty, then if
@@ -121,38 +132,39 @@
             line and by y characters after beggining of the inserted text
             (if x == 0) or at set at column y (if x ~~ 0)
      `ignoreKeystrokeSequence` a sequenceable collection of keys (in a form
-            as passed to #keyPress:x:y: method.
-    "
-
-    | lineOffset colOffset newCursorCol newCursorLine advanceCursor |
+            as passed to #keyPress:x:y: method."
+    
+    | lineOffset  colOffset  newCursorCol  newCursorLine  advanceCursor |
 
     advanceCursor := false.
     offsetOrNil notNil ifTrue:[
-        lineOffset := offsetOrNil isPoint ifTrue:[offsetOrNil x] ifFalse:[0].
-        colOffset := offsetOrNil isPoint ifTrue:[offsetOrNil y] ifFalse:[offsetOrNil].
-
+        lineOffset := offsetOrNil isPoint ifTrue:[
+                offsetOrNil x
+            ] ifFalse:[ 0 ].
+        colOffset := offsetOrNil isPoint ifTrue:[
+                offsetOrNil y
+            ] ifFalse:[
+                offsetOrNil
+            ].
         newCursorLine := textView cursorLine + lineOffset.
-        newCursorCol := (lineOffset == 0 ifTrue:[textView cursorCol] ifFalse:[0]) + colOffset.
-
+        newCursorCol := (lineOffset == 0 
+                ifTrue:[ textView cursorCol ]
+                ifFalse:[ 0 ]) + colOffset.
         advanceCursor := true.
     ].
-
-    
     self 
-        insertDo:[
+        electricDo:[
             stringOrLines isString ifTrue:[
-                "/ Simple string...    
+                "/ Simple strin
                 textView insertStringAtCursor:stringOrLines.
             ] ifFalse:[
-                "/ Couple lines...
-                textView 
-                    insertLines: stringOrLines
-                    withCR: false.   
+                "/ C
+                textView insertLines:stringOrLines withCR:false.
             ].
             advanceCursor ifTrue:[
-                (textView cursorLine ~~ newCursorLine or:[textView cursorCol ~~ newCursorCol]) ifTrue:[
-                    textView cursorLine: newCursorLine col: newCursorCol.
-                ].
+                (textView cursorLine ~~ newCursorLine 
+                    or:[ textView cursorCol ~~ newCursorCol ]) 
+                        ifTrue:[ textView cursorLine:newCursorLine col:newCursorCol. ].
             ].
         ].
     ignoreKeystrokeSequence notEmptyOrNil ifTrue:[
@@ -162,49 +174,45 @@
 
     "Created: / 19-01-2014 / 20:29:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 20-01-2014 / 09:24:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 22-01-2014 / 21:13:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-insertElectric: text ignoreKeystrokes: ignore    
-    self insertElectric:text advanceCursorBy:nil ignoreKeystrokes: ignore
+electricInsert:text ignoreKeystrokes:ignore 
+    self 
+        electricInsert:text
+        advanceCursorBy:nil
+        ignoreKeystrokes:ignore
 
     "Created: / 21-01-2014 / 23:29:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-insertElectricBlockOpenedBy: openText closedBy: closeText
-    | indent lines autoIndent |
+electricInsertBlockOpenedBy:openText closedBy:closeText 
+    | indent  lines  autoIndent |
 
     textView completionSupport notNil ifTrue:[
-        textView completionSupport 
+        (textView completionSupport)
             stopCompletionProcess;
             closeCompletionView.
-    ].   
-
+    ].
     indent := self indentAtCursorLine.
-
-    autoIndent :=  textView autoIndent.
-    textView autoIndent: false. 
+    autoIndent := textView autoIndent.
+    textView autoIndent:false.
     [
-        textView undoableDo:[
-            lines := Array 
-                        with: openText ? ''
-                        with: '' 
-                        with: ((String new:indent withAll:Character space) , closeText ).
-            self insertElectric: lines advanceCursorBy:  1 @ (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 
-    ].
+        textView 
+            undoableDo:[
+                lines := Array 
+                        with:openText ? ''
+                        with:''
+                        with:((String new:indent withAll:Character space) , closeText).
+                self electricInsert:lines advanceCursorBy:1 @ (indent + 5)
+            ].
+    ] ensure:[ textView autoIndent:autoIndent ].
 
     "Created: / 25-07-2013 / 10:41:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 19-11-2013 / 12:29:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 22-01-2014 / 21:20:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-insertElectricSnippet    
+electricInsertSnippet
     ^ false
 
     "Created: / 22-10-2013 / 01:54:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -229,7 +237,7 @@
     ].
 
     key == Character space ifTrue:[
-        ^ self insertElectricSnippet
+        ^ self electricInsertSnippet
     ].
 
     ^false
@@ -262,7 +270,7 @@
 !
 
 keyPressSpace
-    ^ self insertElectricSnippet
+    ^ self electricInsertSnippet
 
     "Created: / 22-10-2013 / 01:43:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !