ListModelView.st
changeset 1744 2447f4a3dd7c
parent 1743 7a04f0a5dce2
child 1748 0a2213a15e06
--- a/ListModelView.st	Fri Mar 24 12:37:25 2000 +0100
+++ b/ListModelView.st	Fri Mar 24 15:54:40 2000 +0100
@@ -1067,30 +1067,24 @@
 yAbsoluteOfLine:aLineNr
     "given a lineNr, return y-coordinate absolute
     "
-    |index cash|
+    |y y2 y1 cash|
 
-    cash  := startOfLinesY.
-    index := cash at:aLineNr ifAbsent:[cash last].
+    cash := startOfLinesY.
 
-    index isNil ifTrue:[
-        ^ cash detect:[:x| x notNil] ifNone:[0]
+    (y := cash at:aLineNr ifAbsent:nil) notNil ifTrue:[
+        ^ y
     ].
-    ^ index
+
+    "/ recompute a y position
+    y1 := startOfLinesY at:1 ifAbsent:2.
+    y2 := startOfLinesY at:2 ifAbsent:10.
+  ^ aLineNr * (y2 - y1) + y1
 !
 
 yVisibleOfLine:aLineNr
     "given a lineNr, return y-coordinate in view
     "
-    |y y0 y1|
-
-    y := startOfLinesY at:aLineNr ifAbsent:nil.
-    y isNil ifTrue:[
-        "/ try to compute a default size
-        y1 := startOfLinesY at:2 ifAbsent:[StopRedrawSignal raise].
-        y0 := startOfLinesY at:1.
-        y := aLineNr * (y1 - y0) + y0
-    ].
-    ^ y - viewOrigin y
+    ^ (self yAbsoluteOfLine:aLineNr) - viewOrigin y
 
 
 !
@@ -1509,24 +1503,28 @@
 scrollToLine:aLineNumber
     "make line visible
     "
-    |y  "{ Class:SmallInteger }"
-     l  "{ Class:SmallInteger }"
+    |inHg "{ Class:SmallInteger }"
+     yTop "{ Class:SmallInteger }"
+     orgY "{ Class:SmallInteger }"
+     yBot "{ Class:SmallInteger }"
     |
-    (aLineNumber notNil and:[aLineNumber between:1 and:(list size)]) ifFalse:[
+    (shown and:[aLineNumber notNil and:[aLineNumber between:1 and:list size]]) ifFalse:[
         ^ self
     ].
 
-    y := self yVisibleOfLine:aLineNumber.
+    yTop := self yAbsoluteOfLine:aLineNumber.
+    inHg := self innerHeight.
+    orgY := viewOrigin y.
+
+    yTop > orgY ifTrue:[
+        yBot := self yAbsoluteOfLine:(aLineNumber + 1).
 
-    y < margin ifTrue:[
-        y := margin - y.
-    ] ifFalse:[
-        y := self yVisibleOfLine:(1 + aLineNumber).
-        l := height - margin.
-        y > l ifFalse:[^ self].
-        y := l - y.
+        yBot <= (orgY + inHg) ifTrue:[
+            ^ self
+        ].
     ].
-    self scrollTo:(viewOrigin - (0 @ y)).
+    yTop := (yTop - (inHg // 2)) max:0.
+    self scrollTo:(viewOrigin x @ yTop).
 
 
 ! !
@@ -1534,6 +1532,6 @@
 !ListModelView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/ListModelView.st,v 1.38 2000-03-24 11:37:25 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ListModelView.st,v 1.39 2000-03-24 14:54:40 ca Exp $'
 ! !
 ListModelView initialize!