/// <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); } }
/// <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); } }
/// <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); } }