1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
3
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
// software and associated documentation files (the "Software"), to deal in the Software
5
// without restriction, including without limitation the rights to use, copy, modify, merge,
6
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
// to whom the Software is furnished to do so, subject to the following conditions:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17
// DEALINGS IN THE SOFTWARE.
21
namespace ICSharpCode.NRefactory.Editor
24
/// Describes a change of the document text.
25
/// This class is thread-safe.
28
public class TextChangeEventArgs : EventArgs
31
readonly string removedText;
32
readonly string insertedText;
35
/// The offset at which the change occurs.
38
get { return offset; }
42
/// The text that was removed.
44
public string RemovedText {
45
get { return removedText; }
49
/// The number of characters removed.
51
public int RemovalLength {
52
get { return removedText.Length; }
56
/// The text that was inserted.
58
public string InsertedText {
59
get { return insertedText; }
63
/// The number of characters inserted.
65
public int InsertionLength {
66
get { return insertedText.Length; }
70
/// Creates a new TextChangeEventArgs object.
72
public TextChangeEventArgs(int offset, string removedText, string insertedText)
75
this.removedText = removedText ?? string.Empty;
76
this.insertedText = insertedText ?? string.Empty;
80
/// Gets the new offset where the specified offset moves after this document change.
82
public virtual int GetNewOffset(int offset, AnchorMovementType movementType = AnchorMovementType.Default)
84
if (offset >= this.Offset && offset <= this.Offset + this.RemovalLength) {
85
if (movementType == AnchorMovementType.BeforeInsertion)
88
return this.Offset + this.InsertionLength;
89
} else if (offset > this.Offset) {
90
return offset + this.InsertionLength - this.RemovalLength;
97
/// Creates TextChangeEventArgs for the reverse change.
99
public virtual TextChangeEventArgs Invert()
101
return new TextChangeEventArgs(offset, insertedText, removedText);