--- a/SmallSense__EditSupport.st Mon Nov 04 13:48:49 2013 -0300
+++ b/SmallSense__EditSupport.st Tue Nov 19 12:48:26 2013 +0000
@@ -91,29 +91,59 @@
"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."
+insertElectric:stringOrLines advanceCursorBy:offsetOrNil
+ "Insert given stringOrLines. If offsetOrNil is not nil, then
+ move cursor by `offsetOrNil` character after **begining** of
+ inserted text.
+
+ `stringOrLines` could be either string or collection of strings (lines)
+ `offsetOrNil` could be either integer (cursor is then advanced by
+ offsetOrNil characters after **begining** of inserted text)
+ or point (x,y, cursor is then advanced by x lines after current
+ line and by y characters after beggining of the inserted text
+ (if x == 0) or at set at column y (if x ~~ 0)
+ "
+
+ | 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].
+
+ newCursorLine := textView cursorLine + lineOffset.
+ newCursorCol := (lineOffset == 0 ifTrue:[textView cursorCol] ifFalse:[0]) + colOffset.
+
+ advanceCursor := true.
+ ].
+
self
insertDo:[
- offsetOrNil isNil ifTrue:[
- textView insertStringAtCursor:text
+ stringOrLines isString ifTrue:[
+ "/ Simple string...
+ textView insertStringAtCursor:stringOrLines.
] ifFalse:[
- | col |
+ "/ Couple lines...
+ textView
+ insertLines: stringOrLines
+ withCR: false.
+ ].
+ advanceCursor ifTrue:[
+ (textView cursorLine ~~ newCursorLine or:[textView cursorCol ~~ newCursorCol]) ifTrue:[
+ textView cursorLine: newCursorLine col: newCursorCol.
+ ].
+ ].
- col := textView cursorCol.
- textView insertStringAtCursor:text.
- textView cursorCol:col + offsetOrNil.
- ].
+
].
"Created: / 22-10-2013 / 11:56:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 19-11-2013 / 12:30:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
insertElectricBlockOpenedBy: openText closedBy: closeText
- | lineNr indent lines autoIndent |
+ | indent lines autoIndent |
textView completionSupport notNil ifTrue:[
textView completionSupport
@@ -127,15 +157,11 @@
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.
+ self insertElectric: lines advanceCursorBy: 1 @ (indent + 5)
"/ textView insertStringAtCursor: (openText ? '') , Character cr , Character cr, , closeText , Character cr.
"/ line := textView cursorLine - 1.
@@ -147,7 +173,7 @@
].
"Created: / 25-07-2013 / 10:41:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 22-10-2013 / 17:10:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 19-11-2013 / 12:29:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
insertElectricSnippet