Ejemplo n.º 1
0
        /// <summary> Inserts the given content into this instance. </summary>
        /// <param name="caret"> The caret which represents the point at which the content should be
        ///  inserted. </param>
        /// <param name="newContent"> The content to insert. </param>
        /// <param name="autoMerge"> (Optional) True to automatically merge similar fragments together. </param>
        public TextCaret Insert(TextCaret caret, TextBlockContent newContent, bool autoMerge = true)
        {
            if (newContent == this)
            {
                throw new ArgumentException("Content cannot be inserted into itself", nameof(newContent));
            }

            return(Insert(caret, newContent.GetText()));
        }
Ejemplo n.º 2
0
        public TextBlockContent ExtractOrCloneContent(TextCaret caretStart, TextCaret caretEnd, bool shouldRemoveContent)
        {
            VerifyExtractParameters(caretStart, caretEnd);

            NormalizePositioning(ref caretStart, ref caretEnd);

            // zero-width; this check is needed, as the normalization process might shift the end to be
            // before the start when both are pointing at the end of a fragment (the start is normalized to
            // point at the beginning of the next fragment instead).
            if (caretStart == caretEnd)
            {
                return(new TextBlockContent());
            }

            var start = caretStart.Offset;
            var end   = caretEnd.Offset;

            if (start == end)
            {
                return(new TextBlockContent());
            }
            else if (caretStart.IsAtBlockStart && caretEnd.IsAtBlockEnd)
            {
                var newContent = new TextBlockContent(this);

                if (shouldRemoveContent)
                {
                    RemoveAll();
                }

                return(newContent);
            }
            else
            {
                var clone = new TextBlockContent(_buffer.GetText(start, end));

                if (shouldRemoveContent)
                {
                    _buffer.DeleteText(start, end);
                    NotifyChanged();
                }

                return(clone);
            }
        }
 private TextCaret(TextBlockContent content, TextOffset offset)
 {
     Content = content;
     Offset  = offset;
 }
 // <summary> Gets a cursor that is looking at the grapheme at the given index. </summary>
 public static TextCaret FromOffset(TextBlockContent span, TextOffset offset)
 {
     // TODO validate
     return(new TextCaret(span, offset));
 }
 /// <summary> Gets a cursor that is looking at the grapheme at the given index. </summary>
 public static TextCaret FromOffset(TextBlockContent content, int graphemeIndex)
 {
     // TODO validate
     return(FromOffset(content, content.Buffer.GetOffsetToGraphemeIndex(graphemeIndex).GetValueOrDefault()));
 }
 /// <summary>
 ///  Gets a cursor that is looking at the character at the given index.
 ///
 ///  Potentially very expensive, and should be avoided in favor of
 ///  <see cref="FromOffset(TextSpan,int)"/> instead.
 /// </summary>
 /// <param name="span"> The span that the cursor is currently pointing towards. </param>
 public static TextCaret FromCharacterIndex(TextBlockContent content, int characterIndex)
 {
     return(FromOffset(content, content.Buffer.GetOffsetToCharacterIndex(characterIndex).GetValueOrDefault()));
 }
 /// <summary> Gets a cursor that is looking at the end of the content. </summary>
 public static TextCaret FromEnd(TextBlockContent content)
 {
     return(new TextCaret(content,
                          TextOffsetHelpers.CreateAfterTextOffset(content.Buffer)));
 }
 /// <summary> Gets a cursor that is looking at the beginning of the content. </summary>
 public static TextCaret FromBeginning(TextBlockContent content)
 {
     return(new TextCaret(content, content.Buffer.GetFirstOffset()));
 }
Ejemplo n.º 9
0
 public TextBlockContentChangedEventArgs(TextBlockContent changedBlockContent)
 {
     ChangedBlockContent = changedBlockContent;
 }
Ejemplo n.º 10
0
 /// <summary> TextBlockContent constructor. </summary>
 internal TextBlockContent(TextBlockContent content)
     : this(content.GetText())
 {
 }