public static int HandleCommand(IWpfTextView textView, IClassifier classifier, OleInterop.IOleCommandTarget commandTarget, IEditorOperations editorOperations) { // TODO: Handle UNDO management. This should occur as a single undo-able transaction in the Undo history editorOperations.MoveToEndOfLine(false); editorOperations.Delete(); editorOperations.DeleteHorizontalWhiteSpace(); return(VSConstants.S_OK); }
public static void ReplaceSelectedLines(ITextView textView, IEditorOperations editorOperations) { if (textView.Selection.IsEmpty) { return; } var selectedSpan = textView.Selection.SelectedSpans[0]; string origin, change; string title = "Replace With Preserve Sensitive Case"; origin = Prompt.ShowDialog("Replace From : ", title); if (origin.Length == 0) { return; } change = Prompt.ShowDialog("Replace To : ", title); if (origin.Length != change.Length) { return; } string trans = Regex.Replace(selectedSpan.GetText(), origin, new MatchEvaluator((Match match) => { string val = match.Value; char[] arrayVal = val.ToCharArray(); int len = val.Length; for (int i = 0; i < len; ++i) { if (char.IsUpper(arrayVal[i])) { arrayVal[i] = char.ToUpper(change[i]); } else { arrayVal[i] = char.ToLower(change[i]); } } return(new string(arrayVal)); }) , RegexOptions.IgnoreCase); textView.TextBuffer.Replace(selectedSpan, trans); //editorOperations.MoveToEndOfLine(extendSelection: false); //editorOperations.Delete(); editorOperations.DeleteHorizontalWhiteSpace(); }
public static void JoinSelectedLines(ITextView textView, IEditorOperations editorOperations) { if (textView.Selection.IsEmpty) { return; } var selectedSpan = textView.Selection.SelectedSpans[0]; textView.TextBuffer.Replace(selectedSpan, selectedSpan.GetText().Replace("\r\n", " ")); editorOperations.MoveToEndOfLine(extendSelection: false); editorOperations.Delete(); editorOperations.DeleteHorizontalWhiteSpace(); }