Code Coverage Statistics for Source File
c:\Tools\SD3\src\Libraries\ICSharpCode.TextEditor\Project\Src\Actions\CaretActions.cs
|
Sequence Point Coverage
N/A
0 of 0
|
Branch Coverage
N/A
0 of 0
|
Lines
203
|
Highlight:
Uncovered Code
Covered Code
| L | V | Source |
|---|---|---|
1 |
// <file> |
|
2 |
// <copyright see="prj:///doc/copyright.txt"/> |
|
3 |
// <license see="prj:///doc/license.txt"/> |
|
4 |
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/> |
|
5 |
// <version>$Revision: 2681 $</version> |
|
6 |
// </file> |
|
7 |
||
8 |
using System; |
|
9 |
using System.Collections.Generic; |
|
10 |
using System.Drawing; |
|
11 |
||
12 |
using ICSharpCode.TextEditor.Document; |
|
13 |
||
14 |
namespace ICSharpCode.TextEditor.Actions |
|
15 |
{ |
|
16 |
public class CaretLeft : AbstractEditAction |
|
17 |
{ |
|
18 |
public override void Execute(TextArea textArea) |
|
19 |
{ |
|
20 |
TextLocation position = textArea.Caret.Position; |
|
21 |
List<FoldMarker> foldings = textArea.Document.FoldingManager.GetFoldedFoldingsWithEnd(position.Y); |
|
22 |
FoldMarker justBeforeCaret = null; |
|
23 |
foreach (FoldMarker fm in foldings) { |
|
24 |
if (fm.EndColumn == position.X) { |
|
25 |
justBeforeCaret = fm; |
|
26 |
break; // the first folding found is the folding with the smallest Startposition |
|
27 |
} |
|
28 |
} |
|
29 |
||
30 |
if (justBeforeCaret != null) { |
|
31 |
position.Y = justBeforeCaret.StartLine; |
|
32 |
position.X = justBeforeCaret.StartColumn; |
|
33 |
} else { |
|
34 |
if (position.X > 0) { |
|
35 |
--position.X; |
|
36 |
} else if (position.Y > 0) { |
|
37 |
LineSegment lineAbove = textArea.Document.GetLineSegment(position.Y - 1); |
|
38 |
position = new TextLocation(lineAbove.Length, position.Y - 1); |
|
39 |
} |
|
40 |
} |
|
41 |
||
42 |
textArea.Caret.Position = position; |
|
43 |
textArea.SetDesiredColumn(); |
|
44 |
} |
|
45 |
} |
|
46 |
||
47 |
public class CaretRight : AbstractEditAction |
|
48 |
{ |
|
49 |
public override void Execute(TextArea textArea) |
|
50 |
{ |
|
51 |
LineSegment curLine = textArea.Document.GetLineSegment(textArea.Caret.Line); |
|
52 |
TextLocation position = textArea.Caret.Position; |
|
53 |
List<FoldMarker> foldings = textArea.Document.FoldingManager.GetFoldedFoldingsWithStart(position.Y); |
|
54 |
FoldMarker justBehindCaret = null; |
|
55 |
foreach (FoldMarker fm in foldings) { |
|
56 |
if (fm.StartColumn == position.X) { |
|
57 |
justBehindCaret = fm; |
|
58 |
break; |
|
59 |
} |
|
60 |
} |
|
61 |
if (justBehindCaret != null) { |
|
62 |
position.Y = justBehindCaret.EndLine; |
|
63 |
position.X = justBehindCaret.EndColumn; |
|
64 |
} else { // no folding is interesting |
|
65 |
if (position.X < curLine.Length || textArea.TextEditorProperties.AllowCaretBeyondEOL) { |
|
66 |
++position.X; |
|
67 |
} else if (position.Y + 1 < textArea.Document.TotalNumberOfLines) { |
|
68 |
++position.Y; |
|
69 |
position.X = 0; |
|
70 |
} |
|
71 |
} |
|
72 |
textArea.Caret.Position = position; |
|
73 |
textArea.SetDesiredColumn(); |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
public class CaretUp : AbstractEditAction |
|
78 |
{ |
|
79 |
public override void Execute(TextArea textArea) |
|
80 |
{ |
|
81 |
TextLocation position = textArea.Caret.Position; |
|
82 |
int lineNr = position.Y; |
|
83 |
int visualLine = textArea.Document.GetVisibleLine(lineNr); |
|
84 |
if (visualLine > 0) { |
|
85 |
Point pos = new Point(textArea.TextView.GetDrawingXPos(lineNr, position.X), |
|
86 |
textArea.TextView.DrawingPosition.Y + (visualLine - 1) * textArea.TextView.FontHeight - textArea.TextView.TextArea.VirtualTop.Y); |
|
87 |
textArea.Caret.Position = textArea.TextView.GetLogicalPosition(pos); |
|
88 |
textArea.SetCaretToDesiredColumn(); |
|
89 |
} |
|
90 |
// if (textArea.Caret.Line > 0) { |
|
91 |
// textArea.SetCaretToDesiredColumn(textArea.Caret.Line - 1); |
|
92 |
// } |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
public class CaretDown : AbstractEditAction |
|
97 |
{ |
|
98 |
public override void Execute(TextArea textArea) |
|
99 |
{ |
|
100 |
TextLocation position = textArea.Caret.Position; |
|
101 |
int lineNr = position.Y; |
|
102 |
int visualLine = textArea.Document.GetVisibleLine(lineNr); |
|
103 |
if (visualLine < textArea.Document.GetVisibleLine(textArea.Document.TotalNumberOfLines)) { |
|
104 |
Point pos = new Point(textArea.TextView.GetDrawingXPos(lineNr, position.X), |
|
105 |
textArea.TextView.DrawingPosition.Y |
|
106 |
+ (visualLine + 1) * textArea.TextView.FontHeight |
|
107 |
- textArea.TextView.TextArea.VirtualTop.Y); |
|
108 |
textArea.Caret.Position = textArea.TextView.GetLogicalPosition(pos); |
|
109 |
textArea.SetCaretToDesiredColumn(); |
|
110 |
} |
|
111 |
// if (textArea.Caret.Line + 1 < textArea.Document.TotalNumberOfLines) { |
|
112 |
// textArea.SetCaretToDesiredColumn(textArea.Caret.Line + 1); |
|
113 |
// } |
|
114 |
} |
|
115 |
} |
|
116 |
||
117 |
public class WordRight : CaretRight |
|
118 |
{ |
|
119 |
public override void Execute(TextArea textArea) |
|
120 |
{ |
|
121 |
LineSegment line = textArea.Document.GetLineSegment(textArea.Caret.Position.Y); |
|
122 |
TextLocation oldPos = textArea.Caret.Position; |
|
123 |
TextLocation newPos; |
|
124 |
if (textArea.Caret.Column >= line.Length) { |
|
125 |
newPos = new TextLocation(0, textArea.Caret.Line + 1); |
|
126 |
} else { |
|
127 |
int nextWordStart = TextUtilities.FindNextWordStart(textArea.Document, textArea.Caret.Offset); |
|
128 |
newPos = textArea.Document.OffsetToPosition(nextWordStart); |
|
129 |
} |
|
130 |
||
131 |
// handle fold markers |
|
132 |
List<FoldMarker> foldings = textArea.Document.FoldingManager.GetFoldingsFromPosition(newPos.Y, newPos.X); |
|
133 |
foreach (FoldMarker marker in foldings) { |
|
134 |
if (marker.IsFolded) { |
|
135 |
if (oldPos.X == marker.StartColumn && oldPos.Y == marker.StartLine) { |
|
136 |
newPos = new TextLocation(marker.EndColumn, marker.EndLine); |
|
137 |
} else { |
|
138 |
newPos = new TextLocation(marker.StartColumn, marker.StartLine); |
|
139 |
} |
|
140 |
break; |
|
141 |
} |
|
142 |
} |
|
143 |
||
144 |
textArea.Caret.Position = newPos; |
|
145 |
textArea.SetDesiredColumn(); |
|
146 |
} |
|
147 |
} |
|
148 |
||
149 |
public class WordLeft : CaretLeft |
|
150 |
{ |
|
151 |
public override void Execute(TextArea textArea) |
|
152 |
{ |
|
153 |
TextLocation oldPos = textArea.Caret.Position; |
|
154 |
if (textArea.Caret.Column == 0) { |
|
155 |
base.Execute(textArea); |
|
156 |
} else { |
|
157 |
LineSegment line = textArea.Document.GetLineSegment(textArea.Caret.Position.Y); |
|
158 |
||
159 |
int prevWordStart = TextUtilities.FindPrevWordStart(textArea.Document, textArea.Caret.Offset); |
|
160 |
||
161 |
TextLocation newPos = textArea.Document.OffsetToPosition(prevWordStart); |
|
162 |
||
163 |
// handle fold markers |
|
164 |
List<FoldMarker> foldings = textArea.Document.FoldingManager.GetFoldingsFromPosition(newPos.Y, newPos.X); |
|
165 |
foreach (FoldMarker marker in foldings) { |
|
166 |
if (marker.IsFolded) { |
|
167 |
if (oldPos.X == marker.EndColumn && oldPos.Y == marker.EndLine) { |
|
168 |
newPos = new TextLocation(marker.StartColumn, marker.StartLine); |
|
169 |
} else { |
|
170 |
newPos = new TextLocation(marker.EndColumn, marker.EndLine); |
|
171 |
} |
|
172 |
break; |
|
173 |
} |
|
174 |
} |
|
175 |
textArea.Caret.Position = newPos; |
|
176 |
textArea.SetDesiredColumn(); |
|
177 |
} |
|
178 |
||
179 |
||
180 |
} |
|
181 |
} |
|
182 |
||
183 |
public class ScrollLineUp : AbstractEditAction |
|
184 |
{ |
|
185 |
public override void Execute(TextArea textArea) |
|
186 |
{ |
|
187 |
textArea.AutoClearSelection = false; |
|
188 |
||
189 |
textArea.MotherTextAreaControl.VScrollBar.Value = Math.Max(textArea.MotherTextAreaControl.VScrollBar.Minimum, |
|
190 |
textArea.VirtualTop.Y - textArea.TextView.FontHeight); |
|
191 |
} |
|
192 |
} |
|
193 |
||
194 |
public class ScrollLineDown : AbstractEditAction |
|
195 |
{ |
|
196 |
public override void Execute(TextArea textArea) |
|
197 |
{ |
|
198 |
textArea.AutoClearSelection = false; |
|
199 |
textArea.MotherTextAreaControl.VScrollBar.Value = Math.Min(textArea.MotherTextAreaControl.VScrollBar.Maximum, |
|
200 |
textArea.VirtualTop.Y + textArea.TextView.FontHeight); |
|
201 |
} |
|
202 |
} |
|
203 |
} |