Browse Source

VisualLine.GetVisualColumnFloor bugfix: for positions after the end of the line; return the line's end column.

4.0
Daniel Grunwald 15 years ago
parent
commit
783fc0024e
  1. 8
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLine.cs

8
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLine.cs

@ -53,7 +53,7 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -53,7 +53,7 @@ namespace ICSharpCode.AvalonEdit.Rendering
/// Gets the start offset of the VisualLine inside the document.
/// This is equivalent to <c>FirstDocumentLine.Offset</c>.
/// </summary>
public int StartOffset {
public int StartOffset {
get {
return FirstDocumentLine.Offset;
}
@ -323,6 +323,12 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -323,6 +323,12 @@ namespace ICSharpCode.AvalonEdit.Rendering
public int GetVisualColumnFloor(Point point)
{
TextLine textLine = GetTextLineByVisualYPosition(point.Y);
if (point.X > textLine.WidthIncludingTrailingWhitespace) {
// GetCharacterHitFromDistance returns a hit with FirstCharacterIndex=last character inline
// and TrailingLength=1 when clicking behind the line, so the floor function needs to handle this case
// specially end return the line's end column instead.
return GetTextLineVisualStartColumn(textLine) + textLine.Length;
}
CharacterHit ch = textLine.GetCharacterHitFromDistance(point.X);
return ch.FirstCharacterIndex;
}

Loading…
Cancel
Save