ICSharpCode.NRefactory.Editor.TextChangeEventArgs.GetNewOffset C# (CSharp) Method

GetNewOffset() public method

Gets the new offset where the specified offset moves after this document change.
public GetNewOffset ( int offset, AnchorMovementType movementType = AnchorMovementType.Default ) : int
offset int
movementType AnchorMovementType
return int
        public virtual int GetNewOffset(int offset, AnchorMovementType movementType = AnchorMovementType.Default)
        {
            if (offset >= this.Offset && offset <= this.Offset + this.RemovalLength) {
                if (movementType == AnchorMovementType.BeforeInsertion)
                    return this.Offset;
                else
                    return this.Offset + this.InsertionLength;
            } else if (offset > this.Offset) {
                return offset + this.InsertionLength - this.RemovalLength;
            } else {
                return offset;
            }
        }

Usage Example

 public void Update(TextChangeEventArgs change)
 {
     if (SurviveDeletion || offset <= change.Offset || offset >= change.Offset + change.RemovalLength)
     {
         offset = change.GetNewOffset(offset, MovementType);
     }
     else
     {
         offset = -1;
     }
 }
All Usage Examples Of ICSharpCode.NRefactory.Editor.TextChangeEventArgs::GetNewOffset