本文整理汇总了C#中ITextPointer.GetNextInsertionPosition方法的典型用法代码示例。如果您正苦于以下问题:C# ITextPointer.GetNextInsertionPosition方法的具体用法?C# ITextPointer.GetNextInsertionPosition怎么用?C# ITextPointer.GetNextInsertionPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextPointer
的用法示例。
在下文中一共展示了ITextPointer.GetNextInsertionPosition方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTextFlowDirection
//-----------------------------------------------------
//
// Static Methods
//
//------------------------------------------------------
#region Static Methods
/// <summary>
/// Determine the flow direction of the character referred to by the TextPointer.
/// If the context of the pointer is not text, we use the FlowDirection of the
/// containing element.
/// </summary>
/// <param name="pointer">pointer to get flow direction for</param>
/// <returns>positive value means LeftToRight, negative value means RightToLeft</returns>
private static FlowDirection GetTextFlowDirection(ITextPointer pointer)
{
Invariant.Assert(pointer != null, "Null pointer passed.");
Invariant.Assert(pointer.IsAtInsertionPosition, "Pointer is not an insertion position");
int sign = 0;
FlowDirection flowDirection;
LogicalDirection direction = pointer.LogicalDirection;
TextPointerContext currentContext = pointer.GetPointerContext(direction);
if ((currentContext == TextPointerContext.ElementEnd || currentContext == TextPointerContext.ElementStart) &&
!TextSchema.IsFormattingType(pointer.ParentType))
{
// If the current pointer (with its current direction) is at the start or end of a paragraph,
// the next insertion position will be in a separate paragraph. We can't determine direction
// based on the pointer rects in that case so we use the direction of the Paragraph.
flowDirection = (FlowDirection)pointer.GetValue(FlowDirectionProperty);
}
else
{
// We get the rects before and after the character following the current
// pointer and determine that character's flow direction based on the x-values
// of the rects. Because we use direction when requesting a rect, we should
// always get rects that are on the same line (except for the case above)
// Forward gravity for leading edge
Rect current = TextSelectionHelper.GetAnchorRectangle(pointer);
// Get insertion position after the current pointer
ITextPointer nextPointer = pointer.GetNextInsertionPosition(direction);
// There may be no more insertion positions in this document
if (nextPointer != null)
{
// Backward gravity for trailing edge
nextPointer = nextPointer.CreatePointer(direction == LogicalDirection.Backward ? LogicalDirection.Forward : LogicalDirection.Backward);
// Special case - for pointers at the end of a paragraph
// Actually the pointer is the last insertion position in the paragraph and the next insertion position is the first
// in the next paragraph. We handle this by detecting that the two pointers only have markup between them. If the
// markup was only formatting, there would also be content (because insertion position would move past a character).
if (direction == LogicalDirection.Forward)
{
if (currentContext == TextPointerContext.ElementEnd && nextPointer.GetPointerContext(nextPointer.LogicalDirection) == TextPointerContext.ElementStart)
{
return (FlowDirection)pointer.GetValue(FlowDirectionProperty);
}
}
else
{
if (currentContext == TextPointerContext.ElementStart && nextPointer.GetPointerContext(nextPointer.LogicalDirection) == TextPointerContext.ElementEnd)
{
return (FlowDirection)pointer.GetValue(FlowDirectionProperty);
}
}
Rect next = TextSelectionHelper.GetAnchorRectangle(nextPointer);
// Calculate the difference in x-coordinate between the two rects
if (next != Rect.Empty && current != Rect.Empty)
{
sign = Math.Sign(next.Left - current.Left);
// If we are looking at the character before the current pointer,
// we swap the difference since "next" was actually before "current"
if (direction == LogicalDirection.Backward)
{
sign = -(sign);
}
}
}
// If the rects were at the same x-coordinate or we couldn't get rects
// at all, we simply use the FlowDirection at that pointer.
if (sign == 0)
{
flowDirection = (FlowDirection)pointer.GetValue(FlowDirectionProperty);
}
else
{
// Positive is left to right, negative is right to left
flowDirection = (sign > 0 ? FlowDirection.LeftToRight : FlowDirection.RightToLeft);
}
}
//.........这里部分代码省略.........
示例2: AdjustPositionAtTableRowEnd
// If a position is currently at a Table row end, move it inside
// the last cell.
// This is useful when trying to navigate by line, because ITextView
// cannot handle the special end of row position.
private static ITextPointer AdjustPositionAtTableRowEnd(ITextPointer position)
{
if (TextPointerBase.IsAtRowEnd(position))
{
ITextPointer cellEnd = position.GetNextInsertionPosition(LogicalDirection.Backward);
if (cellEnd != null)
{
position = cellEnd;
}
}
return position;
}
示例3: GetAdjustedRangeEnd
// Returns a pointer of a text range adjusted so it does not affect
// the paragraph following the selection.
internal static ITextPointer GetAdjustedRangeEnd(ITextPointer rangeStart, ITextPointer rangeEnd)
{
if (rangeStart.CompareTo(rangeEnd) < 0 && rangeEnd.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
{
rangeEnd = rangeEnd.GetNextInsertionPosition(LogicalDirection.Backward);
if (rangeEnd == null)
{
rangeEnd = rangeStart; // Recover position for container start case - we never return null from this method.
}
}
else if (TextPointerBase.IsAfterLastParagraph(rangeEnd))
{
rangeEnd = rangeEnd.GetInsertionPosition(LogicalDirection.Backward);
}
return rangeEnd;
}
示例4: AdjustMovingPositionForSelectDownByLine
// Helper for OnSelectDownByLine. Updates the selection moving position
// during select down by line.
private static void AdjustMovingPositionForSelectDownByLine(TextEditor This, ITextPointer newMovingPosition, ITextPointer originalMovingPosition, double suggestedX)
{
int newComparedToOld = newMovingPosition.CompareTo(originalMovingPosition);
// Note: we compare orientations of equal positions to handle a case
// when original position was at the end of line (after its linebreak with backward orientation)
// as a result of Shift+End selection; and the new position is in the beginning of the next line,
// which is essentially the same position but oriented differently.
// In such a case the new position is good enough to go there.
// We certainly don't want to go to the end of the document in this case.
if (newComparedToOld > 0 || newComparedToOld == 0 && newMovingPosition.LogicalDirection != originalMovingPosition.LogicalDirection)
{
// We have another line in a given direction; move to it
// If the destination exactly preceeds a line break, expand to include
// the line break if we haven't reached our desired suggestedX.
if (TextPointerBase.IsNextToAnyBreak(newMovingPosition, LogicalDirection.Forward) ||
newMovingPosition.GetNextInsertionPosition(LogicalDirection.Forward) == null)
{
double newPositionX = GetAbsoluteXOffset(This.TextView, newMovingPosition);
FlowDirection paragraphFlowDirection = GetScopingParagraphFlowDirection(newMovingPosition);
FlowDirection controlFlowDirection = This.UiScope.FlowDirection;
if ((paragraphFlowDirection == controlFlowDirection && newPositionX < suggestedX) ||
(paragraphFlowDirection != controlFlowDirection && newPositionX > suggestedX))
{
newMovingPosition = newMovingPosition.GetInsertionPosition(LogicalDirection.Forward);
newMovingPosition = newMovingPosition.GetNextInsertionPosition(LogicalDirection.Forward);
// If we're at the last Paragraph, move to document end to include
// the final paragraph break.
if (newMovingPosition == null)
{
newMovingPosition = originalMovingPosition.TextContainer.End;
}
newMovingPosition = newMovingPosition.GetFrozenPointer(LogicalDirection.Backward);
}
}
ExtendSelectionAndBringIntoView(newMovingPosition, This);
}
else
{
// Remember where we were so that we can return if a line up follows.
if (This._NextLineAdvanceMovingPosition == null)
{
This._NextLineAdvanceMovingPosition = originalMovingPosition;
This._IsNextLineAdvanceMovingPositionAtDocumentHead = false;
}
// No more lines in this direction. Move to end of current line.
newMovingPosition = GetPositionAtLineEnd(originalMovingPosition);
if (newMovingPosition.GetNextInsertionPosition(LogicalDirection.Forward) == null)
{
// Move to the final implicit line at end-of-doc.
newMovingPosition = newMovingPosition.TextContainer.End;
}
ExtendSelectionAndBringIntoView(newMovingPosition, This);
}
}
示例5: HasNeighboringSeparatorChar
// Returns true iff there is a character in the specificed direction adjacent to a
// position which is classified as a separator. This is useful in detecting word breaks.
private static bool HasNeighboringSeparatorChar(ITextPointer position, LogicalDirection direction)
{
ITextPointer nextPosition = position.GetNextInsertionPosition(direction);
if (nextPosition == null)
{
return true;
}
if (position.CompareTo(nextPosition) > 0)
{
ITextPointer temp = position;
position = nextPosition;
nextPosition = temp;
}
int maxCharCount = position.GetOffsetToPosition(nextPosition);
char[] findText = new char[maxCharCount];
int []findTextPositionMap = new int[maxCharCount + 1];
int findTextLength;
findTextLength = SetFindTextAndFindTextPositionMap(
position,
nextPosition,
position.CreatePointer() /* need unfrozen pointer */,
LogicalDirection.Forward,
false /* matchLast */,
findText,
findTextPositionMap);
if (findTextLength == 0)
{
return true;
}
bool hasNeighboringSeparatorChar;
if (direction == LogicalDirection.Forward)
{
hasNeighboringSeparatorChar = IsSeparatorChar(findText[0]);
}
else
{
hasNeighboringSeparatorChar = IsSeparatorChar(findText[findTextLength-1]);
}
return hasNeighboringSeparatorChar;
}