/// <summary> /// Selects the current member. /// </summary> /// <param name="caret">The caret.</param> /// <param name="textDocument">The text document.</param> /// <returns></returns> public static bool SelectCurrentMember(CaretServices caret, TextDocument textDocument) { bool result = false; if (caret == null || textDocument == null) { return(result); } if (caret.InsideCode == true) { SourcePoint sourcePoint = caret.SourcePoint; LanguageElement element = textDocument.GetNodeAt(sourcePoint); if (element.CanBeDocumented == false || element.ElementType == LanguageElementType.EnumElement) { element = element.GetParentElementThatCanBeDocumented(); } SourceRange range = element.GetFullBlockRange(BlockElements.AllSupportElements); CodeRush.Selection.SelectRange(range); result = true; } return(result); }
/// <summary> /// Executes the regex replace. /// </summary> /// <param name="textDocument">The text document.</param> /// <param name="regex">The regex.</param> /// <param name="replaceWith">The replace with.</param> public static void ExecuteRegexReplace(TextDocument textDocument, string regex, string replaceWith) { if (textDocument == null) { return; } SourcePoint cursorPosition = CodeRush.Caret.SourcePoint; try { textDocument.Lock(); string text = textDocument.Text; text = Regex.Replace(text, regex, replaceWith, RegexOptions.Singleline | RegexOptions.Compiled); textDocument.SetText(textDocument.Range, text); } catch (Exception ex) { HandleException(ex); } finally { if (cursorPosition != SourcePoint.Empty) { CodeRush.Caret.MoveTo(cursorPosition); } textDocument.Unlock(); } }
/// <summary> /// Executes the regex replace. /// </summary> /// <param name="textDocument">The text document.</param> /// <param name="regex">The regex.</param> /// <param name="replaceWith">The replace with.</param> public static void ExecuteRegexReplace(TextDocument textDocument, string regex, string replaceWith) { if (textDocument == null) return; SourcePoint cursorPosition = CodeRush.Caret.SourcePoint; try { textDocument.Lock(); string text = textDocument.Text; text = Regex.Replace(text, regex, replaceWith, RegexOptions.Singleline | RegexOptions.Compiled); textDocument.SetText(textDocument.Range, text); } catch (Exception ex) { HandleException(ex); } finally { if (cursorPosition != SourcePoint.Empty) CodeRush.Caret.MoveTo(cursorPosition); textDocument.Unlock(); } }
/// <summary> /// Deletes the whitespace. /// </summary> /// <param name="textDocument">The text document.</param> public static void DeleteWhitespace(TextDocument textDocument) { ExecuteRegexReplace(textDocument, WhitespaceRegexReplace, Environment.NewLine); }
/// <summary> /// Selects the current member. /// </summary> /// <param name="caret">The caret.</param> /// <param name="textDocument">The text document.</param> /// <returns></returns> public static bool SelectCurrentMember(CaretServices caret, TextDocument textDocument) { bool result = false; if (caret == null || textDocument == null) return result; if (caret.InsideCode == true) { SourcePoint sourcePoint = caret.SourcePoint; LanguageElement element = textDocument.GetNodeAt(sourcePoint); if (element.CanBeDocumented == false || element.ElementType == LanguageElementType.EnumElement) element = element.GetParentElementThatCanBeDocumented(); SourceRange range = element.GetFullBlockRange(BlockElements.AllSupportElements); CodeRush.Selection.SelectRange(range); result = true; } return result; }