Changing Colors Of Text In Field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Changing Colors Of Text In Field
I have a text field where the color of my text is blue. I want the ability to click anywhere in the text field (including between words) and when I type any new text...it is black. It seems like when I click in the middle of a word, I inherit the color of the word (which is currently blue).
Any suggestions?
Thanks for any help!
Warren
Any suggestions?
Thanks for any help!
Warren
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Changing Colors Of Text In Field
Hi Warren,
No problem for me with rev 4.0 and livecode 4.50 with OSX
Jean-Marc
No problem for me with rev 4.0 and livecode 4.50 with OSX
Jean-Marc
https://alternatic.ch
Re: Changing Colors Of Text In Field
Try This:
on keyDown
set the textColor of (the selectedChunk) to black
pass keyDown
end keyDown
on keyDown
set the textColor of (the selectedChunk) to black
pass keyDown
end keyDown
Re: Changing Colors Of Text In Field
Hi all,
One scenario, admittedly not raised in the original post, is the case of selecting some text then typing new text over it. In case this, I found:
... is needed, otherwise the first character of the newly inserted text is blue, followed by black characters. This points to a subtle difference between the selection, and the selectedChunk- if there is no text selected (hence the selection is empty) yet the insertion point is in the field, the Dictionary entry for selectedChunk mentions:
Regards,
Michael
One scenario, admittedly not raised in the original post, is the case of selecting some text then typing new text over it. In case this, I found:
Code: Select all
on keyDown
if the selection is not empty then
delete the selectedChunk
end if
set the textColor of (the selectedChunk) to black
pass keyDown
end keyDown
... which is handy to remember. All of this was prompted by jsburnett’s neat solution, which I was very keen to try. I’m running Rev Studio 4.0.0 under Windows XP, by the way.If no text is selected but the text insertion point is in a field, the startChar is the character after the insertion point, and the endChar is the character before the insertion point. In this case, the endChar is one less than the startChar.
Regards,
Michael
Re: Changing Colors Of Text In Field
Michael,
While all that may be true....
if you put the script I posted in the field, it works with the first char changing colors.
Why, despite the documentation you quoted, ?
JSB
While all that may be true....
if you put the script I posted in the field, it works with the first char changing colors.
Why, despite the documentation you quoted, ?
JSB
Re: Changing Colors Of Text In Field
I spoke too soon.
I see your point.
When selecting text, the first char is not changed color.
Thanks!
I see your point.
When selecting text, the first char is not changed color.
Thanks!
Re: Changing Colors Of Text In Field
Hi JSB,
It was because your method was so neat and handy that I was prompted to play with it, during which I stumbled on the need for the minor “tweak”. Then I found myself wondering about the difference between the selection and the selectedChunk, so I thought I’d include a little discussion of what I learned for the benefit of future readers of this thread. I’ve added your solution to my collection of useful code snippets. It’s just the sort of thing I’m likely to need. Many thanks.
Regards,
Michael
It was because your method was so neat and handy that I was prompted to play with it, during which I stumbled on the need for the minor “tweak”. Then I found myself wondering about the difference between the selection and the selectedChunk, so I thought I’d include a little discussion of what I learned for the benefit of future readers of this thread. I’ve added your solution to my collection of useful code snippets. It’s just the sort of thing I’m likely to need. Many thanks.
Regards,
Michael
Re: Changing Colors Of Text In Field
Michael,
Thank you for your nice words.
I've become more interested in reexploring the syntax again.
I believe if the selection is empty, it will return that.
So, I tried the following and it seems to behave the way your script does too.
on keyDown theKey
delete the selection --if the selection is empty it deletes nothing
set the textColor of the selection to black
pass keyDown
end keyDown
Thank you for your nice words.
I've become more interested in reexploring the syntax again.
I believe if the selection is empty, it will return that.
So, I tried the following and it seems to behave the way your script does too.
on keyDown theKey
delete the selection --if the selection is empty it deletes nothing
set the textColor of the selection to black
pass keyDown
end keyDown