internal static void AddExpansionComment(CodeFunction codeFunction) { EditPoint edPoint = codeFunction.EndPoint.CreateEditPoint(); edPoint.LineUp(2); if (edPoint.GreaterThan(codeFunction.StartPoint)) { edPoint.Insert(GetComment(codeFunction.Language)); } }
/// <summary> /// Gets the code block for a given element, this includes any comments that come before the element, /// but after the previous element. /// </summary> /// <param name="parent">The current block's parent.</param> /// <param name="block">The current block.</param> /// <param name="newStartPoint">The starting point used to capture the beginning of the element.</param> /// <returns>The text of a given block.</returns> private string GetCodeBlockText(CodeElement parent, CodeElement block, out EditPoint newStartPoint) { EditPoint blockStartPoint = block.StartPoint.CreateEditPoint(); EditPoint previousblockEndPoint = blockStartPoint.CreateEditPoint(); EditPoint editPoint = blockStartPoint.CreateEditPoint(); TextRanges trs = null; if (editPoint.FindPattern("}", (int)vsFindOptions.vsFindOptionsBackwards, ref previousblockEndPoint, ref trs)) { if (previousblockEndPoint.GreaterThan(parent.StartPoint)) { blockStartPoint = previousblockEndPoint; } else { previousblockEndPoint = blockStartPoint.CreateEditPoint(); editPoint = blockStartPoint.CreateEditPoint(); if (editPoint.FindPattern("{", (int)vsFindOptions.vsFindOptionsBackwards, ref previousblockEndPoint, ref trs)) { if (previousblockEndPoint.GreaterThan(parent.StartPoint)) { blockStartPoint = previousblockEndPoint; } } } } else { if (editPoint.FindPattern("{", (int)vsFindOptions.vsFindOptionsBackwards, ref previousblockEndPoint, ref trs)) { if (previousblockEndPoint.GreaterThan(parent.StartPoint)) { blockStartPoint = previousblockEndPoint; } } } newStartPoint = blockStartPoint.CreateEditPoint(); return(blockStartPoint.GetText(block.EndPoint).Trim()); }
private static void MoveCodeBlock(CodeElement parent, CodeElement block, EditPoint pastePoint) { EditPoint blockStartPoint = block.StartPoint.CreateEditPoint(); EditPoint previousblockEndPoint = blockStartPoint.CreateEditPoint(); EditPoint editPoint = blockStartPoint.CreateEditPoint(); TextRanges trs = null; if (editPoint.FindPattern("}", (int)vsFindOptions.vsFindOptionsBackwards, ref previousblockEndPoint, ref trs)) { if (previousblockEndPoint.GreaterThan(parent.StartPoint)) { blockStartPoint = previousblockEndPoint; } } blockStartPoint.Cut(block.EndPoint, false); pastePoint.Paste(); pastePoint.Insert("\r\n\r\n"); }
public static bool DeleteCodeSite(this CodeFunction value, bool bDelete = true) { if (bDelete && !value.ExistsCodeSite()) { return(true); } EditPoint epStart = value.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint(); EditPoint epEnd = value.GetEndPoint(vsCMPart.vsCMPartBody).CreateEditPoint(); EditPoint epFind = null, epFindStart = null; bool Find(string text, bool start) { string[] textSplit; if (start) { epFind = epStart.CreateEditPoint(); textSplit = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); } else { epFind = epEnd.CreateEditPoint(); textSplit = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Reverse().ToArray(); } int iLine = 0; foreach (var item in textSplit) { int i = item.IndexOfAny(new char[] { '(', ' ' }); string s = i == -1 ? item : item.Substring(0, i + 1); if ((start ? epFind.FindPattern(s) : epFind.FindPattern(s, (int)vsFindOptions.vsFindOptionsBackwards)) && (start ? epFind.LessThan(epEnd) : epFind.GreaterThan(epStart)) && (iLine == 0 || iLine == epFind.Line - (start ? 1 : -1))) { if (iLine == 0) { epFindStart = epFind.CreateEditPoint(); } iLine = epFind.Line; if (start) { epFind.EndOfLine(); } } else { return(false); } } return(true); } void Delete() { if (epFind.GreaterThan(epFindStart)) { epFind.LineDown(1); } else { epFindStart.LineDown(1); } epFind.StartOfLine(); epFindStart.StartOfLine(); epFindStart.Delete(epFind); } if (!Find(value.CSEnterText(), true)) { return(false); } else if (bDelete) { Delete(); } if (!Find(value.CSExitText(), false)) { return(false); } else if (bDelete) { Delete(); } else { return(true); } if (Find(value.CSCatchText(), false) && bDelete) { Delete(); } //格式化指定范围内的文本 value.StartPoint.CreateEditPoint().SmartFormat(value.EndPoint); return(true); }