Hi both,
Hmmm... I have struggled with this seemingly simple little thing....
What I'm trying to explain (poorly):
I need my app to offer the same functionality across platforms. The app is designed to 'rove' on a tablet (away from the office/whilst on site) but 'return' to a desktop (office) when desired. So, clipboard actions will (as I understand it) not help me. (Oops ! Forgot, I'm coding on a Mac (mavericks) with LC6.5.0 commercial). So...
I have a card with a text input field on it.
In the field is a 'load of' html formatted text the user has entered.
I have a second field (generally on a different card (easier to explain like this) - but (in reality) on a new instance of the same card (with a different client data).
In this second field is also (potentially) a 'load of' html formatted text that the user has already entered (but it may too be empty as of yet).
I would like to copy a user selected, html formatted, portion of the first field (on the first card) to a user selected position in a another html formatted text field on the second (instance) of a card - whilst maintaining the html formatting of the copied text.
So, what I currently do is along the lines of :
COPY Script - this just selects the user-hilighted characters and dumps them (in this case) into a global (this could also be a Custom Property or...)
Code: Select all
-- assuming my vars are declared...
--...and after checking the selected (target / focussedobject) field is indeed a copy-able field...
put the selectedchunk into sText
put word 2 of sText into nSa
if nSa > 0 then --Just check the cursor is in the field
put the htmltext of the selection into gsCopyText
else
beep --Warn the user of invalid cursor location...
end if
Now then, if I simply 'set the text of field "FieldToPasteInto" to gsCopyText', then I get html formatted text in the field (but, of course, no other text, if there were any) - so , in theory, I'm half way there ! Now all I have to do is set the insertion point. Well, I could do this with 'selected chunk' of the newly highlighted field and, after all the usual checks, 'put gsCopyText into the selection' or split the text in the destination field and insert the copytext into it... or... in all other cases I've tried, when I try to ADD or INSERT my copytext into an existing text I simply end up with either text that takes the formatting of the destination point OR text that displays the html tags...
Code: Select all
put the text of field "lblCopyText" into the selection --no formatting, no tags
put the htmltext of field "lblCopyText" into the selection --no formatting, tags are displayed
put gsCopyText into the selection --no formatting, tags are displayed
BUT, your way (both of you) works like a charm :
Code: Select all
put the selectedChunk of field "DestinationField" into sDestination
set the htmltext sDestination to gsCopyText
I'm not sure why... but I'm absolutely delighted it does - THANKS A MILLION GUYS ! Just goes to prove 'there's more than one way to skin a cat' and LC is very flexible even if one doesn't always receive the result one expects...
Is there, in fact, any specific reason I'm missing why Bernd's/Craig's script works where as mine doesn't (except that you two are obviously far more adept than I !)
I can see :
Code: Select all
put gsCopyText into the selection --Fails miserably
but
Code: Select all
set the htmltext sDestination to gsCopyText --works brilliantly
any obvious reason as to why - apart from that's the way the engine translates the two commands...
Either way, thanks again chaps - MUCH appreciated...
Have a great weekend !
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1