Exemplo n.º 1
0
        public CellString GetText(int offset, int length)
        {
            VerifyAccess();
            var cells = new CellString(length);

            // Get the line the contains 'offset'
            var line = LineByOffset(offset);
            var i    = offset - line.BegOffset;

            for (; line != null; line = line.NextLine, i = 0)
            {
                // Insert newline delimiters between lines
                if (cells.Length != 0)
                {
                    var len = Math.Min(length, LineEnd.Length);
                    cells.Append(LineEnd, 0, len);
                    length -= len;
                }

                // Insert text from 'line'
                {
                    var len = Math.Min(length, line.Length);
                    cells.Append(line, i, len);
                    length -= len;
                }
            }

            return(cells);
        }
Exemplo n.º 2
0
        public void SetText(CellString text, int start, int length)
        {
            Debug.Assert(Validate(text, start, length));

            Text.Length = 0;
            Text.Append(text, start, length);
            Invalidate();
        }
Exemplo n.º 3
0
        /// <summary>Gets the selected text.</summary>
        public virtual CellString GetText()
        {
            var doc = TextArea.Document;

            if (doc == null)
            {
                throw new Exception("No associated TextDocument");
            }

            var iter = Segments.GetEnumerator();

            // No segments
            if (!iter.MoveNext())
            {
                return(CellString.Empty);
            }

            // If there is only one segment, return the text directly
            var text = doc.GetText(iter.Current);

            if (!iter.MoveNext())
            {
                return(text);
            }

            // Otherwise, combine text from the segments
            var cstr = new CellString(text)
            {
                Capacity = Length
            };

            for (var more = true; more; more = iter.MoveNext())
            {
                cstr.Append(doc.GetText(iter.Current));
            }

            return(cstr);
        }
Exemplo n.º 4
0
 public CellString(CellString str)
     : this(str.Length)
 {
     m_text.Append(str.m_text);
     m_style.AddRange(str.m_style);
 }
Exemplo n.º 5
0
 /// <summary>Set the whole line to the given text and style</summary>
 public void SetText(CellString text) => SetText(text, 0, text.Length);
Exemplo n.º 6
0
 internal Line(CellString text, int start, int length)
     : this()
 {
     SetText(text, start, length);
 }
Exemplo n.º 7
0
 internal Line(CellString text)
     : this()
 {
     SetText(text);
 }
Exemplo n.º 8
0
        // Notes:
        //  - An IList<Cell> is basically a StringBuilder
        //  - 'Text' should not include new-line characters.
        //    There is an implicit new line at the end of each line.
        //  - There isn't a reference to 'TextDocument' because Line's
        //    shouldn't know about Documents, and it's wasteful of memory.
        //  - The new-line is not included in the returned text because
        //    that would require a dependency on the 'Document' for 'LineEnd'.
        //  - A document (and therefore these Lines) can be shared by multiple
        //    view controls. Don't store WPF visuals in this class.

        internal Line()
        {
            Text = new CellString();
        }