Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
Jellobus
- Posts: 317
- Joined: Tue Dec 10, 2013 2:53 pm
Post
by Jellobus » Mon Mar 03, 2014 6:20 am
Hi everyone!
I am trying to solve an issue with characters without space in field. set dontWrap to false does not affect characters without space. look at the link first,
http://lessons.runrev.com/s/lessons/m/2 ... -wrap-text
I tested this script with
on keyUp message in the field script, but it seems this method needs two fields. I like to make it with a single field but did not succeed..Must be there is a way to achieve. Can anyone make it with a single field?
Cheers,
Louis
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Mon Mar 03, 2014 6:34 am
Hi Louis,
This works
Code: Select all
on closeField
put wordWrapped(me,25) into me
end closeField
put that into the field script.
It triggers when you leave the field.
Not sure you'll be happy with that but give it a try.
Write back if you want help trying a different way.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
dave.kilroy
- VIP Livecode Opensource Backer

- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
-
Contact:
Post
by dave.kilroy » Mon Mar 03, 2014 11:06 am
Hi Louis
What Simon said - plus, you might also want something to clean out those inserted 'return's from your string of chars - the following code all goes in the field's script:
Code: Select all
on openField
cleanString
end openField
on closeField
callWrapper
end closeField
on exitField
callWrapper
end exitField
on cleanString
local tString
repeat for each char c in the text of me
if c <> return then put c after tString
end repeat
put tString into me
end cleanString
on callWrapper
local tWidth
put 25 into tWidth
put wordWrapped(the text of me,tWidth) into me
end callWrapper
"...this is not the code you are looking for..."
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Mon Mar 03, 2014 7:15 pm
Wouldn't removing the returns just unwrap it again?
At any rate, a faster way to remove the returns in a text block is to use the "replace" command. That way you don't need to loop through every character, which is slow:
Code: Select all
on cleanString
put the text of me into tString
replace cr with empty in tString
put tString into me
end cleanString
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
dave.kilroy
- VIP Livecode Opensource Backer

- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
-
Contact:
Post
by dave.kilroy » Mon Mar 03, 2014 7:37 pm
Hi Jacque
Well yes - I was thinking the OP might need to use the string of chars without returns in it
And yes - "replace cr with empty" is both more elegant and faster

"...this is not the code you are looking for..."
-
Jellobus
- Posts: 317
- Joined: Tue Dec 10, 2013 2:53 pm
Post
by Jellobus » Tue Mar 04, 2014 4:01 am
Hi, Simon, Dave, and Jacque.
Thanks for your advice
I tested your script and found that spaces between words are removed if I repetitively open and close to edit text of field.
Is it possible to make field behaves like a memo app in ios? so chars will be wrapped as soon as users type it in the field.
Thanks for your creative idea!
Louis
-
Simon
- VIP Livecode Opensource Backer

- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
Post
by Simon » Wed Mar 05, 2014 2:17 am
Hi Louis,
This may do what you want but I'm not very happy with it.
Code: Select all
global i
on closeField
put 0 into i
end closeField
on focusIn
put 0 into i
end focusIn
on keyDown
if the length of me > i + 10 then
put cr after me
add 10 to i
end if
pass keyDown
end keyDown
I think you are better off with the wordWrapped function.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
Jellobus
- Posts: 317
- Joined: Tue Dec 10, 2013 2:53 pm
Post
by Jellobus » Wed Mar 05, 2014 4:05 pm
Hi Simon,
Thanks your suggestion. I have tried like yours (slightly different) but the behavior of field was not consistent. I am keep trying to find solution to make a field behaves like typical memo app in mobile. I will post it if I find a way to achieve it.
Cheers,
Louis