|
|
|
|
@ -307,13 +307,21 @@ namespace ICSharpCode.AvalonEdit.Rendering
@@ -307,13 +307,21 @@ namespace ICSharpCode.AvalonEdit.Rendering
|
|
|
|
|
/// Gets the text line containing the specified visual column.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public TextLine GetTextLine(int visualColumn) |
|
|
|
|
{ |
|
|
|
|
return GetTextLine(visualColumn, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the text line containing the specified visual column.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public TextLine GetTextLine(int visualColumn, bool isAtEndOfLine) |
|
|
|
|
{ |
|
|
|
|
if (visualColumn < 0) |
|
|
|
|
throw new ArgumentOutOfRangeException("visualColumn"); |
|
|
|
|
if (visualColumn >= VisualLengthWithEndOfLineMarker) |
|
|
|
|
return TextLines[TextLines.Count - 1]; |
|
|
|
|
foreach (TextLine line in TextLines) { |
|
|
|
|
if (visualColumn < line.Length) |
|
|
|
|
if (isAtEndOfLine ? visualColumn <= line.Length : visualColumn < line.Length) |
|
|
|
|
return line; |
|
|
|
|
else |
|
|
|
|
visualColumn -= line.Length; |
|
|
|
|
@ -437,6 +445,14 @@ namespace ICSharpCode.AvalonEdit.Rendering
@@ -437,6 +445,14 @@ namespace ICSharpCode.AvalonEdit.Rendering
|
|
|
|
|
return GetVisualColumn(GetTextLineByVisualYPosition(point.Y), point.X, allowVirtualSpace); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal int GetVisualColumn(Point point, bool allowVirtualSpace, out bool isAtEndOfLine) |
|
|
|
|
{ |
|
|
|
|
var textLine = GetTextLineByVisualYPosition(point.Y); |
|
|
|
|
int vc = GetVisualColumn(textLine, point.X, allowVirtualSpace); |
|
|
|
|
isAtEndOfLine = (vc >= GetTextLineVisualStartColumn(textLine) + textLine.Length); |
|
|
|
|
return vc; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the visual column from a document position (relative to top left of the document).
|
|
|
|
|
/// If the user clicks between two visual columns, rounds to the nearest column.
|
|
|
|
|
@ -497,9 +513,16 @@ namespace ICSharpCode.AvalonEdit.Rendering
@@ -497,9 +513,16 @@ namespace ICSharpCode.AvalonEdit.Rendering
|
|
|
|
|
/// If the user clicks between two visual columns, returns the first of those columns.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetVisualColumnFloor(Point point, bool allowVirtualSpace) |
|
|
|
|
{ |
|
|
|
|
bool tmp; |
|
|
|
|
return GetVisualColumnFloor(point, allowVirtualSpace, out tmp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal int GetVisualColumnFloor(Point point, bool allowVirtualSpace, out bool isAtEndOfLine) |
|
|
|
|
{ |
|
|
|
|
TextLine textLine = GetTextLineByVisualYPosition(point.Y); |
|
|
|
|
if (point.X > textLine.WidthIncludingTrailingWhitespace) { |
|
|
|
|
isAtEndOfLine = true; |
|
|
|
|
if (allowVirtualSpace && textLine == TextLines[TextLines.Count - 1]) { |
|
|
|
|
// clicking virtual space in the last line
|
|
|
|
|
int virtualX = (int)((point.X - textLine.WidthIncludingTrailingWhitespace) / textView.WideSpaceWidth); |
|
|
|
|
@ -510,11 +533,47 @@ namespace ICSharpCode.AvalonEdit.Rendering
@@ -510,11 +533,47 @@ namespace ICSharpCode.AvalonEdit.Rendering
|
|
|
|
|
// specially and return the line's end column instead.
|
|
|
|
|
return GetTextLineVisualStartColumn(textLine) + textLine.Length; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
isAtEndOfLine = false; |
|
|
|
|
} |
|
|
|
|
CharacterHit ch = textLine.GetCharacterHitFromDistance(point.X); |
|
|
|
|
return ch.FirstCharacterIndex; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the text view position from the specified visual position.
|
|
|
|
|
/// If the position is within a character, it is rounded to the next character boundary.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="visualPosition">The position in WPF device-independent pixels relative
|
|
|
|
|
/// to the top left corner of the document.</param>
|
|
|
|
|
/// <param name="allowVirtualSpace">Controls whether positions in virtual space may be returned.</param>
|
|
|
|
|
public TextViewPosition GetTextViewPosition(Point visualPosition, bool allowVirtualSpace) |
|
|
|
|
{ |
|
|
|
|
bool isAtEndOfLine; |
|
|
|
|
int visualColumn = GetVisualColumn(visualPosition, allowVirtualSpace, out isAtEndOfLine); |
|
|
|
|
int documentOffset = GetRelativeOffset(visualColumn) + this.FirstDocumentLine.Offset; |
|
|
|
|
TextViewPosition pos = new TextViewPosition(this.Document.GetLocation(documentOffset), visualColumn); |
|
|
|
|
pos.IsAtEndOfLine = isAtEndOfLine; |
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the text view position from the specified visual position.
|
|
|
|
|
/// If the position is inside a character, the position in front of the character is returned.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="visualPosition">The position in WPF device-independent pixels relative
|
|
|
|
|
/// to the top left corner of the document.</param>
|
|
|
|
|
/// <param name="allowVirtualSpace">Controls whether positions in virtual space may be returned.</param>
|
|
|
|
|
public TextViewPosition GetTextViewPositionFloor(Point visualPosition, bool allowVirtualSpace) |
|
|
|
|
{ |
|
|
|
|
bool isAtEndOfLine; |
|
|
|
|
int visualColumn = GetVisualColumnFloor(visualPosition, allowVirtualSpace, out isAtEndOfLine); |
|
|
|
|
int documentOffset = GetRelativeOffset(visualColumn) + this.FirstDocumentLine.Offset; |
|
|
|
|
TextViewPosition pos = new TextViewPosition(this.Document.GetLocation(documentOffset), visualColumn); |
|
|
|
|
pos.IsAtEndOfLine = isAtEndOfLine; |
|
|
|
|
return pos; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets whether the visual line was disposed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
|