blob: 8ffb5fe34527ecf6ecfd762fc40232a278a9d4fe (
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
|
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
//
// This file contain implementations details that are subject to change without notice.
// Use at your own risk.
//
namespace Microsoft.VisualStudio.Text.Implementation
{
using System;
/// <summary>
/// Base class for a tracking span in a particular <see cref="ITextBuffer"/>.
/// </summary>
internal abstract partial class TrackingSpan : ITrackingSpan
{
#region State and Construction
protected readonly SpanTrackingMode trackingMode;
public TrackingSpan(ITextVersion version, Span span, SpanTrackingMode trackingMode)
{
if (version == null)
{
throw new ArgumentNullException("version");
}
if (span.End > version.Length)
{
throw new ArgumentOutOfRangeException("span");
}
if (trackingMode < SpanTrackingMode.EdgeExclusive || trackingMode > SpanTrackingMode.Custom)
{
throw new ArgumentOutOfRangeException("trackingMode");
}
this.trackingMode = trackingMode;
}
#endregion
#region ITrackingSpan members
public abstract ITextBuffer TextBuffer { get; }
public SpanTrackingMode TrackingMode
{
get { return this.trackingMode; }
}
public abstract TrackingFidelityMode TrackingFidelity { get; }
public Span GetSpan(ITextVersion version)
{
if (version == null)
{
throw new ArgumentNullException("version");
}
if (version.TextBuffer != this.TextBuffer)
{
throw new ArgumentException(Strings.InvalidVersion);
}
return TrackSpan(version);
}
public SnapshotSpan GetSpan(ITextSnapshot snapshot)
{
if (snapshot == null)
{
throw new ArgumentNullException("snapshot");
}
if (snapshot.TextBuffer != this.TextBuffer)
{
throw new ArgumentException(Strings.InvalidSnapshot);
}
return new SnapshotSpan(snapshot, TrackSpan(snapshot.Version));
}
public SnapshotPoint GetStartPoint(ITextSnapshot snapshot)
{
SnapshotSpan s = this.GetSpan(snapshot);
return new SnapshotPoint(snapshot, s.Start);
}
public SnapshotPoint GetEndPoint(ITextSnapshot snapshot)
{
SnapshotSpan s = this.GetSpan(snapshot);
return new SnapshotPoint(snapshot, s.End);
}
public string GetText(ITextSnapshot snapshot)
{
return GetSpan(snapshot).GetText();
}
#endregion
#region Helpers
protected abstract Span TrackSpan(ITextVersion targetVersion);
#endregion
#region Diagnostic Support
protected static string SpanTrackingModeToString(SpanTrackingMode trackingMode)
{
switch (trackingMode)
{
case SpanTrackingMode.EdgeExclusive:
return "→←";
case SpanTrackingMode.EdgeInclusive:
return "←→";
case SpanTrackingMode.EdgeNegative:
return "←←";
case SpanTrackingMode.EdgePositive:
return "→→";
case SpanTrackingMode.Custom:
return "custom";
default:
return "??";
}
}
protected static string ToString(ITextVersion version, Span span, SpanTrackingMode trackingMode)
{
return string.Format(System.Globalization.CultureInfo.CurrentCulture, "V{0} {2}@{1}",
version.VersionNumber, span.ToString(), SpanTrackingModeToString(trackingMode));
}
#endregion
}
}
|