[REBOL] Re: cursor line
From: arolls:bigpond:au at: 18-Aug-2001 22:42
> Thanks, but I'm not trying to count newlines. I'm trying to count lines
> on the screen in a text area with wrap on. That I can do, and it varies
> depending on the width of the screen.. length? my-area/line-list gives
> me this information. But what line is the cursor on.
Ok, forgive me if I still misunderstand your intention.
But I am pretty sure that system/view/line-info/offset
will tell you what line it is on. You just need to
divide the y offset by the height of a line of text
and it should tell you how many lines down you are.
To demonstrate this, do the following a number of
times, adding some text and positioning the cursor
on different lines each time, eg.:
view layout [a: area]
system/view/line-info/offset
== 2x47 ; example
view layout [a: area]
system/view/line-info/offset
== 2x133 ; example
There's 15 pixels for each line, and an initial offset
of 2x2, so to get the line number, subtract 2 from the y
coordinate,then divide by 15.
Right, I notice that if you continue to type more text
than can fit in an area, the area will scroll, but
system/view/line-info/offset doesn't care about that.
How much did it scroll? If a is the area, then the scroll
amount is in a/para/scroll == 0x-34, for example.
You could combine a/para/scroll with system/view/line-info/offset
to find out the line-number from the beginning of the text,
not just from the top edge of the area.
I suppose it should be:
line-number:
(system/view/line-info/offset/y - a/para/scroll/y - 2) / 15
This is not quite perfect, because sometimes partial scroll
amounts give fractional answers. I am still looking into it,
however...