本文整理汇总了C#中ITextPointer.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# ITextPointer.CompareTo方法的具体用法?C# ITextPointer.CompareTo怎么用?C# ITextPointer.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextPointer
的用法示例。
在下文中一共展示了ITextPointer.CompareTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SpellingError
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
// Creates a new instance.
internal SpellingError(Speller speller, ITextPointer start, ITextPointer end)
{
Invariant.Assert(start.CompareTo(end) < 0);
_speller = speller;
_start = start.GetFrozenPointer(LogicalDirection.Forward);
_end = end.GetFrozenPointer(LogicalDirection.Backward);
}
示例2: TextSegment
/// <summary>
/// Constructor.
/// </summary>
/// <param name="startPosition">
/// Position preceeding the TextSegment's content.
/// </param>
/// <param name="endPosition">
/// Position following the TextSegment's content.
/// </param>
/// <param name="preserveLogicalDirection">
/// Whether preserves LogicalDirection of start and end positions.
/// </param>
internal TextSegment(ITextPointer startPosition, ITextPointer endPosition, bool preserveLogicalDirection)
{
ValidationHelper.VerifyPositionPair(startPosition, endPosition);
if (startPosition.CompareTo(endPosition) == 0)
{
// To preserve segment emptiness
// we use the same instance of a pointer
// for both segment ends.
_start = startPosition.GetFrozenPointer(startPosition.LogicalDirection);
_end = _start;
}
else
{
Invariant.Assert(startPosition.CompareTo(endPosition) < 0);
_start = startPosition.GetFrozenPointer(preserveLogicalDirection ? startPosition.LogicalDirection : LogicalDirection.Backward);
_end = endPosition.GetFrozenPointer(preserveLogicalDirection ? endPosition.LogicalDirection : LogicalDirection.Forward);
}
}
示例3: Contains
//-----------------------------------------------------
//
// ITextRange Methods
//
//-----------------------------------------------------
#region ITextRange Methods
//......................................................
//
// Selection Building
//
//......................................................
/// <summary>
/// </summary>
//
internal static bool Contains(ITextRange thisRange, ITextPointer textPointer)
{
NormalizeRange(thisRange);
if (textPointer == null)
{
throw new ArgumentNullException("textPointer");
}
if (textPointer.TextContainer != thisRange.Start.TextContainer)
{
throw new ArgumentException(SR.Get(SRID.NotInAssociatedTree), "textPointer");
}
// Correct position normalization on range boundary so that
// our test would not depend on what side of formatting tags
// pointer is located.
if (textPointer.CompareTo(thisRange.Start) < 0)
{
textPointer = textPointer.GetFormatNormalizedPosition(LogicalDirection.Forward);
}
else if (textPointer.CompareTo(thisRange.End) > 0)
{
textPointer = textPointer.GetFormatNormalizedPosition(LogicalDirection.Backward);
}
// Check if at least one segment contains this position.
for (int i = 0; i < thisRange._TextSegments.Count; i++)
{
if (thisRange._TextSegments[i].Contains(textPointer))
{
return true;
}
}
return false;
}
示例4: VerifyPositionPair
// Verifies two positions are safe to use as a logical text span.
//
// Throws ArgumentNullException if startPosition == null || endPosition == null
// ArgumentException if startPosition.TextContainer != endPosition.TextContainer or
// startPosition > endPosition
internal static void VerifyPositionPair(ITextPointer startPosition, ITextPointer endPosition)
{
if (startPosition == null)
{
throw new ArgumentNullException("startPosition");
}
if (endPosition == null)
{
throw new ArgumentNullException("endPosition");
}
if (startPosition.TextContainer != endPosition.TextContainer)
{
throw new ArgumentException(SR.Get(SRID.InDifferentTextContainers, "startPosition", "endPosition"));
}
if (startPosition.CompareTo(endPosition) > 0)
{
throw new ArgumentException(SR.Get(SRID.BadTextPositionOrder, "startPosition", "endPosition"));
}
}
示例5: GetTightBoundingGeometryFromTextPositions
internal Geometry GetTightBoundingGeometryFromTextPositions(ITextPointer startPosition, ITextPointer endPosition, Rect visibleRect)
{
Debug.Assert( TableParagraph.Table != null
&& CalculatedColumns != null );
Geometry geometry = null;
PTS.FSTABLEROWDESCRIPTION[] arrayTableRowDesc;
PTS.FSKUPDATE fskupdTable;
PTS.FSRECT rectTable;
if (QueryTableDetails(out arrayTableRowDesc, out fskupdTable, out rectTable))
{
bool passedEndPosition = false;
for (int iR = 0; iR < arrayTableRowDesc.Length && !passedEndPosition; ++iR)
{
PTS.FSKUPDATE[] arrayUpdate;
IntPtr[] arrayFsCell;
PTS.FSTABLEKCELLMERGE[] arrayTableCellMerge;
QueryRowDetails(
arrayTableRowDesc[iR].pfstablerow,
out arrayFsCell,
out arrayUpdate,
out arrayTableCellMerge);
for (int iC = 0; iC < arrayFsCell.Length; ++iC)
{
if (arrayFsCell[iC] == IntPtr.Zero)
{
// paginated case - cell may be null
continue;
}
CellParaClient cpc = (CellParaClient)(PtsContext.HandleToObject(arrayFsCell[iC]));
if (endPosition.CompareTo(cpc.Cell.ContentStart) <= 0)
{
// remember that at least one cell in this row starts after the range's end.
// in this case it is safe to break after this whole row is processed.
// Note: can not break right away because cells in arrayFsCell come not
// necessarily in backing store (cp) order.
passedEndPosition = true;
}
else
{
if (startPosition.CompareTo(cpc.Cell.ContentEnd) <= 0)
{
Geometry cellGeometry = cpc.GetTightBoundingGeometryFromTextPositions(startPosition, endPosition, visibleRect);
CaretElement.AddGeometry(ref geometry, cellGeometry);
}
}
}
}
}
if (geometry != null)
{
geometry = Geometry.Combine(geometry, Visual.Clip, GeometryCombineMode.Intersect, null);
}
return geometry;
}
示例6: GetTextSegmentValues
/// <summary>
/// Gets start and end offset for a text segment but clamps those values to the start and end
/// of a given element. This way if a large text range is being resolved on a node that only contains
/// a portion of the text range (such as a paragraph) the result only includes the content in that node.
/// </summary>
private void GetTextSegmentValues(TextSegment segment, ITextPointer elementStart, ITextPointer elementEnd, out int startOffset, out int endOffset)
{
startOffset = 0;
endOffset = 0;
if (elementStart.CompareTo(segment.Start) >= 0)
{
// segment starts before the start of the element
startOffset = 0;
}
else
{
startOffset = elementStart.GetOffsetToPosition(segment.Start);
}
if (elementEnd.CompareTo(segment.End) >= 0)
{
endOffset = elementStart.GetOffsetToPosition(segment.End);
}
else
{
// segment ends after the end of the element
endOffset = elementStart.GetOffsetToPosition(elementEnd);
}
}
示例7: MarkRange
// Marks a text run as clean or dirty.
private void MarkRange(ITextPointer start, ITextPointer end, RunType runType)
{
if (start.CompareTo(end) == 0)
{
return;
}
int startIndex;
int endIndex;
Invariant.Assert(runType == RunType.Clean || runType == RunType.Dirty);
startIndex = FindIndex(start.CreateStaticPointer(), LogicalDirection.Forward);
endIndex = FindIndex(end.CreateStaticPointer(), LogicalDirection.Backward);
// We don't expect start/end to ever point off the edge of the document.
Invariant.Assert(startIndex >= 0);
Invariant.Assert(endIndex >= 0);
// Remove wholly covered runs.
if (startIndex + 1 < endIndex)
{
// Tell the HighlightLayer about any error runs that are going away.
for (int i = startIndex + 1; i < endIndex; i++)
{
NotifyHighlightLayerBeforeRunChange(i);
}
_runList.RemoveRange(startIndex + 1, endIndex - startIndex - 1);
endIndex = startIndex + 1;
}
// Merge the bordering edge runs.
if (startIndex == endIndex)
{
// We're contained in a single run.
AddRun(startIndex, start, end, runType);
}
else
{
// We cover two runs.
Invariant.Assert(startIndex == endIndex - 1);
// Handle the first run.
AddRun(startIndex, start, end, runType);
// Recalc endIndex, since it may have changed in the merge.
endIndex = FindIndex(end.CreateStaticPointer(), LogicalDirection.Backward);
Invariant.Assert(endIndex >= 0);
// Handle the second run.
AddRun(endIndex, start, end, runType);
}
}
示例8: IdentifyWordsOnSelectionEnds
// Part of ExtendSelectionByMouse method:
// Identifies words on selection ends.
private void IdentifyWordsOnSelectionEnds(ITextPointer anchorPosition, ITextPointer cursorPosition, bool forceWordSelection, out TextSegment anchorWordRange, out TextSegment cursorWordRange)
{
if (forceWordSelection)
{
anchorWordRange = TextPointerBase.GetWordRange(anchorPosition);
cursorWordRange = TextPointerBase.GetWordRange(cursorPosition, cursorPosition.LogicalDirection);
}
else
{
// Define whether word adjustment is allowed. Pressing Shift+Control prevents from auto-word expansion.
bool disableWordExpansion = _textEditor.AutoWordSelection == false || ((Keyboard.Modifiers & ModifierKeys.Shift) != 0 && (Keyboard.Modifiers & ModifierKeys.Control) != 0);
if (disableWordExpansion)
{
anchorWordRange = new TextSegment(anchorPosition, anchorPosition);
cursorWordRange = new TextSegment(cursorPosition, cursorPosition);
}
else
{
// Autoword expansion heuristics
// -----------------------------
// Word autoword heuristics:
// a) After active end returned to selected area, autoword expansion on active end is disabled
// b) After active end returned to the very first word, expansion on anchor word is disabled either
// We do this though only if selection has crossed initial word boundary at least once.
// c) After active end crosses new word, autoword expansion of active end is enabled again
// Calculate a word range for anchor position
anchorWordRange = TextPointerBase.GetWordRange(anchorPosition);
// Check if we re-entering selection or moving outside
// and set autoexpansion flags accordingly
if (_previousCursorPosition != null &&
(anchorPosition.CompareTo(cursorPosition) < 0 && cursorPosition.CompareTo(_previousCursorPosition) < 0 ||
_previousCursorPosition.CompareTo(cursorPosition) < 0 && cursorPosition.CompareTo(anchorPosition) < 0))
{
// Re-entering selection.
// Store position of reentering
_reenterPosition = cursorPosition.CreatePointer();
// When re-entering reaches initial word, disable word expansion on anchor end either
if (_anchorWordRangeHasBeenCrossedOnce && anchorWordRange.Contains(cursorPosition))
{
_allowWordExpansionOnAnchorEnd = false;
}
}
else
{
// Extending the selection.
// Check if we are crossing a boundary of last reentered word to re-enable word expansion on moving end
if (_reenterPosition != null)
{
TextSegment lastReenteredWordRange = TextPointerBase.GetWordRange(_reenterPosition);
if (!lastReenteredWordRange.Contains(cursorPosition))
{
_reenterPosition = null;
}
}
}
// Identify expanded range on both ends
//
if (anchorWordRange.Contains(cursorPosition) ||
anchorWordRange.Contains(cursorPosition.GetInsertionPosition(LogicalDirection.Forward)) ||
anchorWordRange.Contains(cursorPosition.GetInsertionPosition(LogicalDirection.Backward)))
{
// Selection does not cross word boundary, so shrink selection to exact anchor/cursor positions
anchorWordRange = new TextSegment(anchorPosition, anchorPosition);
cursorWordRange = new TextSegment(cursorPosition, cursorPosition);
}
else
{
// Selection crosses word boundary.
_anchorWordRangeHasBeenCrossedOnce = true;
if (!_allowWordExpansionOnAnchorEnd || //
TextPointerBase.IsAtWordBoundary(anchorPosition, /*insideWordDirection:*/LogicalDirection.Forward))
{
// We collapse anchorPosition in two cases:
// If we have been re-entering the initial word before -
// then we treat it as an indicator that user wants exact position on anchor end
// or
// if selection starts exactly on word boundary -
// then we should not include the following word (when selection extends backward).
//
// So in the both cases we collapse anchorWordRange to exact _anchorPosition
anchorWordRange = new TextSegment(anchorPosition, anchorPosition);
}
if (TextPointerBase.IsAfterLastParagraph(cursorPosition) ||
TextPointerBase.IsAtWordBoundary(cursorPosition, /*insideWordDirection:*/LogicalDirection.Forward))
{
cursorWordRange = new TextSegment(cursorPosition, cursorPosition);
}
//.........这里部分代码省略.........
示例9: ConvertToMovingEdge
// Uses the current selection state to match an ITextPointer to one of the possible
// moving position edges.
private MovingEdge ConvertToMovingEdge(ITextPointer anchorPosition, ITextPointer movingPosition)
{
ITextSelection thisSelection = this;
MovingEdge movingEdge;
if (thisSelection.IsEmpty)
{
// Empty selections have no moving edge.
movingEdge = MovingEdge.None;
}
else if (thisSelection.TextSegments.Count < 2)
{
// Simple text selections move opposite their anchor positions.
movingEdge = (anchorPosition.CompareTo(movingPosition) <= 0) ? MovingEdge.End : MovingEdge.Start;
}
else
{
// Table selection. Look for an exact match.
if (movingPosition.CompareTo(thisSelection.Start) == 0)
{
movingEdge = MovingEdge.Start;
}
else if (movingPosition.CompareTo(thisSelection.End) == 0)
{
movingEdge = MovingEdge.End;
}
else if (movingPosition.CompareTo(thisSelection.TextSegments[0].End) == 0)
{
movingEdge = MovingEdge.StartInner;
}
else if (movingPosition.CompareTo(thisSelection.TextSegments[thisSelection.TextSegments.Count-1].Start) == 0)
{
movingEdge = MovingEdge.EndInner;
}
else
{
movingEdge = (anchorPosition.CompareTo(movingPosition) <= 0) ? MovingEdge.End : MovingEdge.Start;
}
}
return movingEdge;
}
示例10: WalkTextRun
// GetText handler for text runs.
private static bool WalkTextRun(ITextPointer navigator, ITextPointer limit, char[] text, int cchReq, ref int charsCopied, UnsafeNativeMethods.TS_RUNINFO[] runInfo, int cRunInfoReq, ref int cRunInfoRcv)
{
int runCount;
int offset;
bool hitLimit;
Invariant.Assert(navigator.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text);
Invariant.Assert(limit == null || navigator.CompareTo(limit) <= 0);
hitLimit = false;
if (cchReq > 0)
{
runCount = TextPointerBase.GetTextWithLimit(navigator, LogicalDirection.Forward, text, charsCopied, Math.Min(cchReq, text.Length - charsCopied), limit);
navigator.MoveByOffset(runCount);
charsCopied += runCount;
hitLimit = (text.Length == charsCopied) || (limit != null && navigator.CompareTo(limit) == 0);
}
else
{
// Caller doesn't want text, just run info.
// Advance the navigator.
runCount = navigator.GetTextRunLength(LogicalDirection.Forward);
navigator.MoveToNextContextPosition(LogicalDirection.Forward);
// If the caller passed in a non-null limit, backup to the limit if
// we've passed it.
if (limit != null)
{
if (navigator.CompareTo(limit) >= 0)
{
offset = limit.GetOffsetToPosition(navigator);
Invariant.Assert(offset >= 0 && offset <= runCount, "Bogus offset -- extends past run!");
runCount -= offset;
navigator.MoveToPosition(limit);
hitLimit = true;
}
}
}
if (cRunInfoReq > 0 && runCount > 0)
{
// Be sure to merge this text run with the previous run, if they are both text runs.
// (A good robustness fix would be to make cicero handle this, if we ever get the chance.)
if (cRunInfoRcv > 0 && runInfo[cRunInfoRcv - 1].type == UnsafeNativeMethods.TsRunType.TS_RT_PLAIN)
{
runInfo[cRunInfoRcv - 1].count += runCount;
}
else
{
runInfo[cRunInfoRcv].count = runCount;
runInfo[cRunInfoRcv].type = UnsafeNativeMethods.TsRunType.TS_RT_PLAIN;
cRunInfoRcv++;
}
}
return hitLimit;
}
示例11: MoveToNextInsertionPosition
/// <summary>
/// Advances this TextNavigator by a count number of characters.
/// </summary>
/// <param name="thisNavigator">ITextPointer to advance.</param>
/// <param name="direction">
/// A direction in which to search a next characters.
/// </param>
/// <returns>
/// True if the navigator is advanced, false if the end of document is
/// encountered and the navigator is not repositioned.
/// </returns>
/// <remarks>
/// A "character" in this context is a sequence of one or several text
/// symbols: one or more Unicode code points may be a character, every
/// embedded object is a character, a sequence of closing block tags
/// followed by opening block tags may also be a unit. Formatting tags
/// do not contribute in any unit.
/// </remarks>
internal static bool MoveToNextInsertionPosition(ITextPointer thisNavigator, LogicalDirection direction)
{
Invariant.Assert(!thisNavigator.IsFrozen, "Can't reposition a frozen pointer!");
bool moved = true;
int increment = direction == LogicalDirection.Forward ? +1 : -1;
ITextPointer initialPosition = thisNavigator.CreatePointer();
if (!IsAtInsertionPosition(thisNavigator))
{
// If the TextPointer is not currently at an insertion position,
// move the TextPointer to the next insertion position in
// the indicated direction, just like the MoveToInsertionPosition method.
if (!MoveToInsertionPosition(thisNavigator, direction))
{
// No insertion position in all content. MoveToInsertionPosition() guarantees that navigator is moved back to initial position.
moved = false;
goto Exit;
}
if ((direction == LogicalDirection.Forward && initialPosition.CompareTo(thisNavigator) < 0) ||
(direction == LogicalDirection.Backward && thisNavigator.CompareTo(initialPosition) < 0))
{
// We have found an insertion position in requested direction.
goto Exit;
}
}
// Start with skipping character formatting tags in this direction
while (TextSchema.IsFormattingType(thisNavigator.GetElementType(direction)))
{
thisNavigator.MoveByOffset(increment);
}
do
{
if (thisNavigator.GetPointerContext(direction) != TextPointerContext.None)
{
thisNavigator.MoveByOffset(increment);
}
else
{
// No insertion position in this direction; Move back
thisNavigator.MoveToPosition(initialPosition);
moved = false;
goto Exit;
}
}
while (!IsAtInsertionPosition(thisNavigator));
// We must leave position normalized in backward direction
if (direction == LogicalDirection.Backward)
{
// For this we must skip character formatting tags if we have any
while (TextSchema.IsFormattingType(thisNavigator.GetElementType(direction)))
{
thisNavigator.MoveByOffset(increment);
}
// However if it is block start we should back off
TextPointerContext context = thisNavigator.GetPointerContext(direction);
if (context == TextPointerContext.ElementStart || context == TextPointerContext.None)
{
increment = -increment;
while (TextSchema.IsFormattingType(thisNavigator.GetElementType(LogicalDirection.Forward))
&& !IsAtInsertionPosition(thisNavigator))
{
thisNavigator.MoveByOffset(increment);
}
}
}
Exit:
if (moved)
{
if (direction == LogicalDirection.Forward)
{
Invariant.Assert(thisNavigator.CompareTo(initialPosition) > 0, "thisNavigator is expected to be moved from initialPosition - 1");
}
//.........这里部分代码省略.........
示例12: GetTextWithLimit
// Like GetText, excepts also accepts a limit parameter -- no text is returned past
// this second position.
// limit may be null, in which case it is ignored.
internal static int GetTextWithLimit(ITextPointer thisPointer, LogicalDirection direction, char[] textBuffer, int startIndex, int count, ITextPointer limit)
{
int charsCopied;
if (limit == null)
{
// No limit, just call GetText.
charsCopied = thisPointer.GetTextInRun(direction, textBuffer, startIndex, count);
}
else if (direction == LogicalDirection.Forward && limit.CompareTo(thisPointer) <= 0)
{
// Limit completely blocks the read.
charsCopied = 0;
}
else if (direction == LogicalDirection.Backward && limit.CompareTo(thisPointer) >= 0)
{
// Limit completely blocks the read.
charsCopied = 0;
}
else
{
int maxCount;
// Get an upper bound on the amount of text to copy.
// Since GetText always stops on non-text boundaries, it's
// ok if the count too high, it will get truncated anyways.
if (direction == LogicalDirection.Forward)
{
maxCount = Math.Min(count, thisPointer.GetOffsetToPosition(limit));
}
else
{
maxCount = Math.Min(count, limit.GetOffsetToPosition(thisPointer));
}
maxCount = Math.Min(count, maxCount);
charsCopied = thisPointer.GetTextInRun(direction, textBuffer, startIndex, maxCount);
}
return charsCopied;
}
示例13: IsAtLineWrappingPosition
/// <summary>
/// Checks if line wrapping is happening at this position
/// </summary>
internal static bool IsAtLineWrappingPosition(ITextPointer position, ITextView textView)
{
Invariant.Assert(position != null, "null check: position");
if (!position.HasValidLayout)
{
return false;
}
Invariant.Assert(textView != null, "textView cannot be null because the position has valid layout");
TextSegment lineSegment = textView.GetLineRange(position);
if (lineSegment.IsNull)
{
return false;
}
bool isAtLineWrappingPosition = position.LogicalDirection == LogicalDirection.Forward
? position.CompareTo(lineSegment.Start) == 0
: position.CompareTo(lineSegment.End) == 0;
return isAtLineWrappingPosition;
}
示例14: RestrictWithinBlock
private static ITextPointer RestrictWithinBlock(ITextPointer position, ITextPointer limit, LogicalDirection direction)
{
Invariant.Assert(!(direction == LogicalDirection.Backward) || position.CompareTo(limit) >= 0, "for backward direction position must be >= than limit");
Invariant.Assert(!(direction == LogicalDirection.Forward) || position.CompareTo(limit) <= 0, "for forward direcion position must be <= than linit");
while (direction == LogicalDirection.Backward ? position.CompareTo(limit) > 0 : position.CompareTo(limit) < 0)
{
TextPointerContext context = position.GetPointerContext(direction);
if (context == TextPointerContext.ElementStart || context == TextPointerContext.ElementEnd)
{
Type elementType = position.GetElementType(direction);
if (!typeof(Inline).IsAssignableFrom(elementType))
{
limit = position;
break;
}
}
else if (context == TextPointerContext.EmbeddedElement)
{
limit = position;
break;
}
position = position.GetNextContextPosition(direction);
}
// Return normalized position - in the direction towards a center position.
return limit.GetInsertionPosition(direction == LogicalDirection.Backward ? LogicalDirection.Forward : LogicalDirection.Backward);
}
示例15: Max
/// <summary>
/// Returns the following TextPointer of a pair.
/// </summary>
/// <param name="position1">
/// TextPointer to compare.
/// </param>
/// <param name="position2">
/// TextPointer to compare.
/// </param>
internal static ITextPointer Max(ITextPointer position1, ITextPointer position2)
{
return position1.CompareTo(position2) >= 0 ? position1 : position2;
}