Electric editing for Smalltalk: autoinsert space fter assignment.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 22 Oct 2013 11:11:14 +0100
changeset 135 f40d2ac07f38
parent 134 e34ee6ceb7c8
child 136 a1c1b160f2ca
Electric editing for Smalltalk: autoinsert space fter assignment.
SmallSense__EditSupport.st
SmallSense__SmalltalkEditSupport.st
--- a/SmallSense__EditSupport.st	Tue Oct 22 03:29:26 2013 +0100
+++ b/SmallSense__EditSupport.st	Tue Oct 22 11:11:14 2013 +0100
@@ -85,6 +85,12 @@
     "Modified: / 22-10-2013 / 03:15:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+insertElectric: text
+    self insertDo:[textView insertStringAtCursor: text].
+
+    "Created: / 22-10-2013 / 11:08:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 insertElectricBlockOpenedBy: openText closedBy: closeText
     | line col indent |
 
--- a/SmallSense__SmalltalkEditSupport.st	Tue Oct 22 03:29:26 2013 +0100
+++ b/SmallSense__SmalltalkEditSupport.st	Tue Oct 22 11:11:14 2013 +0100
@@ -178,18 +178,22 @@
     key == $^ ifTrue:[
         ^ self keyPressReturnToken
     ].
-    key == #Return ifTrue:[
+    key == #Return ifTrue: [
         ^ self keyPressReturn
     ].
 
-    key == $: ifTrue:[
+    key == $: ifTrue: [
         ^ self keyPressDoubleColon.
     ].
 
+    key == $= ifTrue: [
+        ^ self keyPressEqual
+    ].
+
     ^ super keyPress: key x:x y:y in: view
 
     "Created: / 07-03-2010 / 09:36:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 22-10-2013 / 03:08:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 22-10-2013 / 11:09:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 keyPressDoubleColon
@@ -198,6 +202,23 @@
     "Created: / 22-10-2013 / 03:08:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+keyPressEqual
+    | line |
+
+    line := textView listAt:textView cursorLine.
+    line isNil ifTrue:[ ^ false ].
+    line := line string.
+    line size > textView cursorCol ifTrue: [ ^ false ].
+    line size < (textView cursorCol - 1) ifTrue: [ ^ false ].
+    (line at: textView cursorCol - 1) == $: ifTrue: [
+        self insertElectric:'= '.  
+        ^ true
+    ].
+    ^ false
+
+    "Created: / 22-10-2013 / 11:01:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 keyPressReturn
     | line tokens i t |