////////////////////////////////////////////////////////////////////////////////
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package flashx.textLayout.operations
{
import flashx.textLayout.edit.ElementRange;
import flashx.textLayout.edit.ParaEdit;
import flashx.textLayout.edit.SelectionState;
import flashx.textLayout.elements.FlowLeafElement;
import flashx.textLayout.elements.InlineGraphicElement;
import flashx.textLayout.elements.ParagraphElement;
import flashx.textLayout.elements.SpanElement;
import flashx.textLayout.elements.TCYElement;
import flashx.textLayout.formats.ITextLayoutFormat;
import flashx.textLayout.formats.TextLayoutFormat;
import flashx.textLayout.tlf_internal;
use namespace tlf_internal;
/**
* The InsertTextOperation class encapsulates a text insertion operation.
*
* @see flashx.textLayout.edit.EditManager
* @see flashx.textLayout.events.FlowOperationEvent
*
* @playerversion Flash 10
* @playerversion AIR 1.5
* @langversion 3.0
*/
public class InsertTextOperation extends FlowTextOperation
{
private var _deleteSelectionState:SelectionState;
private var delSelOp:DeleteTextOperation = null;
/** @private - this should be private but too late for code changes on Labs */
public var _text:String;
private var adjustedForInsert:Boolean = false;
private var _characterFormat:ITextLayoutFormat;
/**
* Creates an InsertTextOperation object.
*
* @param operationState Describes the insertion point or range of text.
* @param text The string to insert.
* @param deleteSelectionState Describes the range of text to delete before doing insertion,
* if different than the range described by operationState
.
*
* @playerversion Flash 10
* @playerversion AIR 1.5
* @langversion 3.0
*/
public function InsertTextOperation(operationState:SelectionState, text:String, deleteSelectionState:SelectionState = null)
{
super(operationState);
_characterFormat = operationState.pointFormat;
_text = text;
initialize(deleteSelectionState);
}
private function initialize(deleteSelectionState:SelectionState):void
{
if (deleteSelectionState == null)
deleteSelectionState = originalSelectionState;
if (deleteSelectionState.anchorPosition != deleteSelectionState.activePosition)
{
_deleteSelectionState = deleteSelectionState;
delSelOp = new DeleteTextOperation(_deleteSelectionState);
}
}
/**
* The text inserted by this operation.
* @playerversion Flash 10
* @playerversion AIR 1.5
* @langversion 3.0
*/
public function get text():String
{
return _text;
}
public function set text(value:String):void
{
_text = value;
}
/**
* The text deleted by this operation, if any.
*
*
null
if no text is deleted.
This function is called by the edit manager, when necessary.
* * @playerversion Flash 10 * @playerversion AIR 1.5 * @langversion 3.0 */ public override function redo():SelectionState { doInternal(); return new SelectionState(textFlow,absoluteStart+_text.length,absoluteStart+_text.length,null); } /** @private */ tlf_internal override function merge(op2:FlowOperation):FlowOperation { if (absoluteStart < absoluteEnd) return null; if (this.endGeneration != op2.beginGeneration) return null; // We are assuming here that these operations are contiguous, because // SelectionManager doesn't try to merge operations if the selection // has changed var insertOp:InsertTextOperation = null; if (op2 is InsertTextOperation) insertOp = op2 as InsertTextOperation; if (insertOp) { if (insertOp.deleteSelectionState != null || deleteSelectionState != null) return null; if ((insertOp.originalSelectionState.pointFormat == null) && (originalSelectionState.pointFormat != null)) return null; if ((originalSelectionState.pointFormat == null) && (insertOp.originalSelectionState.pointFormat != null)) return null; if (originalSelectionState.absoluteStart + _text.length != insertOp.originalSelectionState.absoluteStart) return null; if (((originalSelectionState.pointFormat == null) && (insertOp.originalSelectionState.pointFormat == null)) || (TextLayoutFormat.isEqual(originalSelectionState.pointFormat, insertOp.originalSelectionState.pointFormat))) _text += insertOp.text; else return null; setGenerations(beginGeneration,insertOp.endGeneration); return this; } if (op2 is SplitParagraphOperation) return new CompositeOperation([this,op2]); return null; } } }