Пример #1
0
 internal PointF GetFocusPosition(HtmlTag aTag, out Int32 aLine, ref Int32 aChar)
 {
     aLine = -1;
     if (aTag is TextTag)
     {
         TextTag tag = (TextTag)aTag;
         tag.LocateText(out aLine, ref aChar);
     }
     return(GetFocusPosition(aTag, aLine, aChar));
 }
Пример #2
0
        /// <summary>
        /// return a cursor that point to the tag right side of current
        /// </summary>
        public MiniHtmlCursor RightShift(bool fullTag)
        {
            MiniHtmlCursor retVal = new MiniHtmlCursor(parentHtml);

            if ((selectedTag is TextTag) && !(fullTag))
            {
                TextTag currentTag = (TextTag)(selectedTag);
                Int32   pos        = currentTag.LocateText(selectedLine, selectedChar);
                if (pos >= currentTag.text.Length)
                {
                    fullTag = true;
                }
                else
                {
                    Int32 aLine = 0, aChar = pos + 1;
                    currentTag.LocateText(out aLine, ref aChar);
                    retVal.SetCursor(selectedTag, aLine, aChar);
                    return(retVal);
                }
            }

            HtmlTag nextTag = selectedTag.nextTag();

            if (nextTag == null)
            {
                return(null);
            }
            else
            {
                if (!(nextTag is TextTag))
                {
                    retVal.SetCursor(nextTag, -1);
                }
                else
                {
                    retVal.SetCursor(nextTag, 0);
                }
            }
            return(retVal);
        }
Пример #3
0
        /// <summary>
        /// Insert text to current cursor.
        /// </summary>
        public void InsertText(string aText)
        {
            if ((startCursor.selectedTag is TextTag) && (startCursor.selectedTag == endCursor.selectedTag))
            {
                TextTag currentTag = (TextTag)startCursor.selectedTag;
                Int32   sPos       = currentTag.LocateText(firstCursor.selectedLine,
                                                           firstCursor.selectedChar);
                currentTag.ReplaceText(firstCursor, secondCursor, aText);

                parentHtml.documentOutput.Update();

                SetStartCursor(currentTag, sPos + aText.Length);
                SetEndCursor(currentTag, startCursor.selectedLine, startCursor.selectedChar);
            }
        }
Пример #4
0
        /// <summary>
        /// Replace selection to specified text
        /// </summary>
        private void replace(bool textOnly, string aText)
        {
            if ((startCursor.selectedTag == null) || (endCursor.selectedTag == null))
            {
                return;
            }

            if (startCursor.selectedTag != endCursor.selectedTag)
            {
                ((TextTag)(secondCursor.selectedTag)).ReplaceText(firstCursor, secondCursor, "");
                endCursor = endCursor.LeftShift(true);
            }

            while (secondCursor.selectedTag.TagIndex() > firstCursor.selectedTag.TagIndex())
            {
                HtmlTag currentTag = secondCursor.selectedTag;
                secondCursor = secondCursor.LeftShift(true);
                if ((currentTag is TextTag) || !(textOnly))
                {
                    currentTag.RemoveSelf();
                }
            }

            if ((startCursor.selectedTag is TextTag) && (startCursor.selectedTag == endCursor.selectedTag))
            {
                TextTag currentTag = (TextTag)startCursor.selectedTag;
                Int32   sPos       = currentTag.LocateText(startCursor.selectedLine,
                                                           startCursor.selectedChar);
                currentTag.ReplaceText(firstCursor, secondCursor, aText);

                parentHtml.documentOutput.Update();

                SetStartCursor(currentTag, sPos + aText.Length);
                SetEndCursor(currentTag, startCursor.selectedLine, startCursor.selectedChar);
            }
        }
Пример #5
0
        /// <summary>
        /// Remove selected items.
        /// </summary>
        public void RemoveSelection(bool TextOnly)
        {
            if ((startCursor.selectedTag == null) || (endCursor.selectedTag == null))
            {
                return;
            }

            MiniHtmlCursor firstCur  = new MiniHtmlCursor(parentHtml);
            MiniHtmlCursor secondCur = new MiniHtmlCursor(parentHtml);

            firstCur.SetCursor(firstCursor.selectedTag, firstCursor.selectedLine, firstCursor.selectedChar);
            secondCur.SetCursor(secondCursor.selectedTag, secondCursor.selectedLine, secondCursor.selectedChar);

//          if (!(startCursor.selectedTag is TextTag) || !(endCursor.selectedTag is TextTag))
//              return;

            if (firstCur.selectedTag != secondCur.selectedTag)
            {
                if (firstCur.selectedTag is TextTag)
                {
                    ((TextTag)(secondCur.selectedTag)).ReplaceText(firstCur, secondCursor, "");
                }
                secondCur = secondCur.LeftShift(true);
            }

            while (secondCur.selectedTag.TagIndex() > firstCur.selectedTag.TagIndex())
            {
                HtmlTag currentTag = secondCur.selectedTag;
                secondCur = secondCur.LeftShift(true);
                if ((currentTag is TextTag) || (!(TextOnly) && (currentTag is RegionTag)))
                {
//                  Console.WriteLine("removing " + currentTag.name);
//                  if (currentTag is TextTag) Console.WriteLine(((TextTag)currentTag).text);
                    currentTag.RemoveSelf();
                }
            }

            if (firstCur.selectedTag is RegionTag)
            {
                HtmlTag currentTag = firstCur.selectedTag;

                firstCur = firstCur.RightShiftText();

                SetEndCursor(firstCur.selectedTag, 0);

                currentTag.RemoveSelf();
            }

            if ((firstCur.selectedTag is TextTag) && (firstCur.selectedTag == secondCur.selectedTag))
            {
                TextTag currentTag = (TextTag)firstCur.selectedTag;
                Int32   sPos       = currentTag.LocateText(firstCur.selectedLine,
                                                           firstCur.selectedChar);
                currentTag.ReplaceText(firstCur, secondCur, "");

                parentHtml.Invalidate();
                parentHtml.documentOutput.Update();

                SetStartCursor(currentTag, sPos);
                SetEndCursor(startCursor.selectedTag, startCursor.selectedLine, startCursor.selectedChar);
            }
        }