Skip to main content
Legend
September 12, 2013
Answered

Technique to undo a character format application?

  • September 12, 2013
  • 1 reply
  • 1441 views

Hi,

Seems that answers to complicated questions are a bit sparse in these parts, but I'll try again anyway

I'm wondering if there is any technique to reliably undo a character format application change; that is, an application of properties to a range of text with SetTextProps(). It is fairly simple to remember a list of original properties (PropVals) and the original text range (TextRange), then reapply those original properties to the whole range. However, within a text range, each character can have its own unique set of properties. So, remembering one set of original properties is not enough... seems I have to remember the properties of every single character in the range, the reapply character-by-character, in order to ensure that the new property application is completely undone.

When you apply a character format in the GUI, FM reliably allows an undo, restoring each affected character to its original state. Surely it isn't remembering a PropVals array for every single character (?)  I'm just wondering if there is another trick here. It's entirely possible if FM is internally using another trick, it isn't one that I can feasibly replicate.

Thanks,

Russ

This topic has been closed for replies.
Correct answer 4everJang

Hi Russ,

If you use a GetText method and use the Constants.FTI_CharPropsChange you should get an array of text items where each item has one particular set of properties. You should be able to save those for later restore. There should be no need to save the properties of each single character.

Ciao

Jang

1 reply

4everJang
4everJangCorrect answer
Legend
September 12, 2013

Hi Russ,

If you use a GetText method and use the Constants.FTI_CharPropsChange you should get an array of text items where each item has one particular set of properties. You should be able to save those for later restore. There should be no need to save the properties of each single character.

Ciao

Jang

Russ WardAuthor
Legend
September 13, 2013

Hi Jang,

Thanks for the tip. This would streamline things a bit, I think, but I would still need to store multiple property sets at each point where the properties change, right? I'd have to also retain the text items, so I could step through all the offsets, retrieve the historic properties, then apply them to the correct range.

Just thinking out loud here, trying to asses whether this is worth it.

Russ

4everJang
Legend
September 13, 2013

Hi Russ,

You don't need to actually do the GetProps until the moment when something needs to be undone. Keep the array of TextItems until it is no longer needed. Thinking out loud as well, this leads me to the original question: what is it exactly that you want to restore?

You could keep a safety copy of a Pgf every time something within that Pgf is changed. Then restoring becomes retrieving the entire Pgf and overwriting the changed Pgf with it. Similar for other objects, but as you mention character formats I assume saving a verison of a Pgf on every change inside it should do the trick.

Ciao

Jang