class: TextView
authorClaus Gittinger <cg@exept.de>
Fri, 08 Mar 2013 10:46:39 +0100
changeset 4528 527c90bfd2cc
parent 4527 4445373fd930
child 4529 ec75c190f714
class: TextView changed: #redrawVisibleLine: #redrawVisibleLine:col: #redrawVisibleLine:from:to: be tolerant to invalid selectionStartCol/endCol should not happen, but some subclass or an aborted edit operation may leave nil there occasionally, which leads to endless exceptions when doing redraws.
TextView.st
--- a/TextView.st	Wed Mar 06 10:39:31 2013 +0100
+++ b/TextView.st	Fri Mar 08 10:46:39 2013 +0100
@@ -2921,51 +2921,52 @@
 
     |line|
 
-    (selectionStartLine notNil and:[selectionEndLine notNil]) ifTrue:[
-	line := self visibleLineToAbsoluteLine:visLineNr.
-	(line between:selectionStartLine and:selectionEndLine) ifTrue:[
-	    (line == selectionStartLine) ifTrue:[
-		(line == selectionEndLine) ifTrue:[
-		    "it's part-of-single-line selection"
-		    self clearMarginOfVisibleLine:visLineNr with:bgColor.
-		    (selectionStartCol > 1) ifTrue:[
-			super redrawVisibleLine:visLineNr from:1 to:(selectionStartCol - 1)
-		    ].
-		    self drawVisibleLineSelected:visLineNr from:selectionStartCol to:selectionEndCol.
-		    super redrawVisibleLine:visLineNr from:(selectionEndCol + 1).
-		    ^ self
-		].
-
-		"it's the first line of a multi-line selection"
-		(selectionStartCol ~~ 1) ifTrue:[
-		    self clearMarginOfVisibleLine:visLineNr with:bgColor.
-		    super redrawVisibleLine:visLineNr from:1 to:(selectionStartCol - 1)
-		] ifFalse:[
-		    viewOrigin x == 0 ifTrue:[
-			self clearMarginOfVisibleLine:visLineNr with:self currentSelectionBgColor.
-		    ]
-		].
-		self drawVisibleLineSelected:visLineNr from:selectionStartCol.
-		^ self
-	    ].
-
-	    (line == selectionEndLine) ifTrue:[
-		"it's the last line of a multi-line selection"
-		(selectionEndCol == 0) ifTrue:[
-		    ^ super redrawVisibleLine:visLineNr
-		].
-
-		self clearMarginOfVisibleLine:visLineNr with:self currentSelectionBgColor.
-		self drawVisibleLineSelected:visLineNr from:1 to:selectionEndCol.
-		super redrawVisibleLine:visLineNr from:(selectionEndCol + 1).
-		^ self
-	    ].
-
-	    "it's a full line in a multi-line selection"
-	    self clearMarginOfVisibleLine:visLineNr with:self currentSelectionBgColor.
-	    self drawVisibleLineSelected:visLineNr.
-	    ^ self
-	]
+    (selectionStartLine notNil and:[selectionEndLine notNil
+    and:[ selectionStartCol notNil and:[selectionEndCol notNil]]]) ifTrue:[
+        line := self visibleLineToAbsoluteLine:visLineNr.
+        (line between:selectionStartLine and:selectionEndLine) ifTrue:[
+            (line == selectionStartLine) ifTrue:[
+                (line == selectionEndLine) ifTrue:[
+                    "it's part-of-single-line selection"
+                    self clearMarginOfVisibleLine:visLineNr with:bgColor.
+                    (selectionStartCol > 1) ifTrue:[
+                        super redrawVisibleLine:visLineNr from:1 to:(selectionStartCol - 1)
+                    ].
+                    self drawVisibleLineSelected:visLineNr from:selectionStartCol to:selectionEndCol.
+                    super redrawVisibleLine:visLineNr from:(selectionEndCol + 1).
+                    ^ self
+                ].
+
+                "it's the first line of a multi-line selection"
+                (selectionStartCol ~~ 1) ifTrue:[
+                    self clearMarginOfVisibleLine:visLineNr with:bgColor.
+                    super redrawVisibleLine:visLineNr from:1 to:(selectionStartCol - 1)
+                ] ifFalse:[
+                    viewOrigin x == 0 ifTrue:[
+                        self clearMarginOfVisibleLine:visLineNr with:self currentSelectionBgColor.
+                    ]
+                ].
+                self drawVisibleLineSelected:visLineNr from:selectionStartCol.
+                ^ self
+            ].
+
+            (line == selectionEndLine) ifTrue:[
+                "it's the last line of a multi-line selection"
+                (selectionEndCol == 0) ifTrue:[
+                    ^ super redrawVisibleLine:visLineNr
+                ].
+
+                self clearMarginOfVisibleLine:visLineNr with:self currentSelectionBgColor.
+                self drawVisibleLineSelected:visLineNr from:1 to:selectionEndCol.
+                super redrawVisibleLine:visLineNr from:(selectionEndCol + 1).
+                ^ self
+            ].
+
+            "it's a full line in a multi-line selection"
+            self clearMarginOfVisibleLine:visLineNr with:self currentSelectionBgColor.
+            self drawVisibleLineSelected:visLineNr.
+            ^ self
+        ]
     ].
     super redrawVisibleLine:visLineNr
 
@@ -2980,19 +2981,20 @@
     "/
     "/ care for selection
     "/
-    (selectionStartLine notNil and:[selectionEndLine notNil]) ifTrue:[
-	line := self visibleLineToAbsoluteLine:visLine.
-	(line between:selectionStartLine and:selectionEndLine) ifTrue:[
-	    ((line == selectionStartLine)
-	    and: [col < selectionStartCol]) ifFalse:[
-		((line == selectionEndLine)
-		and: [col > selectionEndCol]) ifFalse:[
-		    "its in the selection"
-		    self drawVisibleLineSelected:visLine col:col.
-		    ^ self.
-		]
-	    ]
-	]
+    (selectionStartLine notNil and:[selectionEndLine notNil
+    and:[ selectionStartCol notNil and:[selectionEndCol notNil]]]) ifTrue:[
+        line := self visibleLineToAbsoluteLine:visLine.
+        (line between:selectionStartLine and:selectionEndLine) ifTrue:[
+            ((line == selectionStartLine)
+            and: [col < selectionStartCol]) ifFalse:[
+                ((line == selectionEndLine)
+                and: [col > selectionEndCol]) ifFalse:[
+                    "its in the selection"
+                    self drawVisibleLineSelected:visLine col:col.
+                    ^ self.
+                ]
+            ]
+        ]
     ].
     self drawVisibleLine:visLine col:col with:fgColor and:bgColor
 
@@ -3037,76 +3039,77 @@
 
     allIn := false.
     allOut := false.
-    (selectionStartLine isNil or:[selectionEndLine isNil]) ifTrue:[
-	allOut := true
+    (selectionStartLine isNil or:[selectionEndLine isNil
+    or:[selectionStartCol isNil or:[selectionEndCol isNil]]]) ifTrue:[
+        allOut := true
     ] ifFalse:[
-	(line between:selectionStartLine and:selectionEndLine) ifFalse:[
-	    allOut := true
-	] ifTrue:[
-	    (selectionStartLine == selectionEndLine) ifTrue:[
-		((endCol < selectionStartCol)
-		or:[startCol > selectionEndCol]) ifTrue:[
-		    allOut := true
-		] ifFalse:[
-		    ((startCol >= selectionStartCol)
-		    and:[endCol <= selectionEndCol]) ifTrue:[
-			allIn := true
-		    ]
-		]
-	    ] ifFalse:[
-		(line == selectionStartLine) ifTrue:[
-		    (endCol < selectionStartCol) ifTrue:[
-			allOut := true
-		    ] ifFalse:[
-			(startCol >= selectionStartCol) ifTrue:[
-			    allIn := true
-			]
-		    ]
-		] ifFalse:[
-		    (line == selectionEndLine) ifTrue:[
-			(startCol > selectionEndCol) ifTrue:[
-			    allOut := true
-			] ifFalse:[
-			    (endCol <= selectionEndCol) ifTrue:[
-				allIn := true
-			    ]
-			]
-		    ] ifFalse:[
-			allIn := true
-		    ]
-		]
-	    ]
-	]
+        (line between:selectionStartLine and:selectionEndLine) ifFalse:[
+            allOut := true
+        ] ifTrue:[
+            (selectionStartLine == selectionEndLine) ifTrue:[
+                ((endCol < selectionStartCol)
+                or:[startCol > selectionEndCol]) ifTrue:[
+                    allOut := true
+                ] ifFalse:[
+                    ((startCol >= selectionStartCol)
+                    and:[endCol <= selectionEndCol]) ifTrue:[
+                        allIn := true
+                    ]
+                ]
+            ] ifFalse:[
+                (line == selectionStartLine) ifTrue:[
+                    (endCol < selectionStartCol) ifTrue:[
+                        allOut := true
+                    ] ifFalse:[
+                        (startCol >= selectionStartCol) ifTrue:[
+                            allIn := true
+                        ]
+                    ]
+                ] ifFalse:[
+                    (line == selectionEndLine) ifTrue:[
+                        (startCol > selectionEndCol) ifTrue:[
+                            allOut := true
+                        ] ifFalse:[
+                            (endCol <= selectionEndCol) ifTrue:[
+                                allIn := true
+                            ]
+                        ]
+                    ] ifFalse:[
+                        allIn := true
+                    ]
+                ]
+            ]
+        ]
     ].
     allOut ifTrue:[
-	super redrawVisibleLine:visLine from:startCol to:endCol.
-	^ self
+        super redrawVisibleLine:visLine from:startCol to:endCol.
+        ^ self
     ].
 
     allIn ifTrue:[
-	self drawVisibleLineSelected:visLine from:startCol to:endCol
+        self drawVisibleLineSelected:visLine from:startCol to:endCol
     ] ifFalse:[
-	"redraw part before selection"
-	((line == selectionStartLine)
-	 and:[startCol <= selectionStartCol]) ifTrue:[
-	    super redrawVisibleLine:visLine from:startCol
-					      to:(selectionStartCol - 1).
-	    leftCol := selectionStartCol
-	] ifFalse:[
-	    leftCol := startCol
-	].
-	"redraw selected part"
-	(selectionEndLine > line) ifTrue:[
-	    rightCol := endCol
-	] ifFalse:[
-	    rightCol := selectionEndCol min:endCol
-	].
-	self drawVisibleLineSelected:visLine from:leftCol to:rightCol.
-
-	"redraw part after selection"
-	(rightCol < endCol) ifTrue:[
-	    super redrawVisibleLine:visLine from:(rightCol + 1) to:endCol
-	]
+        "redraw part before selection"
+        ((line == selectionStartLine)
+         and:[startCol <= selectionStartCol]) ifTrue:[
+            super redrawVisibleLine:visLine from:startCol
+                                              to:(selectionStartCol - 1).
+            leftCol := selectionStartCol
+        ] ifFalse:[
+            leftCol := startCol
+        ].
+        "redraw selected part"
+        (selectionEndLine > line) ifTrue:[
+            rightCol := endCol
+        ] ifFalse:[
+            rightCol := selectionEndCol min:endCol
+        ].
+        self drawVisibleLineSelected:visLine from:leftCol to:rightCol.
+
+        "redraw part after selection"
+        (rightCol < endCol) ifTrue:[
+            super redrawVisibleLine:visLine from:(rightCol + 1) to:endCol
+        ]
     ].
 
     "special care for first and last line of selection:
@@ -3116,14 +3119,14 @@
     and:[(startCol == 1)
     and:[selectionStartLine < selectionEndLine]])
     ifTrue:[
-	self clearMarginOfVisibleLine:visLine with:self currentSelectionBgColor.
+        self clearMarginOfVisibleLine:visLine with:self currentSelectionBgColor.
     ].
 
     ((line == selectionStartLine)
     and:[(startCol == 1)
     and:[selectionStartLine < selectionEndLine]])
     ifTrue:[
-	self clearMarginOfVisibleLine:visLine with:bgColor.
+        self clearMarginOfVisibleLine:visLine with:bgColor.
     ]
 
     "Modified: 6.3.1996 / 14:23:26 / cg"
@@ -4804,11 +4807,11 @@
 !TextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.346 2013-01-26 21:11:40 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.347 2013-03-08 09:46:39 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.346 2013-01-26 21:11:40 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.347 2013-03-08 09:46:39 cg Exp $'
 ! !