Page 1 of 1
how do you find selected line in a text field
Posted: Sun Feb 24, 2013 8:52 am
by user#606
In this case, the text field is set to "Dont Wrap"
Lock text and List behaviour are false.
The reason for this is so the list of email addresses, one per line can be easily added on to. This in not practical with the List behaviour TRUE
It would appear simple to put the insertion point or select the line and then capture the email address on that line. The line number in fact.
But only if the List behaviour is TRUE.
Unfortunately, when List behaviour is TRUE, adding another address to the list is a few clicks to get the insertion point to the end of the last item and then the return key to create a new line in which to cut and paste a new email address.
There must be a simple way of getting the line number without messing about with List behaviour.
Any ideas?
Re: how do you find selected line in a text field
Posted: Sun Feb 24, 2013 9:30 am
by monte
Hi... not really sure why you can't set listbehavior true if the field is locked anyway... However, if you don't want to then use the clickLine
Re: how do you find selected line in a text field
Posted: Sun Feb 24, 2013 9:43 am
by Dixie
user606...
The script below will do what you wish to do using a 'list' field...
Code: Select all
on mouseDown
put line (word 2 of the clickline) of me
end mouseDown
on mouseDoubleUp
if the clipboard is "text" then
put the clipboarddata ["text"] into newAddress
if "@" is not among the chars of newAddress then exit mouseDoubleUp
put the number of lines of me into lineCount
put newAddress into line lineCount + 1 of me
set the clipboardData["text"] to empty
end if
end mouseDoubleUp
Just place the above into a 'list' filed... however, if you just wish to find the line number then use the 'lineOffset' function...
be well
Dixie
Re: how do you find selected line in a text field
Posted: Sun Feb 24, 2013 10:01 am
by user#606
Hi Monte
I said the Lock text was false.
Also, as I also stated, setting list behavior messes up the simple text editing....
Hi Dixi,
I dont think that will help solve the problem. I am not looking for email addresses in a block of text. However, in another part of my project, that code will help a great deal. Thank you.
To avoid advisors barking up the wrong tree, I set out the field state and explained what I was hoping to achieve and why.
I know how to select lines and the contents, but this appears to be only possible if List behavior is true.
Can the line be found without the list behavior true?
Re: how do you find selected line in a text field
Posted: Sun Feb 24, 2013 10:17 am
by Dixie
user606...
I think that I am not understanding exactly what you want to do...
user#606 wrote:The reason for this is so the list of email addresses, one per line can be easily added on to. This in not practical with the List behaviour TRUE
I thought that you wished to be able to 'paste' an new email address into a new line at the bottom of a field that contains your email addresses... with as few clicks as possible.,,, if that is so, then script I posted will do just that... as long as you have copied an email address from somewhere, then 'double clicking' in the field will create a new line and insert the email address at the bottom of the list . If the text that you have on the clipboard, ie the text that you have taken from wherever does not contain a '@' symbol, suggesting that it is not a valid email address then liveCode will bail out of the script...
The mouseDown handler in the script that I posted is just residue from when I was putting the script together... but feel free to disregard everything I have just said..
be well
Dixie
Re: how do you find selected line in a text field
Posted: Sun Feb 24, 2013 10:31 am
by user#606
Hi Dixie,
The question is, how can you find the line number (ultimately to get the content of that ling) in a text field, consisting of several lines.
The listbehavior must NOT be true. It is this part that prevents me finding a solution.
The reason listbehavior needs to be false is so subsequent editing is not messed up.
What I must achieve is:-
Click the Email address I want, (lets say Email@address2) so I have that address or line number, to act on.
Normally, you have to have listbehavoir TRUE, before it will work.
I dont want that, because it makes copy and paste of an additional address at some future time, very difficult. (compared with adding onto a normal block of text.
Email@address1
Email@address2
Email@address3
Re: how do you find selected line in a text field
Posted: Sun Feb 24, 2013 11:18 am
by Dixie
user606...
I think this will do what you want... put it in the script of an ordinary field.
Code: Select all
on selectionChanged
put "Line" && (word 2 of the clickline) &"." && "The text is:" && line (word 2 of the clickline) of me
end selectionChanged
Dixie
Re: how do you find selected line in a text field
Posted: Sun Feb 24, 2013 1:04 pm
by user#606
Hi Dixie,
I have tried the code you suggest, modified as follows.
Code: Select all
on selectionChanged
local linenum
put (word 2 of the clickline) into linenum
--answer linenum
end selectionChanged
However, the purpose of getting the line number is to put the content of the line (email address in this case) into the RevEmail function.
If I want to add to the text, or edit the existing, it will always proceed to generating the email.
So, you have answered one point, but created an additional issue.
The solution I have found so far is this.
The text field is as I specified so word processor editing is simple. This is the usual state of affairs in daily use.
Above the text box is a "Create Email button.
If I want to generate an Email, I click this and it changes the LineBehavior to TRUE, and so I can see the condition, it changes the text to red.
Now, when I click the required line, it functions as desired by copying the line content to the Email part of the RevEmail function and up pops the email.
The process continues to set the LineBehavior back to False and sets the text back to black.
The code for the create button is:
Code: Select all
on mouseUp
set listBehavior of field "input4" to true
set the textcolor of field "input4" to "red"
end mouseUp
The code for the text field is:
Code: Select all
on mouseUp
local emailaddress
put the value of the clickLine into emailaddress
revMail emailaddress
put empty into emailaddress
set listBehavior of field "input4" to false
set locktext of field "input4" to false
set the textcolor of field "input4" to "black"
end mouseUp
I have shown the above in case it is useful to some other Mutt like me.
I realise now, the solution will always require at least two clicks to achieve my objective, if I avoid using the other mouse button to difrentiate between tasks.
Anyway, thank you so much for the help. You got it sorted for me, indirectly.
all the content.
Re: how do you find selected line in a text field
Posted: Mon Feb 25, 2013 8:40 pm
by sritcp
Hi user606:
In an ordinary text field (LIST = false), a click does not send a mouseUp message, but a control-click does.
So you can edit the field to add email addresses, etc., but use control-click to capture line number, email address, etc. to generate email.
Would that work for you?
Regards,
Sri.
Re: how do you find selected line in a text field
Posted: Mon Feb 25, 2013 9:08 pm
by dunbarx
The fabulous "selectionChanged" message trumps the fact that in an ordinary editable field, a mouseUp message is not sent when clicking.
Try this in the field script:
Code: Select all
on selectionchanged
put word 2 of the clickLine into tLine
answer tLine && the value of line tLine of me
end selectionchanged
The secret is that clicking also resets the blinking cursor, and that lies squarely on the new line. No messy control-click.
Craig Newman
Edit. Oops, I see this is old news.
Re: how do you find selected line in a text field
Posted: Tue Feb 26, 2013 11:06 am
by user#606
Hi Dunbarx, and Scritcp,
Thank you for your reply.
Although the application is only for my use, therefore any reasonable solution, including Control-Click would be ok, I wanted to minimise any unnecessary actions.
I concluded that what I needed to do would always end up as a two stage process.
However, I think the solution Dunbarx has suggested is worth exploring, if not for this project, but for the future.
Thanks to all for contributing.