Page 1 of 1

Text colour

Posted: Thu Dec 04, 2014 9:11 am
by Traxgeek
Hi, I'm sure this must have been covered but I can't find where ! :oops:

I'm playing with html text input controls.
I can, post-writing my html text, select a chunk and colour it - or whatever I wish to do with it (bold, italic, whatever) - no problems there.
I can also set the text/'foregroundColor' BUT...

What I cannot seem to do is set the foreground colour for the next one, or more, characters that I am about to write/enter.

When I try to set the foreground colour (naturally enough, kind of) the whole of my text changes colour to the newly selected colour.
Is there a way to set the colour of, if you like, the cursor; so that any future characters typed/entered are the new colour whilst any existing text colouring remains unchanged.
(With drawing controls, one can set the 'penColor' but I haven't found a way to do this for text...
As always, any and all help really appreciated.

Trax.

Re: Text colour

Posted: Thu Dec 04, 2014 11:44 am
by bn
Trax,

I am not sure I understand completely what you want.
Assuming you want to type html text in a regular LC field (as opposed to setting the htmlText of a LC field)

would something like this in the field's script help?

Code: Select all

on keyUp pKey
   put "blue,red,green,brown" into tColors
   put the selectedChunk into tSelChunk
   put word 4 of tSelChunk into tNo
   set the foregroundColor of char tNo of me to any item of tColors
end keyUp
kind regards
Bernd

Re: Text colour

Posted: Fri Dec 05, 2014 12:34 pm
by Traxgeek
Hi Bernd,
I'm not too good at explaining myself at the best of times - I'll try again...

I have a field into which I type.
Sometimes I just type, sometimes I cut 'n' paste something from a web page and then modify or add to it in some way (i.e. sometimes it's effectively plain text , other times it's html text.

I can retrospectively/after typing something, hilite a chunk (say a word or a line of text) and then colour it, make it bold etc. all by setting the 'textstyle' of that selected chunk. No worries there...

What I'd like to be able to do though is select the colour of any future text that I am about to/will write.
I think your response gives me a working idea though which would be to set the colour of the char at the current cursor location so that when I do start typing then my selected colour will come into play.

Thanks.

Trax

Re: Text colour

Posted: Fri Dec 05, 2014 4:29 pm
by dunbarx
Hi.

Why not set a custom property of the field so that the new text will take that color? You can select the color from a pullDown or answer a dialog, whatever. Now modify the code so that the "next" char interrogates the current state of that property.

(pseudo)

set the foreColor of the next char to the nextCharColor of me

Craig Newman

Re: Text colour

Posted: Sat Dec 06, 2014 4:49 pm
by jacque
The selectedChunk has a value even if it's just an insertion point. You should be able to set text properties on that. All subsequent text should assume the revised styling.

Re: Text colour

Posted: Sun Dec 07, 2014 3:57 pm
by Traxgeek
Thank you Jacque, Thank you dubarx and Thank you Bernd.
Much appreciated all three of you.