本文整理汇总了C#中ITextPointer.MoveToInsertionPosition方法的典型用法代码示例。如果您正苦于以下问题:C# ITextPointer.MoveToInsertionPosition方法的具体用法?C# ITextPointer.MoveToInsertionPosition怎么用?C# ITextPointer.MoveToInsertionPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextPointer
的用法示例。
在下文中一共展示了ITextPointer.MoveToInsertionPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: if
/// <summary>
/// </summary>
void ITextSelection.SetCaretToPosition(ITextPointer caretPosition, LogicalDirection direction, bool allowStopAtLineEnd, bool allowStopNearSpace)
{
// We need a pointer with appropriate direction,
// becasue it will be used in textRangeBase.Select method for
// pointer normalization.
caretPosition = caretPosition.CreatePointer(direction);
// Normalize the position in its logical direction - to get to text content over there.
caretPosition.MoveToInsertionPosition(direction);
// We need a pointer with the reverse direction to confirm
// the line wrapping position. So we can ensure Bidi caret navigation.
// Bidi can have the different caret position by setting the
// logical direction, so we have to only set the logical direction
// as the forward for the real line wrapping position.
ITextPointer reversePosition = caretPosition.CreatePointer(direction == LogicalDirection.Forward ? LogicalDirection.Backward : LogicalDirection.Forward);
// Check line wrapping condition
if (!allowStopAtLineEnd &&
((TextPointerBase.IsAtLineWrappingPosition(caretPosition, this.TextView) &&
TextPointerBase.IsAtLineWrappingPosition(reversePosition, this.TextView)) ||
TextPointerBase.IsNextToPlainLineBreak(caretPosition, LogicalDirection.Backward) ||
TextSchema.IsBreak(caretPosition.GetElementType(LogicalDirection.Backward))))
{
// Caret is at wrapping position, and we are not allowed to stay at end of line,
// so we choose forward direction to appear in the begiinning of a second line
caretPosition.SetLogicalDirection(LogicalDirection.Forward);
}
else
{
if (caretPosition.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.Text &&
caretPosition.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
{
// This is statistically most typical case. No "smartness" needed
// to choose standard Forward orientation for the caret.
// NOTE: By using caretPosition's direction we solve BiDi caret orientation case:
// The orietnation reflects a direction from where caret has been moved
// or orientation where mouse clicked. So we will stick with appropriate
// character.
// Nothing to do. The caretPosition is good to go.
}
else if (!allowStopNearSpace)
{
// There are some tags around, and we are not allowed to choose a side near to space.
// So we need to perform some content analysis.
char[] charBuffer = new char[1];
if (caretPosition.GetPointerContext(direction) == TextPointerContext.Text &&
caretPosition.GetTextInRun(direction, charBuffer, 0, 1) == 1 &&
Char.IsWhiteSpace(charBuffer[0]))
{
LogicalDirection oppositeDirection = direction == LogicalDirection.Forward ? LogicalDirection.Backward : LogicalDirection.Forward;
// Check formatting switch condition at this position
FlowDirection initialFlowDirection = (FlowDirection)caretPosition.GetValue(FrameworkElement.FlowDirectionProperty);
bool moved = caretPosition.MoveToInsertionPosition(oppositeDirection);
if (moved &&
initialFlowDirection == (FlowDirection)caretPosition.GetValue(FrameworkElement.FlowDirectionProperty) &&
(caretPosition.GetPointerContext(oppositeDirection) != TextPointerContext.Text ||
caretPosition.GetTextInRun(oppositeDirection, charBuffer, 0, 1) != 1 ||
!Char.IsWhiteSpace(charBuffer[0])))
{
// In the opposite direction we have a non-space
// character. So we choose that direction
direction = oppositeDirection;
caretPosition.SetLogicalDirection(direction);
}
}
}
}
// Now that orientation of a caretPosition is identified,
// build an empty selection at this position
TextRangeBase.BeginChange(this);
try
{
TextRangeBase.Select(this, caretPosition, caretPosition);
// Note how Select method works for the case of empty range:
// It creates a single instance TextPointer normalized and oriented
// in a direction taken from caretPosition:
ITextSelection thisSelection = this;
Invariant.Assert(thisSelection.Start.LogicalDirection == caretPosition.LogicalDirection); // orientation must be as passed
Invariant.Assert(this.IsEmpty);
//Invariant.Assert((object)thisSelection.Start == (object)thisSelection.End); // it must be the same instance of TextPointer
//Invariant.Assert(TextPointerBase.IsAtInsertionPosition(thisSelection.Start, caretPosition.LogicalDirection)); // normalization must be done in the same diredction as orientation
// Clear active positions when selection is empty
SetActivePositions(null, null);
}
finally
{
TextRangeBase.EndChange(this);
}
//.........这里部分代码省略.........
示例2: MoveToInsertionPosition
/// <summary>
/// This wrapper is to cover up a shortcoming in MoveToInsertionPosition code.
/// If the position is inside a Hyperlink, it is being moved out of the hyperlink and to the previous
/// insertion position which can be on the previous line (or unit) and this is creating problems
/// This is a temporary solution until we find a better solution to handle the case
/// There is also a related bug in MoveToLineBoundary: PS#1742102
/// </summary>
internal static bool MoveToInsertionPosition(ITextPointer position, LogicalDirection direction)
{
if (!position.TextContainer.IsReadOnly ||
(!TextPointerBase.IsAtNonMergeableInlineStart(position) && !TextPointerBase.IsAtNonMergeableInlineEnd(position)))
{
return position.MoveToInsertionPosition(direction);
}
return false;
}