Improvement in (Smalltalk)EditSupport.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Wed, 18 Sep 2013 00:58:49 +0100
changeset 89 8ff5fb2b27bf
parent 88 4db839c0a78f
child 90 4035038db277
Improvement in (Smalltalk)EditSupport. After some electric text is inserted, BackSpace will delete the inserted text instead of just last character.
SmallSense__EditSupport.st
SmallSense__SmalltalkEditSupport.st
--- a/SmallSense__EditSupport.st	Tue Sep 17 17:18:14 2013 +0100
+++ b/SmallSense__EditSupport.st	Wed Sep 18 00:58:49 2013 +0100
@@ -3,7 +3,7 @@
 "{ NameSpace: SmallSense }"
 
 Object subclass:#EditSupport
-	instanceVariableNames:'service textView'
+	instanceVariableNames:'service textView backspaceIsUndo'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'SmallSense-Core-Services'
@@ -42,12 +42,27 @@
 service:aSmallSenseService
     service := aSmallSenseService.
     textView := aSmallSenseService textView.
+    backspaceIsUndo := false.
 
-    "Modified: / 25-07-2013 / 00:11:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 17-09-2013 / 23:16:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !EditSupport methodsFor:'editing'!
 
+insertDo: aBlock
+    textView hasSelection ifTrue:[
+        textView undoableDo:[
+            textView deleteSelection
+        ].
+    ].
+    textView undoableDo: [
+         aBlock value.
+    ].
+    backspaceIsUndo := true.
+
+    "Created: / 17-09-2013 / 23:15:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 insertElectricBlockOpenedBy: openText closedBy: closeText
     | line col indent |
 
@@ -88,7 +103,7 @@
     ^false
 
     "Created: / 24-07-2013 / 23:31:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 04-08-2013 / 02:32:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 17-09-2013 / 23:18:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !EditSupport methodsFor:'private'!
--- a/SmallSense__SmalltalkEditSupport.st	Tue Sep 17 17:18:14 2013 +0100
+++ b/SmallSense__SmalltalkEditSupport.st	Wed Sep 18 00:58:49 2013 +0100
@@ -144,6 +144,16 @@
     lastTypedKey1 := lastTypedKey0.
     lastTypedKey0 := key.
 
+    key == #BackSpace ifTrue:[
+        backspaceIsUndo ifTrue:[
+             textView undo.
+             backspaceIsUndo := false.
+             ^ true.
+        ].
+    ].
+    backspaceIsUndo := false.
+
+
     key == $^ ifTrue:[
         ^ self keyPressReturnToken
     ].
@@ -154,7 +164,7 @@
     ^ super keyPress: key x:x y:y in: view
 
     "Created: / 07-03-2010 / 09:36:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 04-08-2013 / 02:31:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 17-09-2013 / 23:19:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 keyPressReturn
@@ -170,8 +180,11 @@
     i := line indexOfNonSeparator.
     (i ~~ 0 and:[ i < line size and:[(line at:i) == $" and:[(line at:i + 1) == $/]]]) ifTrue:[
         "/ OK, current line contains eol-comment
-        textView undoableDo:[
-            textView insertStringAtCursor: (Character cr asString , '"/ ')
+        self insertDo:[
+             textView insertCharAtCursor: Character cr. 
+        ].
+        self insertDo:[
+            textView insertStringAtCursor: '"/ '
         ].
         ^ true   
     ].
@@ -213,19 +226,20 @@
     ^ false.
 
     "Created: / 25-07-2013 / 00:02:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 16-09-2013 / 18:08:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 17-09-2013 / 23:21:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 keyPressReturnToken
     RBFormatter spaceAfterReturnToken ifTrue:[
-        textView undoableDo:[
-            textView  insertStringAtCursor:'^ ' 
+        self insertDo:[ 
+            textView insertStringAtCursor:'^ ' 
         ].
         ^ true
     ].
     ^ false
 
     "Created: / 24-07-2013 / 23:59:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 17-09-2013 / 23:20:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !SmalltalkEditSupport methodsFor:'private'!