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!
on mouseUp
put the selectedText into tSelect
put "</font>" after tSelect
put "<font color ="& quote & "red" & quote &">"before tSelect
put tSelect into the selectedText
end mouseUp
I think it is part of the windows interface that a field looses focus if you click a button, on a mac this is not the case.
I would trapp the loosing of focus in a script of the field and set a custom property of that field that you than query:
on focusOut -- for locked text fields
set the cLastSelection of me to the selectedChunk
put "out"
end focusOut
on exitfield -- for editable fields
set the cLastSelection of me to the selectedChunk
put "out"
end exitfield
on mouseUp
set the textcolor of the cLastSelection of field 1 to red
end mouseUp
If you want this for multiple fields I would set a custom property of the card (e.g. the cLastSelection of this card) and then query that in the button script.
The way you approached it before you were mixing the raw html of a field. This would have to be done in the htmlText of field xyz. And than set the htmlText of field xyz to the changed htmlText.
If you only want to change color textsize and style it is easier to use the syntax I propose.
regards
Bernd
Thanks for that. Unfortunately it's not working too well.
When I click the button nothing happens - because the exitfield hasn't happened until I click outside the box (clicking a button doesn't register).
So, if I select a chunk and click my button and then click outside the field I get the "out" message. Then if I click the button again the text that I had selected changes to red but it isn't selected.
Jim,
I thought you were on a windows computer. So I actually tested by clicking outside of the field and then clicking the button.
On a mac it is easier (assuming that I am correct that on a windows computer a field looses focus when a button is clicked), almost your original approach:
this works on locked text and on editable text, the selection is not lost.
Bernd - Nice - that works well with your textcolor code but not with my HTML code. I should have explained - the HTML that was in my code is intended to work thus:
I select word 2 from the following:
One two three.
I click my button
I get:
One <font color ="red">two</font> three.
And word 2 should still be selected.
I could, of course, use HTMLtext but that produces loads of paragraph code (<p> etc) which I don't want or need.
Jim,
I dont quite understand. What do you want to display?
One Two(in red) Three
or
One <font color ="red">two</font> three
The word two should be red or do you want the html in the text?
What do you want to be selected after your operation? Is it the word 'two' that should be selected?
Could you explain a little more the context of what you want to achieve?
regards
Bernd
I want the HTML code displayed. and I'd like the word two to be selected (or the HTML and two would be fine too).
The reason I need this is because I'm making a simple HTML code tool which will add simple HTML formatting to text. I have a palette with buttons for Italic, Bold, Bold+Italic and red.
In some instances I'd like to have bold and red and I don't want to have to reselect the same text each time.
on mouseUp
-- get the char count of the selection
-- e.g. char 34 to 38 of field 1
put the selectedChunk into tSelectChunk
put the selectedText into tSelect -- get the text
-- a little errorchecking
if tSelect = "" then exit mouseUP
put "</font>" after tSelect -- do your html
put "<font color = "& quote & "red" & quote & ">" into tbefore -- split html
put tbefore before tSelect
put length (tbefore) into tLength
-- add leading html to the selectedChunk to hilite /change color of the original word
add tLength to word 2 of tSelectChunk
add tLength to word 4 of tSelectChunk
put tSelect into the selectedText
-- change color
set textcolor of tSelectChunk to red
-- restore selection
select tSelectChunk
end mouseUp