Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

cursor line

 [1/12] from: hijim:pronet at: 18-Aug-2001 10:11


Hi Anton, Thanks for trying to get this figured out. For the html and program editor there is no wrap, so counting newlines will work fine. But with wrap on, we need something else. I put your line-number: (system/view/line-info/offset/y - a/para/scroll/y - 2) / 15 into the program, but I get an error: ** Script Error: Cannot use path on none! value ** Where: get-lines ** Near: system/view/line-info/offset/y - my-area/para/scroll/y - 2
>>
The whole script is at http://www.geocities.com/~jimclatfelter/ed-txt.txt Your code is on line 17. I put a semi-colon in front so the program will run. The line information updates (for now) whenever you press the space key or click on Line or Lines or Pages. Thanks for trying to get this, Jim Anton wrote:

 [2/12] from: arolls::bigpond::net::au at: 19-Aug-2001 5:03


That's because before any text is entered, system/view/line-info/offset == none You can just put a test around that: either none? system/view/line-info/offset [ ; no text entered, oh dear ; return 1 as default line-number line-number: 1 ][ ; calculate line-number as below ]

 [3/12] from: arolls:bigpond:au at: 19-Aug-2001 5:47


I am losing patience with this approach. I think it's kind of problematic, since the scroll amount can be any fractions of lines, depending on how big the area is. I would rather get into the area feel and rework it totally. :) You want to do this anyway, because you need to trap key events so that your info-fields are updated with the line number automatically. But that will have to wait until tomorrow...

 [4/12] from: agem:crosswinds at: 18-Aug-2001 22:32


RE: [REBOL] Re: cursor line my half cent: once i saw a function which gives you the position on screen for the caret, in pixels. used for jumping to line with caret. with that one could calculate line by dividing by font-heigh? needs some digging, maybe later. -Volker [arolls--bigpond--net--au] wrote:

 [5/12] from: hijim:pronet at: 16-Aug-2001 20:22


I figured out a way to get the curent line of the cursor in a text area, but I'm having trouble implementing it. I hope this is understandable. aa: length? my-area/line-list ;lines in text a: my-area/text ;text b: system/view/caret ;text from cursor to end bb: length? my-area/line-list ;length of b text if system/view/caret <> none [ my-area/text: copy b my-cursor/text: aa - bb ;cursor line ] my-area/text: a ;restore original text The problem is that aa and bb (my-area/line-list) are always the same as each other. I tried to use COPY length? my-area/line-list , but I got the error ** Script Error: copy expected value argument of type: series port bitset I need bb to retain the value of the the shortened text (from the cursor to the end). As it is now, it reverts to the values of aa when I restore the original text. How can I assign bb so it holds its value? This will work if I can solve this problem. Even at that, there's probably a more direct solution, but this will do the job. Thanks, Jim

 [6/12] from: arolls:bigpond:au at: 17-Aug-2001 14:21


I don't understand what you are trying to do. Please explain what operation you want done to the text. When is the code below executed? Is it a delete to the end of the line? etc.

 [7/12] from: hijim:pronet at: 16-Aug-2001 22:13


Hi Anton, I'm trying to find out what line the cursor is on in a text area. The code calculates that by finding the number of lines in the area and then reducing the text to that from the cursor to the end. I can find the number of lines both times. I just can't keep the value of aa and bb from being identical. Both variables always contain the number of lines in the current text. How can I assign this number to a variable that will not change? I'd like to have this info always current, but that would mean calculating on every keystroke. Instead I have a button to update and display number of lines in the text area, number of pages that will go to the printer, and (I'm hoping) what line the cursor is on. I know the code will work if I can assign to a variable that will not change, but COPY doesn't do it. I'm sure there's a simple answer to this. Of course, a more direct method might be better. I've experimented with system/view/line-info, as you suggested, but I get nothing that seems related to the current cursor line. Thanks, Jim Anton wrote:

 [8/12] from: brett:codeconscious at: 17-Aug-2001 15:31


Hi Jim, system/view/caret is pointing to the "same" text as my-area/text but is just at a different series index which shows where the cursor is. You can see this by printing head system/view/caret So based on that here's my little way of finding the line, by counting the number of line breaks: text-b4-cursor: copy/part head system/view/caret system/view/caret parse/all text-b4-cursor [ (line-num: 1) some [thru newline (line-num: add 1 line-num)] to end ] Line-num is left with the line number. I haven't thoroughly tested it but it may help. No doubt someone else has a more elegant solution for you. Brett.

 [9/12] from: brett:codeconscious at: 17-Aug-2001 15:35


> Of course, a more direct method might be better. I've experimented with > system/view/line-info, as you suggested, but I get nothing that seems > related to the current cursor line.
I stumbled across the following function TEXTINFO and it seems related but I have absolutely no idea how one uses it (sorry). Maybe it will help though.
>> help textinfo
USAGE: TEXTINFO face line-info line DESCRIPTION: Sets the line text information in an object for a face. TEXTINFO is a native value. ARGUMENTS: face -- The face for which the information is defined. (Type: object) line-info -- The object where the information will be set. (Type: object) line -- The line to get information for. (Type: number any-string)

 [10/12] from: arolls:bigpond:au at: 17-Aug-2001 17:19


Well, here's possibly a better way: line-number: func [/local s c][ if s: system/view/caret [ c: 0 repeat i (index? s) - 1 [ if (pick head s i) = newline [c: c + 1] ] return c ] ] view layout [ a: area {a long string^/with^/many^/lines in it.} button "line number" [print line-number] ]

 [11/12] from: hijim:pronet at: 17-Aug-2001 6:48


Hi Anton and Brett, 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. I'll work on it some more. It must be my error. I know my method should work. I'll ask again if I can explain it better. I'll post the function if I can get it to work. Thanks, Jim

 [12/12] 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...