--- a/SmallSense__SmalltalkEditSupport.st Fri May 02 12:29:52 2014 +0100
+++ b/SmallSense__SmalltalkEditSupport.st Mon May 05 09:23:22 2014 +0100
@@ -10,6 +10,65 @@
!
+!SmalltalkEditSupport class methodsFor:'utilities'!
+
+indent: text by: level
+ ^ String streamContents:[ :out |
+ | in |
+
+ in := text readStream.
+ [ in atEnd ] whileFalse:[
+ in peek == Character cr ifTrue:[
+ out nextPut: in next.
+ out next: level put: Character space.
+ ] ifFalse:[
+ out nextPut: in next.
+ ].
+ ].
+ ]
+
+ "Created: / 04-05-2014 / 23:29:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+undent: text
+ | lines indent tabwidth |
+
+ lines := text asStringCollection.
+ tabwidth := (ListView userDefaultTabPositions = ListView tab4Positions) ifTrue:[ 4 ] ifFalse: [ 8 ].
+ 1 to: lines size do:[:lineNo |
+ | line i |
+
+ line := lines at: lineNo.
+ i := line indexOfNonSeparator.
+ indent isNil ifTrue:[
+ (i ~~ 0) ifTrue:[
+ indent := ((i - 1) // tabwidth) * tabwidth.
+ indent == 0 ifTrue:[
+ lineNo == 1 ifTrue:[
+ indent := nil.
+ ] ifFalse:[
+ ^ text.
+ ].
+ ].
+ ].
+ ].
+ indent notNil ifTrue:[
+ i > indent ifTrue:[
+ lines at: lineNo put: (line copyFrom: indent + 1).
+ ] ifFalse:[
+ ^ text.
+ ].
+ ].
+ ].
+ ^ (text last == Character cr) ifTrue:[
+ lines asString.
+ ] ifFalse:[
+ lines asStringWithoutFinalCR
+ ].
+
+ "Created: / 04-05-2014 / 23:09:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!SmalltalkEditSupport methodsFor:'accessing'!
language
@@ -192,6 +251,10 @@
].
backspaceIsUndo := false.
+ key == #Paste ifTrue:[
+ ^ self keyPressPaste.
+ ].
+
key == $^ ifTrue:[
^ self keyPressReturnToken
@@ -219,7 +282,7 @@
^ false.
"Created: / 07-03-2010 / 09:36:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 29-01-2014 / 10:31:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 03-05-2014 / 01:08:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
keyPressDoubleColon
@@ -280,6 +343,31 @@
"Modified: / 29-01-2014 / 10:30:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+keyPressPaste
+ | textSelected textPasted currentLineNo currentLine |
+
+ textView checkModificationsAllowed ifTrue:[
+ textSelected := textPasted := textView getTextSelectionOrTextSelectionFromHistory.
+ currentLineNo := textView currentLine.
+ ((currentLineNo > textView list size)
+ or:[ (currentLine := textView list at: currentLineNo) isNil
+ or:[ currentLine indexOfNonSeparator == 0 ]]) ifTrue:[
+ textPasted := self class undent: textPasted.
+ textPasted := self class indent: textPasted by: textView cursorCol - 1.
+ ].
+ textView undoablePasteOrReplace: textPasted info: nil.
+ ].
+
+
+
+
+
+ ^ true
+
+ "Created: / 03-05-2014 / 01:08:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (format): / 04-05-2014 / 23:48:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
keyPressReturn
| line tokens c i t currentLineIndent closingBracketIndex |