EditTextView.st
changeset 133 e58c7c979f33
parent 132 596439fe4efd
child 155 d6f3836d2b51
--- a/EditTextView.st	Mon Jul 03 04:34:22 1995 +0200
+++ b/EditTextView.st	Sun Jul 23 05:03:13 1995 +0200
@@ -28,7 +28,7 @@
 COPYRIGHT (c) 1989 by Claus Gittinger
 	    All Rights Reserved
 
-$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.31 1995-07-03 02:32:38 claus Exp $
+$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.32 1995-07-23 03:01:20 claus Exp $
 '!
 
 !EditTextView class methodsFor:'documentation'!
@@ -49,7 +49,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.31 1995-07-03 02:32:38 claus Exp $
+$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.32 1995-07-23 03:01:20 claus Exp $
 "
 !
 
@@ -215,7 +215,7 @@
 	self hideCursor
     ].
     (button == #paste) ifTrue:[
-	self paste.
+	self pasteOrReplace.
 	^ self
     ].
     super buttonPress:button x:x y:y
@@ -314,14 +314,14 @@
 	    fKeyMacros := Smalltalk at:#FunctionKeySequences.
 	    fKeyMacros notNil ifTrue:[
 		(fKeyMacros includesKey:key) ifTrue:[
-		    self paste:(fKeyMacros at:key) asStringCollection.
+		    self pasteOrReplace:(fKeyMacros at:key) asStringCollection.
 		    ^ self
 		]
 	    ]
 	]
     ].
 
-    ((key == #Paste) or:[key == #Insert]) ifTrue:[self paste. ^self].
+    ((key == #Paste) or:[key == #Insert]) ifTrue:[self pasteOrReplace. ^self].
     (key == #Cut) ifTrue:[self cut. ^self].
     (key == #Again) ifTrue:[self again. ^self].
 
@@ -679,7 +679,7 @@
      of cursor should be drawn.
      Currently, supported are: #block, #frame, #ibeam, #caret and #solidCaret"
 
-    |x y w char y2 x1 x2|
+    |x y w char y2 x1 x2 oldPaint|
 
     self hasSelection ifTrue:[
 	"
@@ -698,42 +698,42 @@
     x := (self xOfCol:cursorCol inVisibleLine:cursorVisibleLine) - leftOffset.
     y := self yOfVisibleLine:cursorVisibleLine.
 
+    oldPaint := paint. "/ do not clobber GC
     cursorType == #frame ifTrue:[
 	super redrawVisibleLine:cursorVisibleLine col:cursorCol.
 
 	char := self characterUnderCursor asString.
 	self paint:bgColor.
-	self displayRectangleX:x y:y width:(font widthOf:char)
-				    height:fontHeight.
-	^ self
-    ].
-    self paint:bgColor.
-    cursorType == #ibeam ifTrue:[
-	x1 := x - 1.
-	y2 := y + fontHeight - 1.
-	self displayLineFromX:x1 y:y toX:x1 y:y2. 
-	self displayLineFromX:x y:y toX:x y:y2. 
-	^ self
+	self displayRectangleX:x y:y 
+			 width:(font widthOf:char) height:fontHeight.
+    ] ifFalse:[
+	self paint:bgColor.
+	cursorType == #ibeam ifTrue:[
+	    x1 := x - 1.
+	    y2 := y + fontHeight - 1.
+	    self displayLineFromX:x1 y:y toX:x1 y:y2. 
+	    self displayLineFromX:x y:y toX:x y:y2. 
+	    ^ self
+	] ifFalse:[
+	    w := fontWidth // 2.
+	    y := y + fontHeight - 3.
+	    y2 := y + w.
+	    x1 := x - w.
+	    x2 := x + w.
+	    cursorType == #caret ifTrue:[
+		self lineWidth:2.
+		self displayLineFromX:x1 y:y2 toX:x y:y. 
+		self displayLineFromX:x y:y toX:x2 y:y2. 
+	    ] ifFalse:[
+		"anything else: solidCaret"
+
+		self fillPolygon:(Array with:(x1 @ y2)
+					with:(x @ y)
+					with:(x2 @ y2))
+	    ]
+	]
     ].
-
-    w := fontWidth // 2.
-    y := y + fontHeight - 3.
-    y2 := y + w.
-    x1 := x - w.
-    x2 := x + w.
-    cursorType == #caret ifTrue:[
-	self lineWidth:2.
-	self displayLineFromX:x1 y:y2 toX:x y:y. 
-	self displayLineFromX:x y:y toX:x2 y:y2. 
-    ] ifFalse:[
-	"anything else: solidCaret"
-
-"/        cursorType == #solidCaret ifTrue:[
-	    self fillPolygon:(Array with:(x1 @ y2)
-				    with:(x @ y)
-				    with:(x2 @ y2))
-"/        ]
-    ].
+    self paint:oldPaint.
 !
 
 cursorReturn
@@ -1313,6 +1313,26 @@
     contentsWasSaved := false
 ! !
 
+!EditTextView methodsFor:'ST-80 compatibility editing'!
+
+insertAndSelect:aString at:aCharacterPosition
+    "insert a selected string at aCharacterPosition."
+
+    |line col|
+
+    line := self lineOfCharacterPosition:aCharacterPosition.
+    col := aCharacterPosition - (self characterPositionOfLine:line col:1) + 1.
+    self insertString:aString atLine:line col:col.
+    self selectFromLine:line col:col toLine:line col:col + aString size - 1
+    "
+     |v|
+
+     v := EditTextView new openAndWait.
+     v contents:'1234567890\1234567890\1234567890\' withCRs.
+     v insertAndSelect:'<- hello there' at:5.
+    "
+! !
+
 !EditTextView methodsFor:'editing'!
 
 insertStringAtCursor:aString
@@ -2640,7 +2660,19 @@
     lastReplacement := someText
 !
 
-paste
+pasteOrReplace:someText
+    "paste copybuffer; if there is a selection, replace it.
+     otherwise paste at cursor position. Replace is not done
+     for originating by a paste, to allow multiple
+     paste."
+
+    ((self hasSelection == true) and:[typeOfSelection ~~ #paste]) ifTrue:[
+	^ self replace:someText
+    ].
+    self paste:someText.
+!
+
+pasteOrReplace
     "paste copybuffer; if there is a selection, replace it.
      otherwise paste at cursor position. Replace is not done
      for originating by a paste, to allow multiple
@@ -2648,10 +2680,18 @@
 
     |sel|
 
-    ((self hasSelection == true) and:[typeOfSelection ~~ #paste]) ifTrue:[
-	^ self replace
-    ].
     sel := self getTextSelection.
+    self pasteOrReplace:sel.
+!
+
+paste
+    "paste copybuffer; if there is a selection, unselect first.
+     Then paste at cursor position."
+
+    |sel|
+
+    sel := self getTextSelection.
+    self unselect.  
     sel notNil ifTrue:[
 	self paste:sel.
     ]