Flex Spark TextArea insertText breaks undo buffer
I have a simple TextArea
<s:TextArea id="taData" keyUp="keyListener(event)" focusEnabled="false" fontFamily开发者_JAVA百科="Courier New" fontSize="12" left="10" right="10" top="40" bottom="10"/>
the keyListener allows tab to be used like this
private function keyListener(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.TAB)
{
event.currentTarget..insertText("\t");
}
}
Everything works as expected, but the undo buffer is reset / stops at the point that a tab was inserted.
Is there a way to ensure that the undo buffer remains in tact even with the tab inserted
If all you want to do is insert a tab into your text when the user presses the tab key, there's a better way to do it (and I hope it will solve your undo issue at the same time).
You'll have to access the TextArea's model - the TextFlow object - and tinker with its configuration. The textflow Configuration class has a property called 'manageTabKey' which defaults to 'false'. If you set it to 'true' it will do what I think you're trying to do for you, i.e. when the user hits the tab key, insert a tab character instead of putting the focus on the next focusable element.
var textFlow:TextFlow = taData.textFlow;
var config:Configuration = Configuration(textFlow.configuration);
config.manageTabKey = true;
The cast to Configuration is necessary, because textFlow.configuration returns an IConfiguration interface that has no setter method for manageTabKey.
Additionally, you could even set the width of your tabs by using the 'tabStops' property.
textFlow.tabStops = "25 50 75 100";
EDIT: I just noticed that you set 'focusEnabled' to false. This will also no longer be necessary.
精彩评论