• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Compositing text modifications with font size modifications for undo

Explorer ,
May 27, 2010 May 27, 2010

Copy link to clipboard

Copied

Hey TLF gurus,

So here's my situation.  I have a text flow.  The user starts typing "The lazy brown dog..." and after each character is typed I'm modifying the font size of all the text to make it fit inside the container.  Here's how I'm doing that: http://aaronhardy.com/flex/size-text-to-container/ (you can right-click the app to see the source).

That all works well, but undo isn't working so well.  When I hit undo, I would like it to remove the text.  But when I call undo on the undo manager, it gets to EditManager.performUndo() where it checks to see if operation.endGeneration is different than textFlow.generation.  In my case, they aren't the same because I updated the font size after the last keystroke.  Because they're different, the undo fails.  Because I updated the font size after the last text insert, TextFlow.processModelChanged() was called and increased the text flow's generation while the insert text operation's end generation stayed the same.

Ultimately I think I want to create a composite operation that contains any text modifications with their following text auto-sizing.  Either that or I want to prevent my font auto-sizing operation from affecting the text flow generation.  Either way, I'm not sure how to go about pulling it off.  I'm sure I can make some sweet hacks but I'd really appreciate some guidance.  Thanks.

Aaron

TOPICS
Text layout framework

Views

460

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 27, 2010 May 27, 2010

Copy link to clipboard

Copied

So what I can do is update the generations on the InsertTextOperation to cover those generations that were a result of the ApplyFormatOperation.  The problem with that is when I undo the InsertTextOperation, the text does get removed but the size doesn't get reverted.  So, naturally I could then re-evaluate the size and modify it appropriately, but then I can't redo the InsertTextOperation because once again the end generation for the InsertTextOperation does not equal the text flow's generation (because I just updated the font size).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 27, 2010 May 27, 2010

Copy link to clipboard

Copied

LATEST

I'm able to successfully merge the sizing operations with the text operations.  I did it in a round-about way but afterward I found a more appropriate way: executing the ApplyFormatOperation by calling back into EditManager.doOperation when the FlowOperationEvent.FLOW_OPERATION_END event is dispatched from TextFlow (essentially making it recursive).  This way the EditManager will composite the operations.  This is described pretty well in the code and documentation of EditManager.doInternal().  I didn't test it, however.

Instead, for a couple reasons I decided not to go with that plan at all but instead went with my Plan B which was to prevent my font auto-sizing operation from affecting the text flow generation.  I essentially want the auto-sizing to occur without it going into the undo history, modifying the text flow generation, etc., etc.  I want it to go incognito.  The way I did this was to store the text flow's generation, make the font size modifications, then set the text flow's generation back to what it was before the font size was applied.  This may have some negative repercussions but for now I think it's the best approach for my needs.

Thanks for letting me talk to myself!  Feel free to add ideas.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines