forked from jacobslusser/ScintillaNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelection.cs
More file actions
154 lines (141 loc) · 5.65 KB
/
Selection.cs
File metadata and controls
154 lines (141 loc) · 5.65 KB
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
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ScintillaNET
{
/// <summary>
/// Represents a selection when there are multiple active selections in a <see cref="Scintilla" /> control.
/// </summary>
public class Selection
{
private readonly Scintilla scintilla;
/// <summary>
/// Gets or sets the anchor position of the selection.
/// </summary>
/// <returns>The zero-based document position of the selection anchor.</returns>
public int Anchor
{
get
{
var pos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNANCHOR, new IntPtr(Index)).ToInt32();
if (pos <= 0)
return pos;
return scintilla.Lines.ByteToCharPosition(pos);
}
set
{
value = Helpers.Clamp(value, 0, scintilla.TextLength);
value = scintilla.Lines.CharToBytePosition(value);
scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNANCHOR, new IntPtr(Index), new IntPtr(value));
}
}
/// <summary>
/// Gets or sets the amount of anchor virtual space.
/// </summary>
/// <returns>The amount of virtual space past the end of the line offsetting the selection anchor.</returns>
public int AnchorVirtualSpace
{
get
{
return scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNANCHORVIRTUALSPACE, new IntPtr(Index)).ToInt32();
}
set
{
value = Helpers.ClampMin(value, 0);
scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNANCHORVIRTUALSPACE, new IntPtr(Index), new IntPtr(value));
}
}
/// <summary>
/// Gets or sets the caret position of the selection.
/// </summary>
/// <returns>The zero-based document position of the selection caret.</returns>
public int Caret
{
get
{
var pos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNCARET, new IntPtr(Index)).ToInt32();
if (pos <= 0)
return pos;
return scintilla.Lines.ByteToCharPosition(pos);
}
set
{
value = Helpers.Clamp(value, 0, scintilla.TextLength);
value = scintilla.Lines.CharToBytePosition(value);
scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNCARET, new IntPtr(Index), new IntPtr(value));
}
}
/// <summary>
/// Gets or sets the amount of caret virtual space.
/// </summary>
/// <returns>The amount of virtual space past the end of the line offsetting the selection caret.</returns>
public int CaretVirtualSpace
{
get
{
return scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNCARETVIRTUALSPACE, new IntPtr(Index)).ToInt32();
}
set
{
value = Helpers.ClampMin(value, 0);
scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNCARETVIRTUALSPACE, new IntPtr(Index), new IntPtr(value));
}
}
/// <summary>
/// Gets or sets the end position of the selection.
/// </summary>
/// <returns>The zero-based document position where the selection ends.</returns>
public int End
{
get
{
var pos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNEND, new IntPtr(Index)).ToInt32();
if (pos <= 0)
return pos;
return scintilla.Lines.ByteToCharPosition(pos);
}
set
{
value = Helpers.Clamp(value, 0, scintilla.TextLength);
value = scintilla.Lines.CharToBytePosition(value);
scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNEND, new IntPtr(Index), new IntPtr(value));
}
}
/// <summary>
/// Gets the selection index.
/// </summary>
/// <returns>The zero-based selection index within the <see cref="SelectionCollection" /> that created it.</returns>
public int Index { get; private set; }
/// <summary>
/// Gets or sets the start position of the selection.
/// </summary>
/// <returns>The zero-based document position where the selection starts.</returns>
public int Start
{
get
{
var pos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNSTART, new IntPtr(Index)).ToInt32();
if (pos <= 0)
return pos;
return scintilla.Lines.ByteToCharPosition(pos);
}
set
{
value = Helpers.Clamp(value, 0, scintilla.TextLength);
value = scintilla.Lines.CharToBytePosition(value);
scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNSTART, new IntPtr(Index), new IntPtr(value));
}
}
/// <summary>
/// Initializes a new instance of the <see cref="Selection" /> class.
/// </summary>
/// <param name="scintilla">The <see cref="Scintilla" /> control that created this selection.</param>
/// <param name="index">The index of this selection within the <see cref="SelectionCollection" /> that created it.</param>
public Selection(Scintilla scintilla, int index)
{
this.scintilla = scintilla;
Index = index;
}
}
}