public static readonly Selection Empty = new Selection (true);
9
10
public bool IsEmpty {
11
get {
12
return anchor.IsEmpty;
13
}
14
}
15
16
readonly DocumentLocation anchor;
9
17
public DocumentLocation Anchor {
10
18
get {
11
19
return anchor;
12
20
}
13
set {
14
if (anchor != value) {
15
anchor = value;
16
OnChanged ();
17
}
18
}
19
21
}
20
22
21
DocumentLocation lead;
23
readonly DocumentLocation lead;
22
24
public DocumentLocation Lead {
23
25
get {
24
26
return lead;
25
27
}
26
set {
27
if (lead != value) {
28
lead = value;
29
OnChanged ();
30
}
31
}
32
28
}
33
29
30
34
31
public int MinLine {
35
32
get {
36
33
return System.Math.Min (Anchor.Line, Lead.Line);
55
52
}
56
53
}
57
54
55
readonly SelectionMode selectionMode;
58
56
public SelectionMode SelectionMode {
59
get;
60
set;
57
get {
58
return selectionMode;
59
}
61
60
}
62
61
63
62
public bool Contains (DocumentLocation loc)
64
63
{
65
64
return anchor <= loc && loc <= lead || lead <= loc && loc <= anchor;
66
65
}
67
68
public Selection ()
69
{
70
SelectionMode = SelectionMode.Normal;
71
}
72
73
public static Selection Clone (Selection selection)
74
{
75
if (selection == null)
76
return null;
77
return new Selection (selection.Anchor, selection.Lead, selection.SelectionMode);
78
}
79
66
67
Selection(bool empty)
68
{
69
anchor = lead = DocumentLocation.Empty;
70
selectionMode = SelectionMode.Normal;
71
}
72
80
73
public Selection (int anchorLine, int anchorColumn, int leadLine, int leadColumn, SelectionMode mode = SelectionMode.Normal) : this(new DocumentLocation (anchorLine, anchorColumn), new DocumentLocation (leadLine, leadColumn), mode)
81
74
{
82
75
}
87
80
throw new ArgumentOutOfRangeException ("anchor", anchor + " is out of range.");
88
81
if (lead.Line < DocumentLocation.MinLine || lead.Column < DocumentLocation.MinColumn)
89
82
throw new ArgumentOutOfRangeException ("lead", lead + " is out of range.");
90
this.Anchor = anchor;
91
this.Lead = lead;
92
this.SelectionMode = selectionMode;
93
}
94
83
this.anchor = anchor;
84
this.lead = lead;
85
this.selectionMode = selectionMode;
86
}
87
88
public Selection WithLead (DocumentLocation newLead)
89
{
90
return new Selection (Anchor, newLead, SelectionMode);
91
}
92
93
public Selection WithAnchor (DocumentLocation newAnchor)
94
{
95
return new Selection (newAnchor, Lead, SelectionMode);
96
}
97
98
public Selection WithRange (DocumentLocation newAnchor, DocumentLocation newLead)
99
{
100
return new Selection (newAnchor, newLead, SelectionMode);
101
}
102
103
public Selection WithSelectionMode (SelectionMode newSelectionMode)
104
{
105
return new Selection (Anchor, Lead, newSelectionMode);
106
}
107
95
108
public TextSegment GetSelectionRange (TextEditorData data)
96
109
{
97
110
int anchorOffset = GetAnchorOffset (data);
130
143
{
131
144
if (obj == null)
132
145
return false;
133
if (ReferenceEquals (this, obj))
134
return true;
135
146
if (obj.GetType () != typeof(Selection))
136
147
return false;
137
148
Mono.TextEditor.Selection other = (Mono.TextEditor.Selection)obj;
138
return Anchor == other.Anchor && Lead == other.Lead;