Browse files

Add GetNewOffset() method to TextChangeEventArgs.

  • Loading branch information...
1 parent 269597e commit c001357617c2b59d08534f9532e8bdb6bd780893 @dgrunwald dgrunwald committed Sep 20, 2011
View
4 src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/ITextAnchor.cs
@@ -121,8 +121,8 @@ public enum AnchorMovementType
{
/// <summary>
/// When text is inserted at the anchor position, the type of the insertion
- /// determines where the caret moves to. For normal insertions, the anchor will stay
- /// behind the inserted text.
+ /// determines where the caret moves to. For normal insertions, the anchor will move
+ /// after the inserted text.
/// </summary>
Default,
/// <summary>
View
17 src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/TextChangeEventArgs.cs
@@ -75,5 +75,22 @@ public TextChangeEventArgs(int offset, string removedText, string insertedText)
this.removedText = removedText ?? string.Empty;
this.insertedText = insertedText ?? string.Empty;
}
+
+ /// <summary>
+ /// Gets the new offset where the specified offset moves after this document change.
+ /// </summary>
+ 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;
+ }
+ }
}
}

0 comments on commit c001357

Please sign in to comment.