Beispiel #1
0
        /// <summary>
        /// Insert the content of a SourceText from a position up to a position.
        /// </summary>
        /// <param name="text">The SourceText to insert</param>
        /// <param name="from">The start location</param>
        /// <param name="to">The end location</param>
        public override void Insert(SourceText paste, int from, int to)
        {
            if (!CheckRange(length, from, to))
            {
                return;
            }

            GapSourceText ft;

            char[] buf = null;

            if (!(paste is GapSourceText))
            {  // convert the text into a GapText
                int s = paste.Size;
                buf = new char[s];
                paste.CopyInStr(buf, s, 0, s);
                ft = new GapSourceText(buf, s, true);
            }
            else
            {
                ft = (GapSourceText)paste;
            }

            int shift = ft.length - (to - from);

            if ((to - from) > 0)
            {
                Send(new TextChangeInfo(TextChanges.TextAboutDeleted, from, to));
            }

            if (HighWaterMark(shift))
            {
                Expand(GrowBy(size + shift), from);
            }
            else
            {
                MoveGap(from);
            }

            ft.CopyTo(body, from, 0, ft.length);

            length    += shift;
            gaplen    -= shift;
            part1len  += ft.length;
            part2body -= shift;
            part2len   = length - part1len;
            body2      = part2body + part1len;

            if (LowWaterMark())
            {
                Shrink();
            }
            base.Insert(paste, from, to);
            base.Send(new TextChangeInfo(TextChanges.TextReplaced, from, to, paste.Size), paste);
        }
        /// <summary>
        /// Insert the content of a SourceText from a position up to a position.
        /// </summary>
        /// <param name="text">The SourceText to insert</param>
        /// <param name="from">The start location</param>
        /// <param name="to">The end location</param>
        public override void Insert(SourceText paste, int from, int to)
        {
            StringSourceText ct;

            char[] buf = null;

            if (!(paste is StringSourceText))
            { // try to convert
                int s = paste.Size;
                buf = new char[s];
                paste.CopyInStr(buf, s, 0, s);
                ct = new StringSourceText(buf, s);
            }
            else
            {
                ct = (StringSourceText)paste;
            }

            int shift = ct.next - (to - from);

            if (!CheckRange(next, from, to))
            {
                return;
            }

            if ((to - from) > 0)
            {
                Send(new TextChangeInfo(TextChanges.TextAboutDeleted, from, to));
            }

            if (HighWaterMark(shift))
            {
                Expand(GrowBy(size + shift));
            }

            if (shift < 0)
            {
                Array.Copy(content, to, content, to + shift, next - to);
            }
            else if (shift > 0)
            {
                Array.Copy(content, from, content, from + shift, next - from);
            }

            //---- insert pasted text
            Array.Copy(ct.content, 0, content, from, ct.next);
            next += shift;
            if (LowWaterMark())
            {
                Expand(size / 2);
            }
            base.Insert(paste, from, to);
            Send(new TextChangeInfo(TextChanges.TextReplaced, from, to, paste.Size), paste);
        }