Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GoFish doesn't scroll to matching line
Message
From
18/01/2023 06:21:36
Lutz Scheffler (Online)
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
 
 
To
18/01/2023 06:12:12
General information
Forum:
Visual FoxPro
Category:
VFPX/Sedna
Miscellaneous
Thread ID:
01685788
Message ID:
01685833
Views:
31
>>>>
>>>>I do not know your skills (mine are poor), but you can try to single step the JS in FireFox. Just google how to do.
>>>
>>>Couldn't manage to step in FireFox, but I was able to do so in Chrome. There's something weird going on here. The JS code that does the scrolling is this:
>>>
>>>
>>>	//Finds y value of given object
>>>	function findPos(obj) {
>>>			var curtop = 0;
>>>			if (obj.offsetParent) {
>>>				   do {
>>>						   curtop += obj.offsetTop;
>>>				   } while (obj = obj.offsetParent);
>>>			return [curtop];
>>>			}
>>>	}
>>>
>>>	//Scroll to location of "matchdiv"
>>>	function ScrollToMatch(){
>>>		var MatchDiv = document.getElementById('matchline');
>>>		var matchPosition = findPos(MatchDiv);
>>>		var bodyHeight = document.body.offsetHeight;
>>>		var scrollTo = parseInt(matchPosition) - (parseInt(bodyHeight) / 3);
>>>		window.scroll(0, scrollTo);
>>>	}
>>>
>>>
>>>When I step through this code on the first sample I created, where there are 198 lines and the match is around line 63, the value for scrollTo comes out negative, which is why is doesn't scroll properly. For the file you sent me, where the match is almost at the end, the calculation gives a value large enough that, if the browser is tall enough, the match shows. Ditto for my second example.
>>>
>>>I don't understand why the calculation is the position of the match less 1/3 of the total body height. I get that the idea is to put the match in the middle of the space, but 1/3 of the overall height doesn't seem like it would always give that result.
>>>
>>>Tamar
>>
>>My best guess to the 1/3 problem is, it places the result somewhere below the middle of the visible area, or 1/3 above the lower boundary.
>>For the negatives, is matchPosition negative or the final result?
>
>matchPosition is, I think, accurate, but because of the large value of bodyHeight, scrollTo is negative. Try a search where the result file is large and the match is farther down than what shows without scrolling, but relatively near the top.
>
>I think this code was assumed to be "good enough," but that there are cases where it fails.
>
>Tamar

Maybe one should place an anchor and force the browser to jump to the anchor? Anyone using JS? Let's see if we can borrow wisdom ...
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform