当前位置: 首页>>代码示例>>C#>>正文


C# ITextPointer.DeleteContentToPosition方法代码示例

本文整理汇总了C#中ITextPointer.DeleteContentToPosition方法的典型用法代码示例。如果您正苦于以下问题:C# ITextPointer.DeleteContentToPosition方法的具体用法?C# ITextPointer.DeleteContentToPosition怎么用?C# ITextPointer.DeleteContentToPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITextPointer的用法示例。


在下文中一共展示了ITextPointer.DeleteContentToPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoveContent

        // Deletes a specified run of content.
        //
        // On exit,
        //   symbolsRemoved <== count of symbols actually removed.
        //   removeStartIndex <== offset of first symbol affected by the edit.
        //
        // removeStartIndex is always <= endPosition.Offset, but it does not necessarily
        // match the position of the logically removed content.  In some rare cases
        // a scoping element may be removed, meaning we have two or more runs of
        // removed content, and removeStartIndex + symbolsRemoved < the offset of
        // the last position affected by the operation.
        private void RemoveContent(ITextPointer startPosition, ITextPointer endPosition, out int symbolsRemoved, out int removeStartIndex)
        {
            symbolsRemoved = 0;
            removeStartIndex = startPosition.Offset;

            if (startPosition.CompareTo(endPosition) == 0)
                return;

            TextContainer container = (TextContainer)startPosition.TextContainer;

            symbolsRemoved = container.SymbolCount;

            if (startPosition is TextPointer)
            {
                _minSymbolsRemovedIndex = Int32.MaxValue;
            }

            startPosition.DeleteContentToPosition(endPosition);

            if (startPosition is TextPointer)
            {
                removeStartIndex = _minSymbolsRemovedIndex;
            }

            symbolsRemoved = symbolsRemoved - container.SymbolCount;
        }
开发者ID:mind0n,项目名称:hive,代码行数:37,代码来源:TextStore.cs

示例2: DeleteParagraphContent

        /// <summary>
        /// Deletes a content covered by two positions assuming that
        /// the content crosses only paragraph-mergeable boundaries (if at all) -
        /// Paragraphs, Sections, Lists, ListItems, but not harder structural 
        /// elements like Tables, TableCells, TableRows, Floaters, Figures.
        /// </summary> 
        /// <param name="start"> 
        /// Position indicating a beginning of deleted content.
        /// </param> 
        /// <param name="end">
        /// Position indicating an end of deleted content.
        /// </param>
        internal static void DeleteParagraphContent(ITextPointer start, ITextPointer end) 
        {
            // Parameters validation 
            Invariant.Assert(start != null, "null check: start"); 
            Invariant.Assert(end != null, "null check: end");
            Invariant.Assert(start.CompareTo(end) <= 0, "expecting: start <= end"); 

            if (!(start is TextPointer))
            {
                // Abstract text container. We can only use basic abstract functionality here: 
                start.DeleteContentToPosition(end);
                return; 
            } 

            TextPointer startPosition = (TextPointer)start; 
            TextPointer endPosition = (TextPointer)end;

            // Delete all equi-scoped content in the given range
            DeleteEquiScopedContent(startPosition, endPosition); // delete content runs from start to root 
            DeleteEquiScopedContent(endPosition, startPosition); // delete contentruns from end to root
 
            // Merge crossed elements 
            if (startPosition.CompareTo(endPosition) < 0)
            { 
                if (TextPointerBase.IsAfterLastParagraph(endPosition))
                {
                    // This means that end position is after the last paragraph of a text container.
 
                    // When the last paragraph is empty (and selection crosses its end boundary)
                    // we need to delete it. 
                    // When last paragraph is not empty, we have to leave it as is. 
                    while (startPosition.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart &&
                        startPosition.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd) 
                    {
                        //
                        TextElement parent = (TextElement)startPosition.Parent;
                        if (parent is Inline || TextSchema.AllowsParagraphMerging(parent.GetType())) 
                        {
                            parent.RepositionWithContent(null); 
                        } 
                        else
                        { 
                            break;
                        }
                    }
                } 
                else
                { 
                    Block firstParagraphOrBlockUIContainer = startPosition.ParagraphOrBlockUIContainer; 
                    Block secondParagraphOrBlockUIContainer = endPosition.ParagraphOrBlockUIContainer;
 
                    // If startPosition and/or endPosition is parented by an empty ListItem, create an implicit paragraph in it.
                    // This will enable the following code to merge paragraphs in list items.

                    if (firstParagraphOrBlockUIContainer == null && TextPointerBase.IsInEmptyListItem(startPosition)) 
                    {
                        startPosition = TextRangeEditTables.EnsureInsertionPosition(startPosition); 
                        firstParagraphOrBlockUIContainer = startPosition.Paragraph; 
                        Invariant.Assert(firstParagraphOrBlockUIContainer != null, "EnsureInsertionPosition must create a paragraph inside list item - 1");
                    } 
                    if (secondParagraphOrBlockUIContainer == null && TextPointerBase.IsInEmptyListItem(endPosition))
                    {
                        endPosition = TextRangeEditTables.EnsureInsertionPosition(endPosition);
                        secondParagraphOrBlockUIContainer = endPosition.Paragraph; 
                        Invariant.Assert(secondParagraphOrBlockUIContainer != null, "EnsureInsertionPosition must create a paragraph inside list item - 2");
                    } 
 
                    if (firstParagraphOrBlockUIContainer != null && secondParagraphOrBlockUIContainer != null)
                    { 
                        TextRangeEditLists.MergeParagraphs(firstParagraphOrBlockUIContainer, secondParagraphOrBlockUIContainer);
                    }
                    else
                    { 
                        // When crossing BlockUIContainer boundaries we need to clear
                        // any empty BlockUIContainers and empty adjacent paragraphs 
                        MergeEmptyParagraphsAndBlockUIContainers(startPosition, endPosition); 
                    }
                } 
            }

            // Remove empty formatting elements
            MergeFormattingInlines(startPosition); 
            MergeFormattingInlines(endPosition);
 
            // Check for remaining empty BlockUICOntainer or empty Hyperlink elements 
            if (startPosition.Parent is BlockUIContainer && ((BlockUIContainer)startPosition.Parent).IsEmpty)
            { 
                ((BlockUIContainer)startPosition.Parent).Reposition(null, null);
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:TextRangeEdit.cs


注:本文中的ITextPointer.DeleteContentToPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。