Ejemplo n.º 1
0
        /// <summary>
        /// insert a linebreak at cursor
        /// </summary>
        public void InsertBreak(bool paragraph)
        {
            //TODO: Make paragraph InsertBreak not require full reload.
            if (paragraph)
            {
                CursorPosition cur = firstCursor.CursorPosition();
//				string seperator = "<p>";
//				if (firstCursor.selectedTag.HaveLastTagNamed("p"))
//					seperator = "</p><p>";

                string seperator = firstCursor.selectedTag.LastRegionTag().name;
                if (firstCursor.selectedTag.HaveLastTagNamed(seperator))
                {
                    seperator = String.Format("</{0}><{0}{1}> ", seperator, firstCursor.selectedTag.LastRegionTag().variables.Html());
                }
                else
                {
                    seperator = String.Format("<{0}> ", seperator);
                }

                string BeforeSel = parentHtml.HtmlBeforeSelection();
                string AfterSel  = parentHtml.HtmlAfterSelection();

                parentHtml.parser.Parse(BeforeSel + seperator + AfterSel);
                parentHtml.documentOutput.Update();
                SetStartCursor(cur);
                startCursor = startCursor.RightShiftText();
                SetEndCursor(startCursor.selectedTag, startCursor.selectedLine, startCursor.selectedChar);
            }
            else
            {
                TextTag txtTag = new TextTag(parentHtml, SplitText());
                //if (txtTag.text == "") return;
                firstCursor.selectedTag.parentTag.AddTag(firstCursor.selectedTag.ParentTagIndex() + 1,
                                                         txtTag);

                Int32     tagID  = Utils.LocateTag(Utils.RemoveFrontSlash("br"));
                RegionTag newTag = new RegionTag(parentHtml, "br", new PropertyList(), tagID, 0);
                firstCursor.selectedTag.parentTag.AddTag(firstCursor.selectedTag.ParentTagIndex() + 1,
                                                         newTag);
                parentHtml.Invalidate();
                parentHtml.documentOutput.Update();

                SetStartCursor(txtTag, 0);
                SetEndCursor(startCursor.selectedTag, startCursor.selectedLine, startCursor.selectedChar);
            }
        }
Ejemplo n.º 2
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);
            }
        }