Get a Number of line in Field

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Vincent
Posts: 13
Joined: Wed Mar 18, 2009 5:33 pm

Get a Number of line in Field

Post by Vincent » Thu Dec 03, 2009 9:57 am

Hi,

I would like to get the number of the cliked line in a field to change its backgroundcolor. So, I tried with the "mouseline" function and the "clickline", but it doesn't work...

Someone could help me, please ?

Thanks in advance,

Vincent.

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: Get a Number of line in Field

Post by ale870 » Thu Dec 03, 2009 2:30 pm

Hello,

I used a trick to make it.
I lock the screen, then select the char (chunk) where the caret (cursor) is located. Finally I use "selectedLine" to check line number!
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10324
Joined: Wed May 06, 2009 2:28 pm

Re: Get a Number of line in Field

Post by dunbarx » Fri Dec 04, 2009 4:55 pm

How do you intend to change the color? Just by clicking on a line? If so, and if the field is locked:

Code: Select all

on mouseup
   put word 2 of the clickLine into tLine --you asked for the line number. not needed, though
   set the foregroundColor of the clickline to any item of "red,green,blue,yellow"
end mouseup
If the field is not locked you need to decide how you want to handle the operation. You might use something like the trick suggested, to temporarily lock the field. Note also that holding the commandKey down while clicking will send a mouseUp message to the field, and you can use the handler above.

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: Get a Number of line in Field

Post by ale870 » Fri Dec 04, 2009 5:07 pm

In order to detect current line number, you can use this code:

Code: Select all

local myRnd

on arrowKey
  put random(100000) into myRnd
  send "aggiorna" && myRnd to me in 100 milliseconds
  
  pass arrowKey
end arrowKey

on aggiorna arg1
  if arg1 is myRnd then
    put the selectedLine into field "fldLine"
  end if
end aggiorna
Put it in the Field (your text editor). Time delay will prevent wrong line numbers, and will speed up cursor movements (update cursor position only if the user stop cursor movement).
Field "fldLine" is another field used to show current line number.
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

Post Reply