本文整理汇总了C#中System.Windows.Documents.TextPointer.GetOffsetToPosition方法的典型用法代码示例。如果您正苦于以下问题:C# TextPointer.GetOffsetToPosition方法的具体用法?C# TextPointer.GetOffsetToPosition怎么用?C# TextPointer.GetOffsetToPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextPointer
的用法示例。
在下文中一共展示了TextPointer.GetOffsetToPosition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveAndHighlightNextNextMatch
/// <summary>
/// Move to the next highlight starting at the <paramref name="caretPosition"/>
/// </summary>
/// <param name="forward">true for next false for previous</param>
/// <param name="caretPosition">caret position</param>
/// <returns>the next highlight starting at the <paramref name="caretPosition"/></returns>
internal Run MoveAndHighlightNextNextMatch(bool forward, TextPointer caretPosition)
{
Debug.Assert(caretPosition != null, "a caret position is always valid");
Debug.Assert(caretPosition.Parent != null && caretPosition.Parent is Run, "a caret Parent is always a valid Run");
Run caretRun = (Run)caretPosition.Parent;
Run currentRun;
if (this.currentHighlightedMatch != null)
{
// restore the current highlighted background to plain highlighted
this.currentHighlightedMatch.Background = ParagraphSearcher.HighlightBrush;
}
// If the caret is in the end of a highlight we move to the adjacent run
// It has to be in the end because if there is a match at the beginning of the file
// and the caret has not been touched (so it is in the beginning of the file too)
// we want to highlight this first match.
// Considering the caller always set the caret to the end of the highlight
// The condition below works well for successive searchs
// We also need to move to the adjacent run if the caret is at the first run and we
// are moving backwards so that a search backwards when the first run is highlighted
// and the caret is at the beginning will wrap to the end
if ((!forward && IsFirstRun(caretRun)) ||
((caretPosition.GetOffsetToPosition(caretRun.ContentEnd) == 0) && ParagraphSearcher.Ishighlighted(caretRun)))
{
currentRun = ParagraphSearcher.GetNextRun(caretRun, forward);
}
else
{
currentRun = caretRun;
}
currentRun = ParagraphSearcher.GetNextMatch(currentRun, forward);
if (currentRun == null)
{
// if we could not find a next highlight wrap arround
currentRun = ParagraphSearcher.GetFirstOrLastRun(caretRun, forward);
currentRun = ParagraphSearcher.GetNextMatch(currentRun, forward);
}
this.currentHighlightedMatch = currentRun;
if (this.currentHighlightedMatch != null)
{
// restore the current highlighted background to current highlighted
this.currentHighlightedMatch.Background = ParagraphSearcher.CurrentHighlightBrush;
}
return currentRun;
}
示例2: Resolve
//---------------------------
// public static methods
//---------------------------
/// <summary>
/// resolves text effect on a text range to a list of text effect targets.
/// The method will walk the text and perform the following task:
/// 1) For each continous block of text, create a text effect targeting the scoping element
/// 2) For the text effect created, calculate the starting cp index and cp count for the effect
///
/// The method will create freezable copy of the TextEffect passed in and fill in
/// CharacterIndex and Count for the range.
/// </summary>
/// <param name="startPosition">starting text pointer</param>
/// <param name="endPosition">end text pointer</param>
/// <param name="effect">effect that is apply on the text</param>
public static TextEffectTarget[] Resolve(
TextPointer startPosition,
TextPointer endPosition,
TextEffect effect
)
{
if (effect == null)
throw new ArgumentNullException("effect");
ValidationHelper.VerifyPositionPair(startPosition, endPosition);
TextPointer effectStart = new TextPointer(startPosition);
// move to the first character symbol at or after Start position
MoveToFirstCharacterSymbol(effectStart);
TextEffect effectCopy;
List<TextEffectTarget> list = new List<TextEffectTarget>();
// we will now traverse the TOM and resolve text effects to the immediate parent
// of the characters. We are effectively applying the text effect onto
// block of continous text.
while (effectStart.CompareTo(endPosition) < 0)
{
// create a copy of the text effect
// so that we can set the CharacterIndex and Count
effectCopy = effect.Clone();
// create a position
TextPointer continuousTextEnd = new TextPointer(effectStart);
// move the position to the end of the continuous text block
MoveToFirstNonCharacterSymbol(continuousTextEnd, endPosition);
// make sure we are not out of the range
continuousTextEnd = (TextPointer)TextPointerBase.Min(continuousTextEnd, endPosition);
// set the character index to be the distance from the Start
// of this text block to the Start of the text container
effectCopy.PositionStart = effectStart.TextContainer.Start.GetOffsetToPosition(effectStart);
// count is the distance from the text block start to end
effectCopy.PositionCount = effectStart.GetOffsetToPosition(continuousTextEnd);
list.Add(
new TextEffectTarget(
effectStart.Parent,
effectCopy
)
);
// move the effectStart to the beginning of the next text block.
effectStart = continuousTextEnd;
MoveToFirstCharacterSymbol(effectStart);
}
return list.ToArray();
}
示例3: getDiffTextArea
public static void getDiffTextArea(ref TextPointer poiStart, ref TextPointer poiEnd, string lastText)
{
int tpCount = poiStart.GetOffsetToPosition(poiEnd);
int tpCountLast = poiEnd.GetOffsetToPosition(poiStart.DocumentEnd);
if (lastText == null || lastText == "" || (new TextRange(poiStart, poiEnd)).Text == "" ||
tpCount <= sc_maxTextChangeCheckCount)
{
poiEnd = poiStart;
return;
}
TextPointer tpHalf = poiStart.GetPositionAtOffset(tpCount / 2);
TextPointer tpLastHalf = poiEnd.GetPositionAtOffset(tpCountLast / 2);
switch (checkDiff(poiStart.DocumentStart, poiEnd, lastText))
{
case TextChangedType_E.OLDLARGER_TRUE:
{
poiStart = poiEnd;
poiEnd = tpLastHalf;
}
break;
case TextChangedType_E.OLDLARGER_FLASE:
{
poiEnd = tpHalf;
}
break;
case TextChangedType_E.NEWLARGER_TRUE:
{
poiStart = tpHalf;
poiEnd = tpHalf;
}
break;
case TextChangedType_E.NEWLARGER_FALSE:
{
poiEnd = tpHalf;
}
break;
default:
{
}
break;
}
getDiffTextArea(ref poiStart, ref poiEnd, lastText);
}