Welcome to mirror list, hosted at ThFree Co, Russian Federation.

EditOptions.cs « Model « TextData « Def « Text « src - github.com/microsoft/vs-editor-api.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 71568ade4187578eba3dd027044306b9ba851811 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//
//  Copyright (c) Microsoft Corporation. All rights reserved.
//  Licensed under the MIT License. See License.txt in the project root for license information.
//
namespace Microsoft.VisualStudio.Text
{
    using Microsoft.VisualStudio.Text.Differencing;

    /// <summary>
    /// Options applicable to text editing transactions.
    /// </summary>
    public struct EditOptions
    {
        private bool computeMinimalChange;
        private StringDifferenceOptions differenceOptions;

        #region Common EditOptions values

        /// <summary>
        /// Do nothing special with this edit.
        /// </summary>
        public readonly static EditOptions None = new EditOptions();

        /// <summary>
        /// Turn this edit into a minimal change, using line and word string differencing.
        /// </summary>
        public readonly static EditOptions DefaultMinimalChange = 
            new EditOptions(new StringDifferenceOptions() { DifferenceType = StringDifferenceTypes.Line | StringDifferenceTypes.Word });

        #endregion

        /// <summary>
        /// Create a set of edit options for computing a minimal difference,
        /// with the given <see cref="StringDifferenceOptions" />.
        /// </summary>
        public EditOptions(StringDifferenceOptions differenceOptions)
        {
            this.computeMinimalChange = true;
            this.differenceOptions = differenceOptions;
        }

        /// <summary>
        /// Create a set of edit options.
        /// </summary>
        public EditOptions(bool computeMinimalChange, StringDifferenceOptions differenceOptions)
        {
            this.computeMinimalChange = computeMinimalChange;
            this.differenceOptions = differenceOptions;
        }

        /// <summary>
        /// True if this edit computes minimal change using the differencing option <see cref="StringDifferenceOptions"/>, false otherwise.
        /// </summary>
        public bool ComputeMinimalChange
        {
            get { return this.computeMinimalChange; }
        }

        /// <summary>
        /// The differencing options for this edit, if <see cref="ComputeMinimalChange" /> is true.
        /// </summary>
        /// <remarks>
        /// <see cref="StringDifferenceOptions.IgnoreTrimWhiteSpace" /> will be
        /// ignored.
        /// </remarks>
        public StringDifferenceOptions DifferenceOptions
        { 
            get { return differenceOptions; }
        }

        #region Overridden methods and operators

        /// <summary>
        /// Provides a string representation of these edit options.
        /// </summary>
        public override string ToString()
        {
            if (this == EditOptions.None || !this.ComputeMinimalChange)
            {
                return "{none}";
            }
            else
            {
                return differenceOptions.ToString();
            }
        }

        /// <summary>
        /// Provides a hash function for the type.
        /// </summary>
        public override int GetHashCode()
        {
            if (this == EditOptions.None || !this.ComputeMinimalChange)
            {
                return 0;
            }
            else
            {
                return differenceOptions.GetHashCode();
            }
        }

        /// <summary>
        /// Determines whether two spans are the same.
        /// </summary>
        /// <param name="obj">The object to compare.</param>
        public override bool Equals(object obj)
        {
            if (obj is EditOptions)
            {
                EditOptions other = (EditOptions)obj;
                if (other.ComputeMinimalChange != this.ComputeMinimalChange)
                    return false;
                if (!this.ComputeMinimalChange)
                    return true;

                return other.differenceOptions == this.differenceOptions;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Determines whether two EditOptions are the same
        /// </summary>
        public static bool operator ==(EditOptions left, EditOptions right)
        {
            return left.Equals(right);
        }

        /// <summary>
        /// Determines whether two EditOptions are different.
        /// </summary>
        public static bool operator !=(EditOptions left, EditOptions right)
        {
            return !(left == right);
        }

        #endregion // Overridden methods and operators
    }
}