class: TextView
authorClaus Gittinger <cg@exept.de>
Fri, 24 Jul 2015 20:09:16 +0200
changeset 5378 d64277a079c1
parent 5377 b1076568773e
child 5379 28ea16ace5ef
class: TextView added: #withSelectionForeground:background:do:
TextView.st
--- a/TextView.st	Fri Jul 24 17:41:41 2015 +0200
+++ b/TextView.st	Fri Jul 24 20:09:16 2015 +0200
@@ -4939,6 +4939,37 @@
     ^ self
 
     "Modified: 29.4.1996 / 12:32:08 / cg"
+!
+
+withSelectionForeground:hilightFg background:hilightBg do:aBlock
+    "evaluate aBlock while the selection is shown highlighted with colors passed as args."
+
+    |oldFg oldBg|
+
+    "
+     change color of selection & hide cursor
+    "
+    oldFg := selectionFgColor.
+    oldBg := selectionBgColor.
+    selectionBgColor := hilightBg.
+    selectionFgColor := hilightFg.
+
+    expandingTop := true.       "/ hack to make the top of the selection visible
+    self makeSelectionVisible.
+    selectionStartLine notNil ifTrue:[
+        selectionEndLine notNil ifTrue:[
+            self redrawFromLine:selectionStartLine to:selectionEndLine.
+        ].
+    ].
+    self flush.
+
+    aBlock ensure:[
+        "
+         undo selection color change and show cursor again
+        "
+        selectionFgColor := oldFg.
+        selectionBgColor := oldBg.
+    ].
 ! !
 
 !TextView methodsFor:'testing'!