/// <summary> /// Return a cursor that point to the next visible tag /// Ignore non-Visible tag and last character of TextTag (except if it's last tag in current line) /// </summary> public MiniHtmlCursor RightShiftText() { MiniHtmlCursor currentCursor = new MiniHtmlCursor(parentHtml); currentCursor.SetCursor(CursorPosition()); try { MiniHtmlCursor.rightShiftVisible(ref currentCursor); } catch { currentCursor.SetCursor(CursorPosition()); } if (currentCursor.selectedTag is TextTag) { bool shiftAgain = true; shiftAgain = MiniHtmlCursor.isLastChar(currentCursor) && MiniHtmlCursor.isLastTag(currentCursor) && !(currentCursor.selectedTag.nextTag() is ElementTag); if (shiftAgain) { MiniHtmlCursor.rightShiftVisible(ref currentCursor); } } return(currentCursor); }
private static void rightShiftVisible(ref MiniHtmlCursor shiftCursor) { do { shiftCursor = shiftCursor.RightShift(false); }while ((shiftCursor.selectedTag.TagIndex() < shiftCursor.parentHtml.tagPositionList.Count) && !(shiftCursor.selectedTag is VisibleTag)); }
private static void leftShiftVisible(ref MiniHtmlCursor shiftCursor) { do { shiftCursor = shiftCursor.LeftShift(false); }while ((shiftCursor.selectedTag.TagIndex() > -1) && !(shiftCursor.selectedTag is VisibleTag)); }
/// <summary> /// Is the cursor pointing to last tag of current Line? /// </summary> public static bool isLastTag(MiniHtmlCursor cursor) { if (cursor.selectedTag is TextTag) { return(((TextTag)(cursor.selectedTag)).AllocatedLine(cursor.selectedLine).LastTag() != cursor.selectedTag); } return(false); }
/// <summary> /// Is the cursor pointing to last char of currentTag? /// </summary> public static bool isLastChar(MiniHtmlCursor cursor) { if (cursor.selectedTag is TextTag) { return(((TextTag)(cursor.selectedTag))[cursor.selectedLine].Length == cursor.selectedChar); } return(false); }
public void LeftShift() { if (endCursor.selectedTag.TagIndex() < 0) { return; } try { startCursor = startCursor.LeftShiftText(); endCursor.SetCursor(startCursor.selectedTag, startCursor.selectedLine, startCursor.selectedChar); } catch { } }
/// <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); } }
/// <summary> /// Return a cursor that point to the last visible tag /// Ignore non-Visible tag and last character of TextTag (except if it's last tag in current line) /// </summary> public MiniHtmlCursor LeftShiftText() { if (selectedTag.TagIndex() < 0) { return(null); } MiniHtmlCursor currentCursor = new MiniHtmlCursor(parentHtml); currentCursor.SetCursor(CursorPosition()); MiniHtmlCursor tempCursor = new MiniHtmlCursor(parentHtml); MiniHtmlCursor.leftShiftVisible(ref currentCursor); if (currentCursor.selectedTag is TextTag) { bool shiftAgain = true; TextTag currentTag = (TextTag)(currentCursor.selectedTag); tempCursor.SetCursor(currentCursor.CursorPosition()); try { MiniHtmlCursor.leftShiftVisible(ref tempCursor); } catch { if (currentCursor == null) { currentCursor.SetCursor(CursorPosition()); } } if (tempCursor != null) { shiftAgain = (MiniHtmlCursor.isLastChar(currentCursor) && MiniHtmlCursor.isLastTag(tempCursor)) && !(currentCursor.selectedTag.nextTag() is ElementTag); if (shiftAgain) { return(tempCursor); } } } return(currentCursor); }
/// <summary> /// update selection between startCursor and endCursor /// </summary> public static void UpdateSelected(MiniHtmlCursor startCursor, MiniHtmlCursor endCursor, bool Changed) { Int32 startPos = startCursor.TagPosition(); Int32 endPos = endCursor.TagPosition(); if (endPos > startPos) { Int32 temp = startPos; startPos = endPos; endPos = startPos; } if ((endPos == -1) || (startPos == -1)) { return; } for (int i = startPos; i <= endPos; i++) { startCursor.parentHtml.tagPositionList[i].needRedraw = Changed; } }
/// <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); }
/// <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); } }
/// <summary> /// Update selection between startCursor and endCursor /// </summary> public void UpdateSelected(bool Changed) { MiniHtmlCursor.UpdateSelected(firstCursor, secondCursor, Changed); }
public MiniHtmlCursor startCursor, endCursor; //Start Cursor and End Cursor /// <summary> /// Constructor /// </summary> public Selection(MiniHtml mh) { startCursor = new MiniHtmlCursor(mh); endCursor = new MiniHtmlCursor(mh); parentHtml = mh; }