public void AssertCharacterHit(TextLine line, double distance, int index, int length) { var ch = line.GetCharacterHitFromDistance(distance); Assert.AreEqual(index, ch.FirstCharacterIndex, string.Format("FirstCharacterIndex, distance={0}", distance)); Assert.AreEqual(length, ch.TrailingLength, string.Format("TrailingLength, distance={0}", distance)); }
/// <summary> /// Gets the visual column from a document position (relative to top left of the document). /// </summary> public int GetVisualColumn(Point point) { TextLine textLine = GetTextLineByVisualYPosition(point.Y); CharacterHit ch = textLine.GetCharacterHitFromDistance(point.X); return(ch.FirstCharacterIndex + ch.TrailingLength); }
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); return(VisualLengthWithEndOfLineMarker + virtualX); } else { // GetCharacterHitFromDistance returns a hit with FirstCharacterIndex=last character in line // and TrailingLength=1 when clicking behind the line, so the floor function needs to handle this case // 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); }
public ICaretPosition MoveCaretToLocation(Double horizontalDistance) { Double offset = horizontalDistance - this.HorizontalOffset; if (offset < 0) { return(_textView.Caret.MoveTo(this.LineSpan.Start, CaretPlacement.LeftOfCharacter)); } if (this.NewlineLength == 0) { if (offset >= this.Width) { return(_textView.Caret.MoveTo(this.LineSpan.End, CaretPlacement.LeftOfCharacter)); } } else if (offset >= (this.Width - 7)) { return(_textView.Caret.MoveTo(this.LineSpan.End - this.NewlineLength, CaretPlacement.LeftOfCharacter)); } Int32 indexOfTextLineAtDistance = this.GetIndexOfTextLineAtDistance(offset); TextLine line = _textLines[indexOfTextLineAtDistance]; Double num3 = _textLineDistances[indexOfTextLineAtDistance]; CharacterHit characterHitFromDistance = line.GetCharacterHitFromDistance(offset - num3); Int32 bufferRelativePosition = this.GetBufferRelativePosition(characterHitFromDistance.FirstCharacterIndex); if (bufferRelativePosition > (this.LineSpan.End - this.NewlineLength)) { return(_textView.Caret.MoveTo(this.LineSpan.End - this.NewlineLength, CaretPlacement.LeftOfCharacter)); } return(_textView.Caret.MoveTo(bufferRelativePosition, (characterHitFromDistance.TrailingLength == 0) ? CaretPlacement.LeftOfCharacter : CaretPlacement.RightOfCharacter)); }
/// <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. /// </summary> public int GetVisualColumn(TextLine textLine, double xPos, bool allowVirtualSpace) { if (xPos > textLine.WidthIncludingTrailingWhitespace) { if (allowVirtualSpace && textLine == TextLines[TextLines.Count - 1]) { int virtualX = (int)Math.Round((xPos - textLine.WidthIncludingTrailingWhitespace) / textView.WideSpaceWidth); return(VisualLengthWithEndOfLineMarker + virtualX); } } CharacterHit ch = textLine.GetCharacterHitFromDistance(xPos); return(ch.FirstCharacterIndex + ch.TrailingLength); }
/// <summary> /// Gets the visual column from a document position (relative to top left of the document). /// If the user clicks between two visual columns, returns the first of those columns. /// </summary> 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); }
// Token: 0x06006632 RID: 26162 RVA: 0x001CBA64 File Offset: 0x001C9C64 internal CharacterHit GetTextPositionFromDistance(double distance) { double num = this.CalculateXOffsetShift(); if (this._line.HasOverflowed && this._owner.ParagraphProperties.TextTrimming != TextTrimming.None) { TextLine textLine = this._line.Collapse(new TextCollapsingProperties[] { this.GetCollapsingProps(this._wrappingWidth, this._owner.ParagraphProperties) }); Invariant.Assert(DoubleUtil.AreClose(num, 0.0)); Invariant.Assert(textLine.HasCollapsed, "Line has not been collapsed"); return(textLine.GetCharacterHitFromDistance(distance)); } return(this._line.GetCharacterHitFromDistance(distance - num)); }
// Token: 0x0600686C RID: 26732 RVA: 0x001D739C File Offset: 0x001D559C internal CharacterHit GetTextPositionFromDistance(int urDistance) { int num = this.CalculateUOffsetShift(); if (this._line.HasOverflowed && this.TextParagraph.Properties.TextTrimming != TextTrimming.None) { TextLine textLine = this._line.Collapse(new TextCollapsingProperties[] { this.GetCollapsingProps(this._wrappingWidth, this.TextParagraph.Properties) }); Invariant.Assert(num == 0); Invariant.Assert(textLine.HasCollapsed, "Line has not been collapsed"); return(textLine.GetCharacterHitFromDistance(TextDpi.FromTextDpi(urDistance))); } return(this._line.GetCharacterHitFromDistance(TextDpi.FromTextDpi(urDistance - num))); }
// Token: 0x06006605 RID: 26117 RVA: 0x001CAE4C File Offset: 0x001C904C internal override IInputElement InputHitTest(double offset) { DependencyObject dependencyObject = null; TextContainer textContainer = this._owner.TextContainer as TextContainer; double num = base.CalculateXOffsetShift(); if (textContainer != null) { CharacterHit characterHitFromDistance; if (this._line.HasOverflowed && this._owner.ParagraphProperties.TextTrimming != TextTrimming.None) { Invariant.Assert(DoubleUtil.AreClose(num, 0.0)); TextLine textLine = this._line.Collapse(new TextCollapsingProperties[] { base.GetCollapsingProps(this._wrappingWidth, this._owner.ParagraphProperties) }); Invariant.Assert(textLine.HasCollapsed, "Line has not been collapsed"); characterHitFromDistance = textLine.GetCharacterHitFromDistance(offset); } else { characterHitFromDistance = this._line.GetCharacterHitFromDistance(offset - num); } TextPointer textPointer = new TextPointer(this._owner.ContentStart, this.CalcPositionOffset(characterHitFromDistance), LogicalDirection.Forward); if (textPointer != null) { TextPointerContext pointerContext; if (characterHitFromDistance.TrailingLength == 0) { pointerContext = textPointer.GetPointerContext(LogicalDirection.Forward); } else { pointerContext = textPointer.GetPointerContext(LogicalDirection.Backward); } if (pointerContext == TextPointerContext.Text || pointerContext == TextPointerContext.ElementEnd) { dependencyObject = (textPointer.Parent as TextElement); } else if (pointerContext == TextPointerContext.ElementStart) { dependencyObject = textPointer.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward); } } } return(dependencyObject as IInputElement); }
// Token: 0x0600686D RID: 26733 RVA: 0x001D7434 File Offset: 0x001D5634 internal IInputElement InputHitTest(int urOffset) { DependencyObject dependencyObject = null; int num = this.CalculateUOffsetShift(); CharacterHit characterHitFromDistance; if (this._line.HasOverflowed && this.TextParagraph.Properties.TextTrimming != TextTrimming.None) { Invariant.Assert(num == 0); TextLine textLine = this._line.Collapse(new TextCollapsingProperties[] { this.GetCollapsingProps(this._wrappingWidth, this.TextParagraph.Properties) }); Invariant.Assert(textLine.HasCollapsed, "Line has not been collapsed"); characterHitFromDistance = textLine.GetCharacterHitFromDistance(TextDpi.FromTextDpi(urOffset)); } else { characterHitFromDistance = this._line.GetCharacterHitFromDistance(TextDpi.FromTextDpi(urOffset - num)); } int cp = this._paraClient.Paragraph.ParagraphStartCharacterPosition + characterHitFromDistance.FirstCharacterIndex + characterHitFromDistance.TrailingLength; TextPointer textPointer = TextContainerHelper.GetTextPointerFromCP(this._paraClient.Paragraph.StructuralCache.TextContainer, cp, LogicalDirection.Forward) as TextPointer; if (textPointer != null) { TextPointerContext pointerContext = textPointer.GetPointerContext((characterHitFromDistance.TrailingLength == 0) ? LogicalDirection.Forward : LogicalDirection.Backward); if (pointerContext == TextPointerContext.Text || pointerContext == TextPointerContext.ElementEnd) { dependencyObject = textPointer.Parent; } else if (pointerContext == TextPointerContext.ElementStart) { dependencyObject = textPointer.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward); } } return(dependencyObject as IInputElement); }
private bool ProcessLineForSelection([NotNull] TextLine line, [NotNull] TextMessage message, double bottomY, int alreadyDrawCharsForMessage, bool messageSelected) { Assert.ArgumentNotNull(line, "line"); Assert.ArgumentNotNull(message, "message"); bool alreadyAdded = _tempSelectionSettings.SelectedMessages.Contains(message); double selectionTop = _selectionSettings.SelectionStartPosition.Y; double selectionBottom = _selectionSettings.SelectionEndPosition.Y; if (selectionBottom < selectionTop) { selectionTop = _selectionSettings.SelectionEndPosition.Y; selectionBottom = _selectionSettings.SelectionStartPosition.Y; } double selectionLeft = _selectionSettings.SelectionStartPosition.X; double selectionRight = _selectionSettings.SelectionEndPosition.X; if (selectionLeft > selectionRight) { selectionLeft = _selectionSettings.SelectionEndPosition.X; selectionRight = _selectionSettings.SelectionStartPosition.X; } if (selectionBottom > ActualHeight) { selectionBottom = ActualHeight; } if (selectionTop < 0) { selectionTop = 0; } if (selectionRight > ActualWidth) { selectionRight = ActualWidth; } if (selectionLeft < 0) { selectionLeft = 0; } double lineBottom = bottomY; double lineTop = bottomY - line.Height; if (lineBottom < selectionBottom && lineTop > selectionTop && alreadyDrawCharsForMessage > 0) { if (!alreadyAdded) { _tempSelectionSettings.SelectedMessages.Add(message); } return(true); } if ((selectionBottom > lineTop && selectionBottom < lineBottom) && (selectionTop > lineTop && selectionTop < lineBottom)) { var leftCharIndex = line.GetCharacterHitFromDistance(selectionLeft).FirstCharacterIndex; var rightCharIndex = line.GetCharacterHitFromDistance(selectionRight).FirstCharacterIndex; if (rightCharIndex > leftCharIndex) { _tempSelectionSettings.SelectionStartCharacterNumber = leftCharIndex; _tempSelectionSettings.SelectionEndCharacterNumber = rightCharIndex; if (!alreadyAdded) { _tempSelectionSettings.SelectedMessages.Add(message); } } return(true); } if (selectionTop > lineTop && selectionTop < lineBottom) { double distance = _selectionSettings.SelectionEndPosition.X; if (selectionTop == _selectionSettings.SelectionStartPosition.Y) { distance = _selectionSettings.SelectionStartPosition.X; } var charIndex = line.GetCharacterHitFromDistance(distance).FirstCharacterIndex; _tempSelectionSettings.SelectionStartCharacterNumber = charIndex; if (!alreadyAdded) { _tempSelectionSettings.SelectedMessages.Add(message); } return(true); } if (selectionBottom > lineTop && selectionBottom < lineBottom) { double distance = _selectionSettings.SelectionEndPosition.X; if (selectionBottom == _selectionSettings.SelectionStartPosition.Y) { distance = _selectionSettings.SelectionStartPosition.X; } var charIndex = line.GetCharacterHitFromDistance(distance).FirstCharacterIndex; _tempSelectionSettings.SelectionEndCharacterNumber = charIndex; if (!alreadyAdded) { _tempSelectionSettings.SelectedMessages.Add(message); } return(true); } if (alreadyAdded && !messageSelected) { _tempSelectionSettings.SelectedMessages.Remove(message); } return(messageSelected); }