                 }
             }
 
+            // The text deleted by this operation.  If we're doing our
+            // own manipulation of the textFlow we have to take the deleted
+            // text into account as well as the inserted text.
+            var delSelOp:SelectionState = 
+                insertTextOperation.deleteSelectionState;
+
+            var delLen:int = (delSelOp == null) ? 0 :
+                             delSelOp.absoluteEnd - delSelOp.absoluteStart;
+                
             if (maxChars != 0)
             {
-                var length1:int = text.length;
+                var length1:int = text.length - delLen;
                 var length2:int = textToInsert.length;
                 if (length1 + length2 > maxChars)
                     textToInsert = textToInsert.substr(0, maxChars - length1);

    {
        //trace("compositionComplete");
                
        // The text flow changed and there wasn't an editing operation
        // to dispatch the change event so do it here.  This happens if the
        // text/content is set and there are no additional editing operations. 
        // We will ignore textFlow changes that occur because the editManager is
        // being hooked up to the textFlow by the TCM.
        if (textChanged || contentChanged)
        {
            if (textFlowChanged)
            {
                var newEvent:TextOperationEvent =
                    new TextOperationEvent(TextOperationEvent.CHANGE);
                dispatchEvent(newEvent);            
            }
            
            textChanged = false;
            contentChanged = false;        
        }
        textFlowChanged = false;
        
        var dimensionChanged:Boolean = false;
        var oldContentWidth:Number = _contentWidth;

     */    
    private var errorCaught:Boolean = false;
    
    /**
     *  @private
     *  Hold the previous editingMode while using a specific instance manager
