Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 3841 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

This one has stumped me.

 

I am writing a sort of html editor in FM 11. So I went ahead and built a set of buttons just like TinyMce and started to replicate their functionality. Using the Insert Calculated Result I can select a a section of text in a field and add the html tags at the beginning and the end of the selection depending on what button is clicked. To view the result I use a web viewer on another Tab. All good for most of it until I needed to leave the field to replicate the TinyMce functionality.

1. H1, H2, paragraph etc. come in a drop down menu in TinyMce.

2. Special characters come in a window popup in TinyMce as they are too numerous to display.

 

So my problem is that I have to leave the selection I have made in the text field in order to display the drop down selection or the popup window and then the script no longer has a reference for where to Insert its Calculated result.

 

The following example script steps work well when individual buttons are on the same layout.

 

 

Set Variable [ $start; Value:Get ( ActiveSelectionStart ) ]
Set Variable [ $size; Value:Get ( ActiveSelectionSize ) ]
Set Variable [ $content; Value:Middle ( Topics::Topic_Text_body; $start ; $size ) ]
 
Insert Calculated Result [ Let ([
$sp = Get(ScriptParameter) ;
$newContent = "<" & Get(ScriptParameter) & ">" & $content &"</" & Get(ScriptParameter) & ">" ] ;
Case (
$sp = "B" ; TextStyleAdd ( $newContent ; Bold ) ;
$sp = "I" ; TextStyleAdd ( $newContent ; Italic ) ;
$sp = "u" ; TextStyleAdd ( $newContent ; Underline ) ;
$sp = "st" ; TextStyleAdd ( $Content ; Strikethrough ) ;
$sp = "sub" ; TextStyleAdd ( $newContent ; Subscript ) ;
$sp = "sup" ; TextStyleAdd ( $newContent ; Superscript ) ;
$newContent )
) ]
 
The case function is there just to generate a bit of visual feedback on the edit Tab text field.
 
If I set the variables prior to leaving the field is there any way to go back to the text originally selected in that field or the position in that field (in the case of inserting special characters) before Inserting the Calculated Result?
Posted
If I set the variables prior to leaving the field is there any way to go back to the text originally selected

 

Have a look at the Set Selection[] script step.

Posted

Thanks for the very fast response Comment, you beat me to it.

 

I figured it out using Set Selection[] and a script trigger.

 

For others I will try to explain.

 

For the Format drop down it needed a script trigger on exiting the text field to set the ActiveSelectionStart & ActiveSelectionSize prior to clicking on the drop down field or the focus was already lost.

 

For the Special Character popup window it did not need the above script trigger in play to work but it was there anyway so may as well use it.

 

So for each problem there needs to be two scripts in the process, the second one in each being for the resultant selection and that's where to use the Set Selection[] script step to get you back to the text field and back to the original selection of text.

 

Now two very curious things.

1. This didn't work with variables. The result was just wacky but it did work with fields and using the Set Field[] script step instead.

2. Generating the Start, Size and calculating the End (as calculation field) resulted in capturing one more character so I had to add a "-1" to the Set Selection[] script step. Could have done it in the calc instead. Didn't matter.

Posted

1. This didn't work with variables. The result was just wacky

 

 

Define "wacky". Did you use global $$variables rather than script $variables that expire as soon as the script runs out?

 

 

Thanks for the very fast response Comment, you beat me to it.

 

You posted.

Posted

By wacky I mean the result for start size and end seemed to work, from recollection, (verified by global variables being displayed on the layout via <<$$xxx>>) but the Set Selection result would be something completely different. Tried as script then global variables and did think about the expiration issue.

 

New to Set Selection[]. I'm pretty sure I just missed something but I have had problems before using variables and have to had set some global fields instead. Again I probably just missed something then too.

 

Thanks. I'm glad I posted.

Posted
I have had problems before using variables and have to had set some global fields instead.

 

You should look into that in more depth. FWIW, I have exactly the same mechanism (set $$variables on field exit, restore selection before inserting calculated result) in a file I use very often and it works without any problems.

  • 2 weeks later...

This topic is 3841 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.