#BUGFIX by cg
authorClaus Gittinger <cg@exept.de>
Tue, 17 Apr 2018 08:21:14 +0200
changeset 6304 93a632d04f8c
parent 6303 8ae931b8a84e
child 6305 5e9740739ad1
#BUGFIX by cg class: ListView comment/format in: #at:put: #list:expandTabs:scanForNonStrings:includesNonStrings:redraw: changed: ensure string colletions #add: #add:beforeIndex: #addAll:beforeIndex: #replaceFrom:to:with:startingAt:
ListView.st
--- a/ListView.st	Wed Apr 11 18:37:27 2018 +0200
+++ b/ListView.st	Tue Apr 17 08:21:14 2018 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
@@ -746,26 +748,26 @@
 
     |fontHeightBefore|
 
-    list isNil ifTrue:[list := OrderedCollection new].
+    list isNil ifTrue:[list := StringCollection new].
     list add:aString.
 
     includesNonStrings ifFalse:[
-	includesNonStrings := (aString notNil and:[(aString isSingleByteString) not]).
-	includesNonStrings ifTrue:[
-	    fontHeightBefore := fontHeight.
-	    self getFontParameters.
-	    fontHeightBefore ~~ fontHeight ifTrue:[
-		self invalidate
-	    ].
-	].
+        includesNonStrings := (aString notNil and:[(aString isSingleByteString) not]).
+        includesNonStrings ifTrue:[
+            fontHeightBefore := fontHeight.
+            self getFontParameters.
+            fontHeightBefore ~~ fontHeight ifTrue:[
+                self invalidate
+            ].
+        ].
     ].
 
     widthOfWidestLine notNil ifTrue:[
-	self recomputeWidthOfWidestLineFor:aString old:nil.
+        self recomputeWidthOfWidestLineFor:aString old:nil.
     ].
 
     shown ifTrue:[
-	self redrawLine:(self size).
+        self redrawLine:(self size).
     ].
     self enqueueDelayedContentsChangedNotification.             "recompute scrollbars"
 
@@ -777,33 +779,33 @@
 
     |lastShown|
 
-    list isNil ifTrue:[list := OrderedCollection new].
+    list isNil ifTrue:[list := StringCollection new].
     list add:aString beforeIndex:index.
 
     widthOfWidestLine notNil ifTrue:[
-	self recomputeWidthOfWidestLineFor:aString old:nil.
+        self recomputeWidthOfWidestLineFor:aString old:nil.
     ].
 
     includesNonStrings ifFalse:[
-	includesNonStrings := (aString notNil and:[(aString isSingleByteString) not]).
+        includesNonStrings := (aString notNil and:[(aString isSingleByteString) not]).
 "/        includesNonStrings ifTrue:[self getFontParameters].
     ].
     shown ifTrue:[
-	lastShown := self lastLineShown.
-	index <= 2 ifTrue:[
-	    self invalidate
-	] ifFalse:[
-	    index to:lastShown do:[:eachLine |
-		self invalidateLine:eachLine
-	    ].
-	].
+        lastShown := self lastLineShown.
+        index <= 2 ifTrue:[
+            self invalidate
+        ] ifFalse:[
+            index to:lastShown do:[:eachLine |
+                self invalidateLine:eachLine
+            ].
+        ].
     ].
     self enqueueDelayedContentsChangedNotification.  "recompute scrollbars"
 
     (scrollWhenUpdating == #end or:[scrollWhenUpdating == #endOfText]) ifTrue:[
-	"/ self selection isNil ifTrue:[
-	    self scrollToBottom.
-	"/ ]
+        "/ self selection isNil ifTrue:[
+            self scrollToBottom.
+        "/ ]
     ].
 
     "Modified: / 25-07-2012 / 12:00:42 / cg"
@@ -814,45 +816,45 @@
 
     |lastShown|
 
-    list isNil ifTrue:[list := OrderedCollection new].
+    list isNil ifTrue:[list := StringCollection new].
     aCollectionOfLines do:[:eachLine |
-	list addAll:aCollectionOfLines beforeIndex:index.
+        list addAll:aCollectionOfLines beforeIndex:index.
     ].
     includesNonStrings ifFalse:[
-	includesNonStrings :=
-	    aCollectionOfLines
-		contains:[:someLine |
-		    someLine notNil and:[(someLine isSingleByteString) not].
-		]
+        includesNonStrings :=
+            aCollectionOfLines
+                contains:[:someLine |
+                    someLine notNil and:[(someLine isSingleByteString) not].
+                ]
     ].
 
     widthOfWidestLine notNil ifTrue:[
-	aCollectionOfLines do:[:eachLine |
-	    self recomputeWidthOfWidestLineFor:eachLine old:nil.
-	].
+        aCollectionOfLines do:[:eachLine |
+            self recomputeWidthOfWidestLineFor:eachLine old:nil.
+        ].
     ].
 "/    widthOfWidestLine := nil. "/ i.e. unknown
     self textChanged.
 
     shown ifTrue:[
-	lastShown := self lastLineShown.
-	((index-1) <= lastShown) ifTrue:[
-	    index <= 2 ifTrue:[
-		self invalidate
-	    ] ifFalse:[
-		index-1 to:lastShown do:[:eachLine |
-		    self invalidateLine:eachLine
-		].
-		"/  self redrawFromLine:index-1.
-	    ].
-	].
+        lastShown := self lastLineShown.
+        ((index-1) <= lastShown) ifTrue:[
+            index <= 2 ifTrue:[
+                self invalidate
+            ] ifFalse:[
+                index-1 to:lastShown do:[:eachLine |
+                    self invalidateLine:eachLine
+                ].
+                "/  self redrawFromLine:index-1.
+            ].
+        ].
     ].
     self enqueueDelayedContentsChangedNotification.  "recompute scrollbars"
 
     (scrollWhenUpdating == #end or:[scrollWhenUpdating == #endOfText]) ifTrue:[
-	"/ self selection isNil ifTrue:[
-	    self scrollToBottom.
-	"/ ]
+        "/ self selection isNil ifTrue:[
+            self scrollToBottom.
+        "/ ]
     ].
 
     "Modified: / 25-07-2012 / 12:00:54 / cg"
@@ -882,12 +884,12 @@
     self withoutRedrawAt:index put:aString.
 
     shown ifTrue:[
-	fontHeightBefore ~= fontHeight ifTrue:[
-	    "/ must redraw everything
-	    self invalidate.
-	    ^ self
-	].
-	self redrawLine:index.
+        fontHeightBefore ~= fontHeight ifTrue:[
+            "/ must redraw everything
+            self invalidate.
+            ^ self
+        ].
+        self redrawLine:index.
 
 "/ the code below is wrong - we really have to redraw everything, if the
 "/ fontHeight changes (due to a labelAndIcon in the list).
@@ -905,16 +907,16 @@
 "/            self redrawLine:index
 "/        ].
 
-	"/ asynchronous:
+        "/ asynchronous:
 "/        visibleLine := self listLineToVisibleLine:index.
 "/        visibleLine notNil ifTrue:[
 "/            y := self yOfVisibleLine:visibleLine.
 "/            self invalidate:((margin @ y) extent:(width@fontHeight))
 "/        ].
 
-	widthBefore ~~ widthOfWidestLine ifTrue:[
-	    self enqueueDelayedContentsChangedNotification
-	]
+        widthBefore ~~ widthOfWidestLine ifTrue:[
+            self enqueueDelayedContentsChangedNotification
+        ]
     ]
 
     "Modified: / 25-07-2012 / 12:01:46 / cg"
@@ -1101,61 +1103,61 @@
     "/ notice, that it may be very expensive to ask aCollection for each line
     "/ for example, iff the lines are generated on the fly by an algorithm
     false ifTrue:[
-	"/ see if there is a change at all.
-	"/ use to compare using =, but that's not enough in case of emphasis change.
-	aCollection size == list size ifTrue:[
-	    same := true.
-	    aCollection size > 0 ifTrue:[
-		aCollection with:list do:[:eachNewLine :eachOldLine |
-		    (eachNewLine == eachOldLine)
-		    ifFalse:[
-			same := false.
-		    ]
-		]
-	    ].
-	    same ifTrue:[^ self].
-	].
+        "/ see if there is a change at all.
+        "/ use to compare using =, but that's not enough in case of emphasis change.
+        aCollection size == list size ifTrue:[
+            same := true.
+            aCollection size > 0 ifTrue:[
+                aCollection with:list do:[:eachNewLine :eachOldLine |
+                    (eachNewLine == eachOldLine)
+                    ifFalse:[
+                        same := false.
+                    ]
+                ]
+            ].
+            same ifTrue:[^ self].
+        ].
     ].
 
     scrollToTop := scrollWhenUpdating == #begin or:[scrollWhenUpdating == #beginOfText].
     scrollToEnd := scrollWhenUpdating == #end or:[scrollWhenUpdating == #endOfText].
 
     (aCollection isEmptyOrNil and:[list isEmptyOrNil]) ifTrue:[
-	"no contents change"
-	list := aCollection.
-	scrollLocked ifFalse:[
-	    scrollToTop ifTrue:[
-		self scrollToTop.
-	    ] ifFalse:[
-		scrollToEnd ifTrue:[
-		    self scrollToBottom.
-		]
-	    ].
-	    self scrollToLeft.
-	].
-	^ self
+        "no contents change"
+        list := aCollection.
+        scrollLocked ifFalse:[
+            scrollToTop ifTrue:[
+                self scrollToTop.
+            ] ifFalse:[
+                scrollToEnd ifTrue:[
+                    self scrollToBottom.
+                ]
+            ].
+            self scrollToLeft.
+        ].
+        ^ self
     ].
 
     checkLineEndConventionWhenUpdating ifTrue:[
-	"Check if the we use DOS/Windows line end convention with CR LF.
-	 The LF has already been consumed by the conversion to a StringCollection,
-	 now check for and remove the trailing left over CRs"
-
-	lineEndCRLF := (aCollection size > 0
-			and:[(firstLine := aCollection at:1) isString
-			and:[firstLine notEmpty
-			and:[firstLine string endsWith:Character return]]]).
+        "Check if the we use DOS/Windows line end convention with CR LF.
+         The LF has already been consumed by the conversion to a StringCollection,
+         now check for and remove the trailing left over CRs"
+
+        lineEndCRLF := (aCollection size > 0
+                        and:[(firstLine := aCollection at:1) isString
+                        and:[firstLine notEmpty
+                        and:[firstLine string endsWith:Character return]]]).
     ].
     lineEndCRLF ifTrue:[
-	list := aCollection
-		    collect:[:eachLineWithCROrNil |
-			eachLineWithCROrNil isNil
-			    ifTrue:nil
-			    ifFalse:[(eachLineWithCROrNil endsWith:Character return)
-				     ifTrue:[eachLineWithCROrNil copyButLast:1]
-				     ifFalse:[eachLineWithCROrNil]]].
+        list := aCollection
+                    collect:[:eachLineWithCROrNil |
+                        eachLineWithCROrNil isNil
+                            ifTrue:nil
+                            ifFalse:[(eachLineWithCROrNil endsWith:Character return)
+                                     ifTrue:[eachLineWithCROrNil copyButLast:1]
+                                     ifFalse:[eachLineWithCROrNil]]].
     ] ifFalse:[
-	list := aCollection.
+        list := aCollection.
     ].
 
     nonStringsBefore := includesNonStrings.
@@ -1163,18 +1165,18 @@
     includesNonStrings := false.
 
     list notNil ifTrue:[
-	expand ifTrue:[
-	    self expandTabs
-	] ifFalse:[
-	    scan ifTrue:[
-		includesNonStrings := list contains:[:e | e isString not].
-	    ] ifFalse:[
-		includesNonStrings := nonStringsIfNoScan ? nonStringsBefore
-	    ]
-	].
+        expand ifTrue:[
+            self expandTabs
+        ] ifFalse:[
+            scan ifTrue:[
+                includesNonStrings := list contains:[:e | e isString not].
+            ] ifFalse:[
+                includesNonStrings := nonStringsIfNoScan ? nonStringsBefore
+            ]
+        ].
     ].
     (includesNonStrings ~~ nonStringsBefore) ifTrue:[
-	self getFontParameters.
+        self getFontParameters.
     ].
 
     widthOfWidestLine := nil.   "/ i.e. unknown
@@ -1182,49 +1184,49 @@
     oldLeft := viewOrigin x.
 
     (includesNonStrings ~~ nonStringsBefore) ifTrue:[
-	self computeNumberOfLinesShown.
+        self computeNumberOfLinesShown.
     ].
 
     scrollLocked ifFalse:[
-	newLeftOffset := viewOrigin x.
-	scrollToTop ifTrue:[
-	    firstLineShown := 1.
-	    newLeftOffset := 0.
-	] ifFalse:[
-	    scrollToEnd ifTrue:[
-		firstLineShown := (list size - nFullLinesShown + 1) max:1.
-		newLeftOffset := 0.
-	    ]
-	].
-	newLeftOffset > 0 ifTrue:[
-	    wText := self widthOfContents.
-	    (viewOrigin x + self innerWidth) > wText ifTrue:[
-		newLeftOffset := (wText - self innerWidth) max:0.
-	    ].
-	].
-	newLeftOffset ~= oldLeft ifTrue:[
-	    viewOrigin := newLeftOffset @ viewOrigin y.
-	].
+        newLeftOffset := viewOrigin x.
+        scrollToTop ifTrue:[
+            firstLineShown := 1.
+            newLeftOffset := 0.
+        ] ifFalse:[
+            scrollToEnd ifTrue:[
+                firstLineShown := (list size - nFullLinesShown + 1) max:1.
+                newLeftOffset := 0.
+            ]
+        ].
+        newLeftOffset > 0 ifTrue:[
+            wText := self widthOfContents.
+            (viewOrigin x + self innerWidth) > wText ifTrue:[
+                newLeftOffset := (wText - self innerWidth) max:0.
+            ].
+        ].
+        newLeftOffset ~= oldLeft ifTrue:[
+            viewOrigin := newLeftOffset @ viewOrigin y.
+        ].
     ].
 
     realized ifTrue:[
-	self contentsChanged.
-	scrollLocked ifFalse:[
-	    "
-	     don't use scroll here to avoid double redraw
-	    "
-	    viewOrigin := viewOrigin isNil ifTrue:[0@0] ifFalse:[(viewOrigin x) @ 0].
-	    gc transformation:nil.
-
-	    oldFirst ~~ firstLineShown ifTrue:[
-		self originChanged:0 @ ((oldFirst - 1) * fontHeight negated).
-	    ].
-	].
-	doRedraw ifTrue:[
-	    shown ifTrue:[
-		self invalidate.
-	    ]
-	]
+        self contentsChanged.
+        scrollLocked ifFalse:[
+            "
+             don't use scroll here to avoid double redraw
+            "
+            viewOrigin := viewOrigin isNil ifTrue:[0@0] ifFalse:[(viewOrigin x) @ 0].
+            gc transformation:nil.
+
+            oldFirst ~~ firstLineShown ifTrue:[
+                self originChanged:0 @ ((oldFirst - 1) * fontHeight negated).
+            ].
+        ].
+        doRedraw ifTrue:[
+            shown ifTrue:[
+                self invalidate.
+            ]
+        ]
     ]
 
     "Modified: / 30-08-1995 / 19:07:13 / claus"
@@ -1347,9 +1349,7 @@
 replaceFrom:startLineNr to:endLineNr with:aCollection startingAt:replStartIndex
     "replace some lines"
 
-    list isNil ifTrue:[
-	list := OrderedCollection new.
-    ].
+    list isNil ifTrue:[ list := StringCollection new:endLineNr ].
     list replaceFrom:startLineNr to:endLineNr with:aCollection startingAt:replStartIndex.
 
     widthOfWidestLine := nil. "/ i.e. unknown
@@ -1357,7 +1357,7 @@
 
     ((startLineNr <= self lastLineShown)
     and:[endLineNr >= firstLineShown]) ifTrue:[
-	self invalidate.
+        self invalidate.
     ].
 
     self enqueueDelayedContentsChangedNotification.