Browse Source

Add GetNewOffset() method to TextChangeEventArgs.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
c001357617
  1. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/ITextAnchor.cs
  2. 17
      src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/TextChangeEventArgs.cs

4
src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/ITextAnchor.cs

@ -121,8 +121,8 @@ namespace ICSharpCode.NRefactory.Editor @@ -121,8 +121,8 @@ namespace ICSharpCode.NRefactory.Editor
{
/// <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>

17
src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/TextChangeEventArgs.cs

@ -75,5 +75,22 @@ namespace ICSharpCode.NRefactory.Editor @@ -75,5 +75,22 @@ namespace ICSharpCode.NRefactory.Editor
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;
}
}
}
}

Loading…
Cancel
Save