public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == _guid && nCmdID == _commandId && Clipboard.ContainsText())
            {
                string       text    = Clipboard.GetText(TextDataFormat.Text);
                PasteCleaner cleaner = new PasteCleaner(text);

                if (cleaner.IsDirty())
                {
                    TextDocument doc   = (TextDocument)_dte.ActiveDocument.Object("TextDocument");
                    EditPoint    start = doc.Selection.TopPoint.CreateEditPoint();

                    // First insert plain text
                    _dte.UndoContext.Open("Paste");
                    doc.Selection.Insert(text);
                    _dte.UndoContext.Close();

                    // Then replace with clean text, so undo restores the default behavior
                    ReplaceText(cleaner, doc, start, text);

                    return(VSConstants.S_OK);
                }
            }

            return(_nextCommandTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
        private void ReplaceText(PasteCleaner cleaner, TextDocument doc, EditPoint start, string text)
        {
            string clean = cleaner.Clean();

            _dte.UndoContext.Open("Paste FixR");

            // Insert
            start.ReplaceText(text.Replace("\n", string.Empty).Length, clean, 0);
            //start.Insert(clean);

            // Format
            doc.Selection.MoveToPoint(start, true);
            FormatSelection();
            _textView.Selection.Clear();

            _dte.UndoContext.Close();
        }