コード例 #1
0
        /// <summary>
        /// Like MergeLists, but will search over formatting elements when
        /// looking for Lists to merge.
        /// </summary>
        internal static bool MergeListsAroundNormalizedPosition(TextPointer mergePosition)
        {
            // Search forward for a List to merge with.
            TextPointer navigator = mergePosition.CreatePointer();

            while (navigator.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd)
            {
                navigator.MoveToNextContextPosition(LogicalDirection.Forward);
            }

            bool merged = MergeLists(navigator);

            // Search backward for a List to merge with.
            if (!merged)
            {
                navigator.MoveToPosition(mergePosition);

                while (navigator.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
                {
                    navigator.MoveToNextContextPosition(LogicalDirection.Backward);
                }

                merged = MergeLists(navigator);
            }

            return(merged);
        }
コード例 #2
0
        // Token: 0x06003B7F RID: 15231 RVA: 0x0010EDDC File Offset: 0x0010CFDC
        internal static bool MergeListsAroundNormalizedPosition(TextPointer mergePosition)
        {
            TextPointer textPointer = mergePosition.CreatePointer();

            while (textPointer.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd)
            {
                textPointer.MoveToNextContextPosition(LogicalDirection.Forward);
            }
            bool flag = TextRangeEditLists.MergeLists(textPointer);

            if (!flag)
            {
                textPointer.MoveToPosition(mergePosition);
                while (textPointer.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
                {
                    textPointer.MoveToNextContextPosition(LogicalDirection.Backward);
                }
                flag = TextRangeEditLists.MergeLists(textPointer);
            }
            return(flag);
        }
コード例 #3
0
ファイル: TextRangeEditLists.cs プロジェクト: JianwenSun/cc
        /// <summary>
        /// Like MergeLists, but will search over formatting elements when
        /// looking for Lists to merge.
        /// </summary>
        internal static bool MergeListsAroundNormalizedPosition(TextPointer mergePosition)
        {
            // Search forward for a List to merge with.
            TextPointer navigator = mergePosition.CreatePointer();

            while (navigator.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd)
            {
                navigator.MoveToNextContextPosition(LogicalDirection.Forward);
            }

            bool merged = MergeLists(navigator);

            // Search backward for a List to merge with.
            if (!merged)
            {
                navigator.MoveToPosition(mergePosition);

                while (navigator.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
                {
                    navigator.MoveToNextContextPosition(LogicalDirection.Backward);
                }

                merged = MergeLists(navigator);
            }

            return merged;
        }
コード例 #4
0
ファイル: TextRangeEdit.cs プロジェクト: sjyanxin/WPFSource
        // Merges Spans or Runs with equal FlowDirection that border at a given position. 
        internal static void MergeFlowDirection(TextPointer position)
        { 
            TextPointerContext backwardContext = position.GetPointerContext(LogicalDirection.Backward); 
            TextPointerContext forwardContext = position.GetPointerContext(LogicalDirection.Forward);
 
            if (!(backwardContext == TextPointerContext.ElementStart || backwardContext == TextPointerContext.ElementEnd) &&
                !(forwardContext == TextPointerContext.ElementStart || forwardContext == TextPointerContext.ElementEnd))
            {
                // Early out if position is not at an Inline border. 
                return;
            } 
 
            // Find the common ancestor of the two adjacent content runs.
            while (position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart && 
                TextSchema.IsMergeableInline(position.Parent.GetType()))
            {
                position = ((Inline)position.Parent).ElementStart;
            } 
            while (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd &&
                TextSchema.IsMergeableInline(position.Parent.GetType())) 
            { 
                position = ((Inline)position.Parent).ElementEnd;
            } 
            TextElement commonAncestor = position.Parent as TextElement;

            if (!(commonAncestor is Span || commonAncestor is Paragraph))
            { 
                // Don't try to merge across Block boundaries.
                return; 
            } 

            // Find the previous content. 
            TextPointer previousPosition = position.CreatePointer();
            while (previousPosition.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementEnd &&
                   TextSchema.IsMergeableInline(previousPosition.GetAdjacentElement(LogicalDirection.Backward).GetType()))
            { 
                previousPosition = ((Inline)previousPosition.GetAdjacentElement(LogicalDirection.Backward)).ContentEnd;
            } 
            Run previousRun = previousPosition.Parent as Run; 

            // Find the next content. 
            TextPointer nextPosition = position.CreatePointer();
            while (nextPosition.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart &&
                   TextSchema.IsMergeableInline(nextPosition.GetAdjacentElement(LogicalDirection.Forward).GetType()))
            { 
                nextPosition = ((Inline)nextPosition.GetAdjacentElement(LogicalDirection.Forward)).ContentStart;
            } 
            Run nextRun = nextPosition.Parent as Run; 

            if (previousRun == null || previousRun.IsEmpty || nextRun == null || nextRun.IsEmpty) 
            {
                // No text to make the merge meaningful.
                return;
            } 

            FlowDirection midpointFlowDirection = (FlowDirection)commonAncestor.GetValue(FrameworkElement.FlowDirectionProperty); 
            FlowDirection previousFlowDirection = (FlowDirection)previousRun.GetValue(FrameworkElement.FlowDirectionProperty); 
            FlowDirection nextFlowDirection = (FlowDirection)nextRun.GetValue(FrameworkElement.FlowDirectionProperty);
 
            // If the previous and next content have the same FlowDirection, but their
            // common ancestor differs, we want to merge them.
            if (previousFlowDirection == nextFlowDirection &&
                previousFlowDirection != midpointFlowDirection) 
            {
                // Expand the context out to include any scoping Spans with local FlowDirection. 
                Inline scopingPreviousInline = GetScopingFlowDirectionInline(previousRun); 
                Inline scopingNextInline = GetScopingFlowDirectionInline(nextRun);
 
                // Set a single FlowDirection Span over the whole lot of it.
                SetStructuralInlineProperty(scopingPreviousInline.ElementStart, scopingNextInline.ElementEnd, FrameworkElement.FlowDirectionProperty, previousFlowDirection);
            }
        } 
コード例 #5
0
        // Helper for EnsureInsertionPosition, inserts a Run element at this position. 
        private static TextPointer CreateImplicitRun(TextPointer position)
        { 
            TextPointer insertionPosition;

            if (position.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward) is Run)
            { 
                insertionPosition = position.CreatePointer();
                insertionPosition.MoveToNextContextPosition(LogicalDirection.Forward); 
                insertionPosition.Freeze(); 
            }
            else if (position.GetAdjacentElementFromOuterPosition(LogicalDirection.Backward) is Run) 
            {
                insertionPosition = position.CreatePointer();
                insertionPosition.MoveToNextContextPosition(LogicalDirection.Backward);
                insertionPosition.Freeze(); 
            }
            else 
            { 
                Run implicitRun = Run.CreateImplicitRun(position.Parent);
                implicitRun.Reposition(position, position); 
                insertionPosition = implicitRun.ContentStart.GetFrozenPointer(position.LogicalDirection); // return a position with the same orientation inside a Run
            }

            return insertionPosition; 
        }