~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory/Editor/TextChangeEventArgs.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
2
 
// 
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:
8
 
// 
9
 
// The above copyright notice and this permission notice shall be included in all copies or
10
 
// substantial portions of the Software.
11
 
// 
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.
18
 
 
19
 
using System;
20
 
 
21
 
namespace ICSharpCode.NRefactory.Editor
22
 
{
23
 
        /// <summary>
24
 
        /// Describes a change of the document text.
25
 
        /// This class is thread-safe.
26
 
        /// </summary>
27
 
        [Serializable]
28
 
        public class TextChangeEventArgs : EventArgs
29
 
        {
30
 
                readonly int offset;
31
 
                readonly string removedText;
32
 
                readonly string insertedText;
33
 
                
34
 
                /// <summary>
35
 
                /// The offset at which the change occurs.
36
 
                /// </summary>
37
 
                public int Offset {
38
 
                        get { return offset; }
39
 
                }
40
 
                
41
 
                /// <summary>
42
 
                /// The text that was removed.
43
 
                /// </summary>
44
 
                public string RemovedText {
45
 
                        get { return removedText; }
46
 
                }
47
 
                
48
 
                /// <summary>
49
 
                /// The number of characters removed.
50
 
                /// </summary>
51
 
                public int RemovalLength {
52
 
                        get { return removedText.Length; }
53
 
                }
54
 
                
55
 
                /// <summary>
56
 
                /// The text that was inserted.
57
 
                /// </summary>
58
 
                public string InsertedText {
59
 
                        get { return insertedText; }
60
 
                }
61
 
                
62
 
                /// <summary>
63
 
                /// The number of characters inserted.
64
 
                /// </summary>
65
 
                public int InsertionLength {
66
 
                        get { return insertedText.Length; }
67
 
                }
68
 
                
69
 
                /// <summary>
70
 
                /// Creates a new TextChangeEventArgs object.
71
 
                /// </summary>
72
 
                public TextChangeEventArgs(int offset, string removedText, string insertedText)
73
 
                {
74
 
                        this.offset = offset;
75
 
                        this.removedText = removedText ?? string.Empty;
76
 
                        this.insertedText = insertedText ?? string.Empty;
77
 
                }
78
 
                
79
 
                /// <summary>
80
 
                /// Gets the new offset where the specified offset moves after this document change.
81
 
                /// </summary>
82
 
                public virtual int GetNewOffset(int offset, AnchorMovementType movementType = AnchorMovementType.Default)
83
 
                {
84
 
                        if (offset >= this.Offset && offset <= this.Offset + this.RemovalLength) {
85
 
                                if (movementType == AnchorMovementType.BeforeInsertion)
86
 
                                        return this.Offset;
87
 
                                else
88
 
                                        return this.Offset + this.InsertionLength;
89
 
                        } else if (offset > this.Offset) {
90
 
                                return offset + this.InsertionLength - this.RemovalLength;
91
 
                        } else {
92
 
                                return offset;
93
 
                        }
94
 
                }
95
 
                
96
 
                /// <summary>
97
 
                /// Creates TextChangeEventArgs for the reverse change.
98
 
                /// </summary>
99
 
                public virtual TextChangeEventArgs Invert()
100
 
                {
101
 
                        return new TextChangeEventArgs(offset, insertedText, removedText);
102
 
                }
103
 
        }
104
 
}