示例#1
0
        public static TextData GetTextDataFrom(RichTextBox rtb, BaseTextData btd, string eol)
        {
            DbgValidateEol(eol);
            DbgValidateEol(btd.Eol);
            Debug.Assert(object.ReferenceEquals(rtb.Document, btd.TextPointers.Doc));

            string       text;
            TextPointers textpointers;

            if (btd.Eol == eol)
            {
                text = btd.Text;
            }
            else
            {
                text = btd.Text.Replace(btd.Eol, eol);
            }

            if (btd.Eol.Length == eol.Length)
            {
                textpointers = btd.TextPointers;
            }
            else
            {
                textpointers = new TextPointers(rtb.Document, eol.Length);
            }

            var(selection_start, selection_end) = GetSelection(rtb.Selection, textpointers);

            return(new TextData(text, eol, textpointers, selection_start, selection_end));
        }
示例#2
0
        internal readonly TextPointers TextPointers; // (maps string index of 'Text' to 'TextPointer')

#pragma warning restore CA1051                       // Do not declare visible instance fields

        internal BaseTextData(string text, string eol, TextPointers pointers)
        {
            Debug.Assert(eol.Length == pointers.EolLength);

            Text         = text;
            Eol          = eol;
            TextPointers = pointers;
        }
示例#3
0
#pragma warning restore CA1051 // Do not declare visible instance fields

        internal TextData(string text, string eol, TextPointers pointers, int selectionStart, int selectionEnd)
            : base(text, eol, pointers)
        {
            SelectionStart = selectionStart;
            SelectionEnd   = selectionEnd;
        }
示例#4
0
        static (int selection_start, int selection_end) GetSelection(TextSelection selection, TextPointers pointers)
        {
            // TODO: implement 'pointers.GetIndices' that takes two text pointers
            int selection_start = Math.Max(0, pointers.GetIndex(selection.Start, LogicalDirection.Backward));
            int selection_end   = Math.Max(0, pointers.GetIndex(selection.End, LogicalDirection.Forward));

            return(selection_start, selection_end);
        }