Ejemplo n.º 1
0
        public bool SetCaretOffset(int offset)
        {
            if (offset < 0)
            {
                return(false);
            }
            SWF.Document document = Document;
            int          curPos   = 0;

            SWF.Line line = null;
            for (int i = 1; i <= document.Lines; i++)
            {
                line = document.GetLine(i);
                int length = line.Text.ToString().Length;
                if (curPos + length >= offset)
                {
                    document.PositionCaret(line, offset - curPos);
                    return(true);
                }
                curPos += length;
            }
            return(false);
        }
Ejemplo n.º 2
0
        public void DeleteCharacters(int pos, int count)
        {
            LineTag tag;
            bool    streamline = false;

            // Can't delete more than the line has
            if (pos >= text.Length)
            {
                return;
            }

            // Find the first tag that we are deleting from
            tag = FindTag(pos + 1);

            // Remove the characters from the line
            text.Remove(pos, count);

            if (tag == null)
            {
                return;
            }

            // Check if we're crossing tag boundaries
            if ((pos + count) > (tag.Start + tag.Length - 1))
            {
                int left;

                // We have to delete cross tag boundaries
                streamline = true;
                left       = count;

                left -= tag.Start + tag.Length - pos - 1;
                tag   = tag.Next;

                // Update the start of each tag
                while ((tag != null) && (left > 0))
                {
                    // Cache tag.Length as is will be indireclty modified
                    // by changes to tag.Start
                    int tag_length = tag.Length;
                    tag.Start -= count - left;

                    if (tag_length > left)
                    {
                        left = 0;
                    }
                    else
                    {
                        left -= tag_length;
                        tag   = tag.Next;
                    }
                }
            }
            else
            {
                // We got off easy, same tag

                if (tag.Length == 0)
                {
                    streamline = true;
                }
            }

            // Delete empty orphaned tags at the end
            LineTag walk = tag;

            while (walk != null && walk.Next != null && walk.Next.Length == 0)
            {
                LineTag t = walk;
                walk.Next = walk.Next.Next;
                if (walk.Next != null)
                {
                    walk.Next.Previous = t;
                }
                walk = walk.Next;
            }

            // Adjust the start Point_ of any tags following
            if (tag != null)
            {
                tag = tag.Next;
                while (tag != null)
                {
                    tag.Start -= count;
                    tag        = tag.Next;
                }
            }

            recalc = true;

            if (streamline)
            {
                Streamline(document.Lines);
            }
        }