Exemple #1
0
        // Returns true if all paragraphs in a range belong to the same block,
        // so they can be easily grouped and ungrouped.
        internal static bool IsListOperationApplicable(TextRange range)
        {
            // First check, if range start/end are parented by ListItems within the same parent list.
            if (IsRangeWithinSingleList(range))
            {
                return(true);
            }

            // Adjust range end so that it does not affect a following paragraph.
            TextPointer end = (TextPointer)TextRangeEdit.GetAdjustedRangeEnd(range.Start, range.End);

            // Now try plain Paragraphs
            Block firstBlock = range.Start.ParagraphOrBlockUIContainer;
            Block lastBlock  = end.ParagraphOrBlockUIContainer;

            if (firstBlock != null && lastBlock != null && firstBlock.Parent == lastBlock.Parent)
            {
                return(true);
            }

            // Allow list editing at potential paragraph positions, this includes
            // positions in initial RichTextBox, empty TableCell, empty ListItem where paragraphs were not yet created.
            if (range.IsEmpty && TextPointerBase.IsAtPotentialParagraphPosition(range.Start))
            {
                return(true);
            }

            return(false);
        }
Exemple #2
0
 // Token: 0x0600625B RID: 25179 RVA: 0x001B9470 File Offset: 0x001B7670
 private static TextSegment CreateNormalizedSegment(ITextPointer start, ITextPointer end)
 {
     if (start.CompareTo(end) == 0)
     {
         if (!TextPointerBase.IsAtInsertionPosition(start, start.LogicalDirection))
         {
             start = start.GetInsertionPosition(start.LogicalDirection);
             end   = start;
         }
     }
     else
     {
         if (!TextPointerBase.IsAtInsertionPosition(start, start.LogicalDirection))
         {
             start = start.GetInsertionPosition(LogicalDirection.Forward);
         }
         if (!TextPointerBase.IsAtInsertionPosition(end, start.LogicalDirection))
         {
             end = end.GetInsertionPosition(LogicalDirection.Backward);
         }
         if (start.CompareTo(end) >= 0)
         {
             if (start.LogicalDirection == LogicalDirection.Backward)
             {
                 start = end.GetFrozenPointer(LogicalDirection.Backward);
             }
             end = start;
         }
     }
     return(new TextSegment(start, end));
 }
Exemple #3
0
        // Token: 0x060038D8 RID: 14552 RVA: 0x00100E4C File Offset: 0x000FF04C
        private static bool IsErrorAtNonMergeableInlineEdge(SpellingError spellingError, out ITextPointer textStart, out ITextPointer textEnd)
        {
            bool result = false;

            textStart = spellingError.Start.CreatePointer(LogicalDirection.Backward);
            while (textStart.CompareTo(spellingError.End) < 0 && textStart.GetPointerContext(LogicalDirection.Forward) != TextPointerContext.Text)
            {
                textStart.MoveToNextContextPosition(LogicalDirection.Forward);
            }
            textEnd = spellingError.End.CreatePointer();
            while (textEnd.CompareTo(spellingError.Start) > 0 && textEnd.GetPointerContext(LogicalDirection.Backward) != TextPointerContext.Text)
            {
                textEnd.MoveToNextContextPosition(LogicalDirection.Backward);
            }
            if (textStart.GetPointerContext(LogicalDirection.Forward) != TextPointerContext.Text || textStart.CompareTo(spellingError.End) == 0)
            {
                return(false);
            }
            Invariant.Assert(textEnd.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.Text && textEnd.CompareTo(spellingError.Start) != 0);
            if ((TextPointerBase.IsAtNonMergeableInlineStart(textStart) || TextPointerBase.IsAtNonMergeableInlineEnd(textEnd)) && typeof(Run).IsAssignableFrom(textStart.ParentType) && textStart.HasEqualScope(textEnd))
            {
                result = true;
            }
            return(result);
        }
Exemple #4
0
            // Token: 0x060085BD RID: 34237 RVA: 0x0024AA08 File Offset: 0x00248C08
            private ITextPointer GetDropPosition(Visual target, Point point)
            {
                Invariant.Assert(target != null);
                Invariant.Assert(this._textEditor.TextView.IsValid);
                if (target != this._textEditor.TextView.RenderScope && target != null && this._textEditor.TextView.RenderScope.IsAncestorOf(target))
                {
                    GeneralTransform generalTransform = target.TransformToAncestor(this._textEditor.TextView.RenderScope);
                    generalTransform.TryTransform(point, out point);
                }
                ITextPointer textPointer = this.TextView.GetTextPositionFromPoint(point, true);

                if (textPointer != null)
                {
                    textPointer = textPointer.GetInsertionPosition(textPointer.LogicalDirection);
                    if (this._textEditor.AcceptsRichContent)
                    {
                        TextSegment normalizedLineRange = TextEditorSelection.GetNormalizedLineRange(this.TextView, textPointer);
                        if (!normalizedLineRange.IsNull && textPointer.CompareTo(normalizedLineRange.End) < 0 && !TextPointerBase.IsAtWordBoundary(textPointer, LogicalDirection.Forward) && this._dragSourceTextRange != null && TextPointerBase.IsAtWordBoundary(this._dragSourceTextRange.Start, LogicalDirection.Forward) && TextPointerBase.IsAtWordBoundary(this._dragSourceTextRange.End, LogicalDirection.Forward))
                        {
                            TextSegment wordRange        = TextPointerBase.GetWordRange(textPointer);
                            string      textInternal     = TextRangeBase.GetTextInternal(wordRange.Start, wordRange.End);
                            int         offsetToPosition = wordRange.Start.GetOffsetToPosition(textPointer);
                            textPointer = ((offsetToPosition < textInternal.Length / 2) ? wordRange.Start : wordRange.End);
                        }
                    }
                }
                return(textPointer);
            }
        // Token: 0x06003B84 RID: 15236 RVA: 0x0010F178 File Offset: 0x0010D378
        internal static void IndentListItems(TextRange range)
        {
            ListItem immediateListItem  = TextPointerBase.GetImmediateListItem(range.Start);
            ListItem immediateListItem2 = TextPointerBase.GetImmediateListItem((TextPointer)TextRangeEdit.GetAdjustedRangeEnd(range.Start, range.End));

            if (immediateListItem == null || immediateListItem2 == null || immediateListItem.Parent != immediateListItem2.Parent || !(immediateListItem.Parent is List))
            {
                return;
            }
            ListItem previousListItem = immediateListItem.PreviousListItem;

            if (previousListItem == null)
            {
                return;
            }
            List element = (List)immediateListItem.Parent;
            List list    = (List)TextRangeEdit.InsertElementClone(immediateListItem.ElementStart, immediateListItem2.ElementEnd, element);

            previousListItem.Reposition(previousListItem.ContentStart, list.ElementEnd);
            Paragraph paragraph = immediateListItem2.Blocks.FirstBlock as Paragraph;

            if (paragraph != null)
            {
                List list2 = paragraph.NextBlock as List;
                if (list2 != null && list2.NextBlock == null)
                {
                    immediateListItem2.Reposition(immediateListItem2.ContentStart, list2.ElementStart);
                    list2.Reposition(null, null);
                }
            }
            TextRangeEditLists.MergeLists(list.ElementStart);
        }
Exemple #6
0
        // Predicate which returns true if list items in this range are within the scope of the same parent list.
        private static bool IsRangeWithinSingleList(TextRange range)
        {
            ListItem startListItem = TextPointerBase.GetListItem(range.Start);

            // Adjust range end so that it does not affect a following paragraph.
            TextPointer end         = (TextPointer)TextRangeEdit.GetAdjustedRangeEnd(range.Start, range.End);
            ListItem    endListItem = TextPointerBase.GetListItem(end);

            // Check if the ListItems belong to one List wrapper.
            if (startListItem != null && endListItem != null && startListItem.Parent == endListItem.Parent)
            {
                return(true);
            }

            // In case of nested lists, it may be the case that start and end list item do not belong to one list wrapper,
            // yet no visual list boundary is crossed.
            // e.g.
            //  * aa
            //      * bb
            //      * cc
            // Special case so that list operations are applicable in this scenario.
            if (startListItem != null && endListItem != null)
            {
                while (end.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd)
                {
                    if (end.Parent == startListItem.Parent)
                    {
                        return(true);
                    }
                    end = end.GetNextContextPosition(LogicalDirection.Forward);
                }
            }

            return(false);
        }
        /// <summary> Resolves text effect on a text range to a list of text effect targets. </summary>
        /// <param name="startPosition">The starting text pointer</param>
        /// <param name="endPosition">The end text pointer</param>
        /// <param name="effect">The effect to apply on the text</param>
        /// <returns>Collection of <see cref="T:System.Windows.Documents.TextEffectTarget" /> objects corresponding to the text range.</returns>
        // Token: 0x06003920 RID: 14624 RVA: 0x001030F0 File Offset: 0x001012F0
        public static TextEffectTarget[] Resolve(TextPointer startPosition, TextPointer endPosition, TextEffect effect)
        {
            if (effect == null)
            {
                throw new ArgumentNullException("effect");
            }
            ValidationHelper.VerifyPositionPair(startPosition, endPosition);
            TextPointer textPointer = new TextPointer(startPosition);

            TextEffectResolver.MoveToFirstCharacterSymbol(textPointer);
            List <TextEffectTarget> list = new List <TextEffectTarget>();

            while (textPointer.CompareTo(endPosition) < 0)
            {
                TextEffect  textEffect   = effect.Clone();
                TextPointer textPointer2 = new TextPointer(textPointer);
                TextEffectResolver.MoveToFirstNonCharacterSymbol(textPointer2, endPosition);
                textPointer2             = (TextPointer)TextPointerBase.Min(textPointer2, endPosition);
                textEffect.PositionStart = textPointer.TextContainer.Start.GetOffsetToPosition(textPointer);
                textEffect.PositionCount = textPointer.GetOffsetToPosition(textPointer2);
                list.Add(new TextEffectTarget(textPointer.Parent, textEffect));
                textPointer = textPointer2;
                TextEffectResolver.MoveToFirstCharacterSymbol(textPointer);
            }
            return(list.ToArray());
        }
        // Returns true if an ITextSelection isn't in a state where we want
        // to acknowledge spelling errors.
        private static bool IsSelectionIgnoringErrors(ITextSelection selection)
        {
            bool isSelectionIgnoringErrors = false;

            // If the selection spans more than a single Block, ignore spelling errors.
            if (selection.Start is TextPointer)
            {
                isSelectionIgnoringErrors = ((TextPointer)selection.Start).ParentBlock != ((TextPointer)selection.End).ParentBlock;
            }

            // If the selection is large, ignore spelling errors.
            if (!isSelectionIgnoringErrors)
            {
                isSelectionIgnoringErrors = selection.Start.GetOffsetToPosition(selection.End) >= 256;
            }

            // If the selection contains unicode line breaks, ignore spelling errors.
            if (!isSelectionIgnoringErrors)
            {
                string text = selection.Text;

                for (int i = 0; i < text.Length && !isSelectionIgnoringErrors; i++)
                {
                    isSelectionIgnoringErrors = TextPointerBase.IsCharUnicodeNewLine(text[i]);
                }
            }

            return(isSelectionIgnoringErrors);
        }
Exemple #9
0
        //---------------------------
        // 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());
        }
Exemple #10
0
        // Assumes that a range contains a sequence of same-level ListItems.
        // Converts all these ListItems into Paragraphs and
        // either adds them to preceding ListItem (as non-bulleted continuation)
        // or pulls them out of a List if they start in the beginning of a List
        internal static void ConvertListItemsToParagraphs(TextRange range)
        {
            ListItem firstListItem = TextPointerBase.GetListItem(range.Start);
            ListItem lastListItem  = TextPointerBase.GetListItem((TextPointer)TextRangeEdit.GetAdjustedRangeEnd(range.Start, range.End));

            // The range must be in a sequence of ListItems belonging to one List wrapper
            if (firstListItem == null || lastListItem == null || firstListItem.Parent != lastListItem.Parent || !(firstListItem.Parent is List))
            {
                return;
            }

            List listToRemove = null;

            ListItem leadingListItem = firstListItem.PreviousListItem;

            if (leadingListItem != null)
            {
                // We have a leading ListItem, so pull selected items into it
                leadingListItem.Reposition(leadingListItem.ContentStart, lastListItem.ElementEnd);
            }
            else
            {
                // We do not have a leading ListItem. So pull selected items out of a list

                // Cut wrapping list after endListItem
                if (lastListItem.NextListItem != null)
                {
                    TextRangeEdit.SplitElement(lastListItem.ElementEnd);
                }

                // Set list to remove
                listToRemove = firstListItem.List;
            }

            // Remove ListItems from all selected blocks
            ListItem listItem = firstListItem;

            while (listItem != null)
            {
                ListItem nextListItem = listItem.ElementEnd.GetAdjacentElement(LogicalDirection.Forward) as ListItem;

                // If this is an empty <ListItem></ListItem>, insert an explicit paragraph in it before deleting the list item.
                if (listItem.ContentStart.CompareTo(listItem.ContentEnd) == 0)
                {
                    TextRangeEditTables.EnsureInsertionPosition(listItem.ContentStart);
                }

                listItem.Reposition(null, null);
                listItem = listItem == lastListItem ? null : nextListItem;
            }

            // If we have a list to remove, remove it and set its FlowDirection to its children
            if (listToRemove != null)
            {
                FlowDirection flowDirection = (FlowDirection)listToRemove.GetValue(Paragraph.FlowDirectionProperty);
                listToRemove.Reposition(null, null);
                TextRangeEdit.SetParagraphProperty(range.Start, range.End, Paragraph.FlowDirectionProperty, flowDirection);
            }
        }
        // Returns the closest insertion position, treating all unicode code points
        // as valid insertion positions.  A useful performance win over
        // GetNextInsertionPosition when only formatting scopes are important.
        ITextPointer ITextPointer.GetFormatNormalizedPosition(LogicalDirection direction)
        {
            ITextPointer pointer = ((ITextPointer)this).CreatePointer();

            TextPointerBase.MoveToFormatNormalizedPosition(pointer, direction);
            pointer.Freeze();
            return(pointer);
        }
        // Token: 0x06003870 RID: 14448 RVA: 0x000FCC00 File Offset: 0x000FAE00
        internal static void DecreaseIndentation(TextEditor This)
        {
            TextSelection textSelection     = (TextSelection)This.Selection;
            ListItem      listItem          = TextPointerBase.GetListItem(textSelection.Start);
            ListItem      immediateListItem = TextPointerBase.GetImmediateListItem(textSelection.Start);

            TextEditorLists.DecreaseIndentation(textSelection, listItem, immediateListItem);
        }
        // Token: 0x06003879 RID: 14457 RVA: 0x000FD0D4 File Offset: 0x000FB2D4
        private static void CreateImplicitParagraphIfNeededAndUpdateSelection(TextSelection thisSelection)
        {
            TextPointer textPointer = thisSelection.Start;

            if (TextPointerBase.IsAtPotentialParagraphPosition(textPointer))
            {
                textPointer = TextRangeEditTables.EnsureInsertionPosition(textPointer);
                thisSelection.Select(textPointer, textPointer);
            }
        }
Exemple #14
0
        private static void CreateImplicitParagraphIfNeededAndUpdateSelection(TextSelection thisSelection)
        {
            // Create implicit paragraph if we are at a potential paragraph position, such as empty FlowDocument, TableCell.
            TextPointer position = thisSelection.Start;

            if (TextPointerBase.IsAtPotentialParagraphPosition(position))
            {
                position = TextRangeEditTables.EnsureInsertionPosition(position);
                thisSelection.Select(position, position);
            }
        }
Exemple #15
0
        // Common handler for all list editing commands
        private static void OnListCommand(object target, ExecutedRoutedEventArgs args)
        {
            TextEditor This = TextEditor._GetTextEditor(target);

            if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection is TextSelection))
            {
                return;
            }

            TextEditorTyping._FlushPendingInputItems(This);

            if (!TextRangeEditLists.IsListOperationApplicable((TextSelection)This.Selection))
            {
                return;
            }

            using (This.Selection.DeclareChangeBlock())
            {
                TextSelection thisSelection = (TextSelection)This.Selection;

                ListItem parentListItem    = TextPointerBase.GetListItem(thisSelection.Start);
                ListItem immediateListItem = TextPointerBase.GetImmediateListItem(thisSelection.Start);
                List     list = parentListItem == null ? null : (List)parentListItem.Parent;

                // Forget previously suggested horizontal position
                TextEditorSelection._ClearSuggestedX(This);

                // Execute the command
                if (args.Command == EditingCommands.ToggleBullets)
                {
                    ToggleBullets(thisSelection, parentListItem, immediateListItem, list);
                }
                else if (args.Command == EditingCommands.ToggleNumbering)
                {
                    ToggleNumbering(thisSelection, parentListItem, immediateListItem, list);
                }
                else if (args.Command == EditingCommands.RemoveListMarkers)
                {
                    TextRangeEditLists.ConvertListItemsToParagraphs(thisSelection);
                }
                else if (args.Command == EditingCommands.IncreaseIndentation)
                {
                    IncreaseIndentation(thisSelection, parentListItem, immediateListItem);
                }
                else if (args.Command == EditingCommands.DecreaseIndentation)
                {
                    DecreaseIndentation(thisSelection, parentListItem, immediateListItem);
                }
                else
                {
                    Invariant.Assert(false);
                }
            }
        }
Exemple #16
0
        internal static void IndentListItems(TextRange range)
        {
            ListItem firstListItem = TextPointerBase.GetImmediateListItem(range.Start);
            ListItem lastListItem  = TextPointerBase.GetImmediateListItem((TextPointer)TextRangeEdit.GetAdjustedRangeEnd(range.Start, range.End));

            // The range must be in a sequence of ListItems belonging to one List wrapper
            if (firstListItem == null || lastListItem == null ||
                firstListItem.Parent != lastListItem.Parent ||
                !(firstListItem.Parent is List))
            {
                return;
            }

            // Identify a ListItem which will become a leading item for this potential sublist
            ListItem leadingListItem = firstListItem.PreviousListItem;

            if (leadingListItem == null)
            {
                // There is no leading list item for this group. Indentation is impossible
                return;
            }

            // Get current List
            List list = (List)firstListItem.Parent;

            // Wrap these items into a List - inheriting all properties from our current list
            List indentedList = (List)TextRangeEdit.InsertElementClone(firstListItem.ElementStart, lastListItem.ElementEnd, list);

            // Wrap the leading ListItem to include the sublist
            leadingListItem.Reposition(leadingListItem.ContentStart, indentedList.ElementEnd);

            // Unwrap sublist from the last selected list item (to keep it on its level)
            Paragraph leadingParagraphOfLastItem = lastListItem.Blocks.FirstBlock as Paragraph;

            if (leadingParagraphOfLastItem != null)
            {
                // Unindenting all items of a sublist - if it is the only following element of a list
                List nestedListOfLastItem = leadingParagraphOfLastItem.NextBlock as List;
                if (nestedListOfLastItem != null && nestedListOfLastItem.NextBlock == null)
                {
                    lastListItem.Reposition(lastListItem.ContentStart, nestedListOfLastItem.ElementStart);
                    nestedListOfLastItem.Reposition(null, null);
                }
            }

            // Merge with neighboring lists
            MergeLists(indentedList.ElementStart);
            // No need in merging at nestedList.ElementEnd as ListItem ends there.
        }
Exemple #17
0
        internal static bool IsValidChild(ITextPointer position, Type childType)
        {
            // Disallow nested hyperlink elements.
            if (typeof(TextElement).IsAssignableFrom(position.ParentType) &&
                TextPointerBase.IsInHyperlinkScope(position))
            {
                if (typeof(Hyperlink).IsAssignableFrom(childType) ||
                    typeof(AnchoredBlock).IsAssignableFrom(childType))
                {
                    return(false);
                }
            }

            return(IsValidChild(position.ParentType, childType));
        }
Exemple #18
0
        // Token: 0x06003C68 RID: 15464 RVA: 0x0011745C File Offset: 0x0011565C
        internal void InternalOnSelectionChanged()
        {
            ITextPointer textPointer;

            if (!this._selection.IsInterimSelection)
            {
                textPointer = this._selection.Start;
            }
            else
            {
                textPointer = this._selection.End;
            }
            ITextPointer end = this._selection.End;
            ITextPointer textPointer2;
            ITextPointer textPointer3;

            if (this._oldStart.CompareTo(textPointer) < 0)
            {
                textPointer2 = this._oldStart;
                textPointer3 = TextPointerBase.Min(textPointer, this._oldEnd);
            }
            else
            {
                textPointer2 = textPointer;
                textPointer3 = TextPointerBase.Min(end, this._oldStart);
            }
            ITextPointer textPointer4;
            ITextPointer textPointer5;

            if (this._oldEnd.CompareTo(end) < 0)
            {
                textPointer4 = TextPointerBase.Max(textPointer, this._oldEnd);
                textPointer5 = end;
            }
            else
            {
                textPointer4 = TextPointerBase.Max(end, this._oldStart);
                textPointer5 = this._oldEnd;
            }
            this._oldStart = textPointer;
            this._oldEnd   = end;
            if (this.Changed != null && (textPointer2.CompareTo(textPointer3) != 0 || textPointer4.CompareTo(textPointer5) != 0))
            {
                TextSelectionHighlightLayer.TextSelectionHighlightChangedEventArgs args = new TextSelectionHighlightLayer.TextSelectionHighlightChangedEventArgs(textPointer2, textPointer3, textPointer4, textPointer5);
                this.Changed(this, args);
            }
        }
        // Token: 0x06003B82 RID: 15234 RVA: 0x0010EF28 File Offset: 0x0010D128
        internal static bool ConvertParagraphsToListItems(TextRange range, TextMarkerStyle markerStyle)
        {
            if (range.IsEmpty && TextPointerBase.IsAtPotentialParagraphPosition(range.Start))
            {
                TextPointer textPointer = TextRangeEditTables.EnsureInsertionPosition(range.Start);
                ((ITextRange)range).Select(textPointer, textPointer);
            }
            Block       paragraphOrBlockUIContainer = range.Start.ParagraphOrBlockUIContainer;
            TextPointer textPointer2 = (TextPointer)TextRangeEdit.GetAdjustedRangeEnd(range.Start, range.End);
            Block       paragraphOrBlockUIContainer2 = textPointer2.ParagraphOrBlockUIContainer;

            if (paragraphOrBlockUIContainer == null || paragraphOrBlockUIContainer2 == null || paragraphOrBlockUIContainer.Parent != paragraphOrBlockUIContainer2.Parent || (paragraphOrBlockUIContainer.Parent is ListItem && paragraphOrBlockUIContainer.PreviousBlock == null))
            {
                return(false);
            }
            Block block = paragraphOrBlockUIContainer;

            while (block != paragraphOrBlockUIContainer2 && block != null)
            {
                if (block is Table || block is Section)
                {
                    return(false);
                }
                block = block.NextBlock;
            }
            ListItem listItem = paragraphOrBlockUIContainer.Parent as ListItem;

            if (listItem != null)
            {
                Block block3;
                for (Block block2 = paragraphOrBlockUIContainer; block2 != null; block2 = block3)
                {
                    block3 = ((block2 == paragraphOrBlockUIContainer2) ? null : (block2.ElementEnd.GetAdjacentElement(LogicalDirection.Forward) as Block));
                    Invariant.Assert(block2.Parent is ListItem);
                    TextRangeEdit.SplitElement(block2.ElementStart);
                }
            }
            else
            {
                new List
                {
                    MarkerStyle = markerStyle
                }.Apply(paragraphOrBlockUIContainer, paragraphOrBlockUIContainer2);
            }
            return(true);
        }
        // Token: 0x06003874 RID: 14452 RVA: 0x000FCCBC File Offset: 0x000FAEBC
        private static void OnListCommand(object target, ExecutedRoutedEventArgs args)
        {
            TextEditor textEditor = TextEditor._GetTextEditor(target);

            if (textEditor == null || !textEditor._IsEnabled || textEditor.IsReadOnly || !textEditor.AcceptsRichContent || !(textEditor.Selection is TextSelection))
            {
                return;
            }
            TextEditorTyping._FlushPendingInputItems(textEditor);
            if (!TextRangeEditLists.IsListOperationApplicable((TextSelection)textEditor.Selection))
            {
                return;
            }
            using (textEditor.Selection.DeclareChangeBlock())
            {
                TextSelection textSelection     = (TextSelection)textEditor.Selection;
                ListItem      listItem          = TextPointerBase.GetListItem(textSelection.Start);
                ListItem      immediateListItem = TextPointerBase.GetImmediateListItem(textSelection.Start);
                List          list = (listItem == null) ? null : ((List)listItem.Parent);
                TextEditorSelection._ClearSuggestedX(textEditor);
                if (args.Command == EditingCommands.ToggleBullets)
                {
                    TextEditorLists.ToggleBullets(textSelection, listItem, immediateListItem, list);
                }
                else if (args.Command == EditingCommands.ToggleNumbering)
                {
                    TextEditorLists.ToggleNumbering(textSelection, listItem, immediateListItem, list);
                }
                else if (args.Command == EditingCommands.RemoveListMarkers)
                {
                    TextRangeEditLists.ConvertListItemsToParagraphs(textSelection);
                }
                else if (args.Command == EditingCommands.IncreaseIndentation)
                {
                    TextEditorLists.IncreaseIndentation(textSelection, listItem, immediateListItem);
                }
                else if (args.Command == EditingCommands.DecreaseIndentation)
                {
                    TextEditorLists.DecreaseIndentation(textSelection, listItem, immediateListItem);
                }
                else
                {
                    Invariant.Assert(false);
                }
            }
        }
            /// <summary>
            /// Calculates a TextPointer indended for dropping the text.
            /// </summary>
            /// <param name="target"></param>
            /// <param name="point"></param>
            /// <returns>
            /// ITextPointer intended for dropping the selected text.
            /// Adjusts the dropping point to a word boundary (beginning of word)
            /// in case if source range contains whole words.
            /// The position returned is oriented towards a character
            /// under the mouse pointer.
            /// </returns>
            private ITextPointer GetDropPosition(Visual target, Point point)
            {
                Invariant.Assert(target != null);
                Invariant.Assert(_textEditor.TextView.IsValid); // caller must guarantee this.

                // Convert point to RenderScope
                if (target != _textEditor.TextView.RenderScope && target != null && (_textEditor.TextView.RenderScope).IsAncestorOf(target))
                {
                    GeneralTransform transform = target.TransformToAncestor(_textEditor.TextView.RenderScope);
                    transform.TryTransform(point, out point);
                }

                ITextPointer dropPosition = this.TextView.GetTextPositionFromPoint(point, /*snapToText:*/ true);

                // For rich text content we adjust drop position to word boundary
                if (dropPosition != null)
                {
                    // Normalize drop position
                    dropPosition = dropPosition.GetInsertionPosition(dropPosition.LogicalDirection);

                    if (_textEditor.AcceptsRichContent)
                    {
                        TextSegment lineRange = TextEditorSelection.GetNormalizedLineRange(this.TextView, dropPosition);

                        if (!lineRange.IsNull &&
                            // The drop position must be before of end of line
                            dropPosition.CompareTo(lineRange.End) < 0 &&
                            // We check if we are not at word boundary already:
                            !TextPointerBase.IsAtWordBoundary(dropPosition, /*insideWordDirection:*/ LogicalDirection.Forward) &&
                            // We do not do it if the source range was not on word boundaries from both ends
                            _dragSourceTextRange != null &&                                                           //
                            TextPointerBase.IsAtWordBoundary(_dragSourceTextRange.Start, LogicalDirection.Forward) && //
                            TextPointerBase.IsAtWordBoundary(_dragSourceTextRange.End, LogicalDirection.Forward))
                        {
                            // Move to word boundary. Select closest one to a dropPosition.
                            TextSegment wordSegment = TextPointerBase.GetWordRange(dropPosition);
                            string      wordText    = TextRangeBase.GetTextInternal(wordSegment.Start, wordSegment.End);
                            int         indexInWord = wordSegment.Start.GetOffsetToPosition(dropPosition);
                            dropPosition = (indexInWord < (wordText.Length / 2)) ? wordSegment.Start : wordSegment.End;
                        }
                    }
                }

                return(dropPosition);
            }
Exemple #22
0
        // Token: 0x060035A5 RID: 13733 RVA: 0x000F37E4 File Offset: 0x000F19E4
        internal void GetFirstDirtyRange(ITextPointer searchStart, out ITextPointer start, out ITextPointer end)
        {
            start = null;
            end   = null;
            int num = this.FindIndex(searchStart.CreateStaticPointer(), LogicalDirection.Forward);

            while (num >= 0 && num < this._runList.Count)
            {
                SpellerStatusTable.Run run = this.GetRun(num);
                if (run.RunType == SpellerStatusTable.RunType.Dirty)
                {
                    start = TextPointerBase.Max(searchStart, run.Position);
                    end   = this.GetRunEndPositionDynamic(num);
                    return;
                }
                num++;
            }
        }
        // Token: 0x06003B83 RID: 15235 RVA: 0x0010F058 File Offset: 0x0010D258
        internal static void ConvertListItemsToParagraphs(TextRange range)
        {
            ListItem listItem  = TextPointerBase.GetListItem(range.Start);
            ListItem listItem2 = TextPointerBase.GetListItem((TextPointer)TextRangeEdit.GetAdjustedRangeEnd(range.Start, range.End));

            if (listItem == null || listItem2 == null || listItem.Parent != listItem2.Parent || !(listItem.Parent is List))
            {
                return;
            }
            List     list             = null;
            ListItem previousListItem = listItem.PreviousListItem;

            if (previousListItem != null)
            {
                previousListItem.Reposition(previousListItem.ContentStart, listItem2.ElementEnd);
            }
            else
            {
                if (listItem2.NextListItem != null)
                {
                    TextRangeEdit.SplitElement(listItem2.ElementEnd);
                }
                list = listItem.List;
            }
            ListItem listItem4;

            for (ListItem listItem3 = listItem; listItem3 != null; listItem3 = ((listItem3 == listItem2) ? null : listItem4))
            {
                listItem4 = (listItem3.ElementEnd.GetAdjacentElement(LogicalDirection.Forward) as ListItem);
                if (listItem3.ContentStart.CompareTo(listItem3.ContentEnd) == 0)
                {
                    TextRangeEditTables.EnsureInsertionPosition(listItem3.ContentStart);
                }
                listItem3.Reposition(null, null);
            }
            if (list != null)
            {
                FlowDirection flowDirection = (FlowDirection)list.GetValue(Block.FlowDirectionProperty);
                list.Reposition(null, null);
                TextRangeEdit.SetParagraphProperty(range.Start, range.End, Block.FlowDirectionProperty, flowDirection);
            }
        }
Exemple #24
0
        /// <summary>
        /// Creates a new segment with the specified pointers, but first
        /// normalizes them to make sure they are on insertion positions.
        /// </summary>
        /// <param name="start">start of the new segment</param>
        /// <param name="end">end of the new segment</param>
        private static TextSegment CreateNormalizedSegment(ITextPointer start, ITextPointer end)
        {
            // Normalize the segment
            if (start.CompareTo(end) == 0)
            {
                // When the range is empty we must keep it that way during normalization
                if (!TextPointerBase.IsAtInsertionPosition(start, start.LogicalDirection))
                {
                    start = start.GetInsertionPosition(start.LogicalDirection);
                    end   = start;
                }
            }
            else
            {
                if (!TextPointerBase.IsAtInsertionPosition(start, start.LogicalDirection))
                {
                    start = start.GetInsertionPosition(LogicalDirection.Forward);
                }
                if (!TextPointerBase.IsAtInsertionPosition(end, start.LogicalDirection))
                {
                    end = end.GetInsertionPosition(LogicalDirection.Backward);
                }

                // Collapse range in case of overlapped normalization result
                if (start.CompareTo(end) >= 0)
                {
                    // The range is effectuvely empty, so collapse it to single pointer instance
                    if (start.LogicalDirection == LogicalDirection.Backward)
                    {
                        // Choose a position normalized backward,
                        start = end.GetFrozenPointer(LogicalDirection.Backward);

                        // NOTE that otherwise we will use start position,
                        // which is oriented and normalizd Forward
                    }
                    end = start;
                }
            }

            return(new TextSegment(start, end));
        }
        // Token: 0x06003B86 RID: 15238 RVA: 0x0010F434 File Offset: 0x0010D634
        private static bool IsRangeWithinSingleList(TextRange range)
        {
            ListItem    listItem    = TextPointerBase.GetListItem(range.Start);
            TextPointer textPointer = (TextPointer)TextRangeEdit.GetAdjustedRangeEnd(range.Start, range.End);
            ListItem    listItem2   = TextPointerBase.GetListItem(textPointer);

            if (listItem != null && listItem2 != null && listItem.Parent == listItem2.Parent)
            {
                return(true);
            }
            if (listItem != null && listItem2 != null)
            {
                while (textPointer.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd)
                {
                    if (textPointer.Parent == listItem.Parent)
                    {
                        return(true);
                    }
                    textPointer = textPointer.GetNextContextPosition(LogicalDirection.Forward);
                }
            }
            return(false);
        }
        // Returns the first dirty run following a specified position in the document.
        // start/end will be left null if no dirty ranges are found.
        internal void GetFirstDirtyRange(ITextPointer searchStart, out ITextPointer start, out ITextPointer end)
        {
            int index;
            Run run;

            start = null;
            end   = null;

            // If this is ever slow enough to matter, we could cache the value.
            for (index = FindIndex(searchStart.CreateStaticPointer(), LogicalDirection.Forward); index >= 0 && index < _runList.Count; index++)
            {
                run = GetRun(index);

                if (run.RunType == RunType.Dirty)
                {
                    // We might get a hit in the first run, in which case start <= searchStart.
                    // Always return searchStart as a minimum.
                    start = TextPointerBase.Max(searchStart, run.Position);
                    end   = GetRunEndPositionDynamic(index);
                    break;
                }
            }
        }
Exemple #27
0
        // Token: 0x060038DD RID: 14557 RVA: 0x00101064 File Offset: 0x000FF264
        private static bool IsSelectionIgnoringErrors(ITextSelection selection)
        {
            bool flag = false;

            if (selection.Start is TextPointer)
            {
                flag = (((TextPointer)selection.Start).ParentBlock != ((TextPointer)selection.End).ParentBlock);
            }
            if (!flag)
            {
                flag = (selection.Start.GetOffsetToPosition(selection.End) >= 256);
            }
            if (!flag)
            {
                string text = selection.Text;
                int    num  = 0;
                while (num < text.Length && !flag)
                {
                    flag = TextPointerBase.IsCharUnicodeNewLine(text[num]);
                    num++;
                }
            }
            return(flag);
        }
 bool ITextPointer.MoveToNextInsertionPosition(LogicalDirection direction)
 {
     return(TextPointerBase.MoveToNextInsertionPosition(this, direction));
 }
 // <see cref="ITextPointer.GetCharacterRect"/>
 Rect ITextPointer.GetCharacterRect(LogicalDirection direction)
 {
     return(TextPointerBase.GetCharacterRect(this, direction));
 }
 // <see cref="ITextPointer.MoveToLineBoundary"/>
 int ITextPointer.MoveToLineBoundary(int count)
 {
     return(TextPointerBase.MoveToLineBoundary(this, ((ITextPointer)this).TextContainer.TextView, count, true));
 }