Flex Textarea:粘贴时剥离的换行符

时间:2011-08-09 13:27:44

标签: flex flex-spark

如果我在spark TextArea中给出restrict =“[a-z] [A-Z]”,并将内容粘贴到其中,则会删除所有换行符。手动按Enter键工作正常。问题在哪里?

<s:TextArea restrict="[A-Z][a-z]"/>

mx TextArea工作正常。

2 个答案:

答案 0 :(得分:0)

如果限制它,换行符将无效。试着这样做:

<s:TextArea restrict="A-Za-z\n"/>

答案 1 :(得分:0)

protected function textArea_changingHandler(event:TextOperationEvent):void
        {
            if (event.operation is PasteOperation)
            {
                event.preventDefault();
                var txt:String = Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT).
                    toString().replace(/[^A-Za-z0-9\s]/ig, "");
                var curPos1:Number = textArea.selectionAnchorPosition;
                var curPos2:Number = textArea.selectionActivePosition;
                if (curPos2 < curPos1)
                {
                    var t:Number = curPos1;
                    curPos1 = curPos2;
                    curPos2 = t;
                }

                if (textArea.text.length > 0)
                {
                    textArea.text = textArea.text.substr(0, curPos1) + txt + textArea.text.substr(curPos2, textArea.
                        text.length);
                }
                else
                {
                    textArea.text = txt;
                }
                textArea.selectRange(curPos1 + txt.length, curPos1 + txt.length);
                event.preventDefault();
            }
        }

这有效地处理了粘贴期间可能发生的所有场景/操作。