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); }
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)); }
public void PlusGitHub() { string raw = "+ private const string _regex = @\"^([\\d]+|\\+|\\-)(\\s|\\.)?\";\r\n+ private const string _regex = @\"^([\\d]+|\\+|\\-)(\\s|\\.)?\";\r\n+ private const string _regex = @\"^([\\d]+|\\+|\\-)(\\s|\\.)?\";\r\n"; string expected = " private const string _regex = @\"^([\\d]+|\\+|\\-)(\\s|\\.)?\";\r\n private const string _regex = @\"^([\\d]+|\\+|\\-)(\\s|\\.)?\";\r\n private const string _regex = @\"^([\\d]+|\\+|\\-)(\\s|\\.)?\";"; _cleaner = new PasteCleaner(raw); _cleaner.IsDirty(); string actual = _cleaner.Clean(); Assert.AreEqual(expected, actual); }
public void LineNumberFirefox() { string raw = "1\t<PropertyGroup>\r\n2\t <DeployOnBuild Condition=\" '$(DeployProjA)'!='' \">$(DeployProjA)</DeployOnBuild>\r\n3\t</PropertyGroup>"; string expected = "<PropertyGroup>\r\n <DeployOnBuild Condition=\" '$(DeployProjA)'!='' \">$(DeployProjA)</DeployOnBuild>\r\n</PropertyGroup>"; _cleaner = new PasteCleaner(raw); _cleaner.IsDirty(); string actual = _cleaner.Clean(); Assert.AreEqual(expected, actual); }
public void CleanEmptyLines() { string raw = "public static string RemoveWhiteSpaceFromStylesheets(string body)\r\n\r\n{\r\n\r\n body = Regex.Replace(body, @\"[a-zA-Z]+#\", \"#\");\r\n\r\n body = Regex.Replace(body, @\"[\\n\\r]+\\s*\", string.Empty);\r\n\r\n body = Regex.Replace(body, @\"\\s+\", \" \");\r\n\r\n body = Regex.Replace(body, @\"\\s?([:,;{}])\\s?\", \"$1\");\r\n\r\n body = body.Replace(\";}\", \"}\");\r\n\r\n body = Regex.Replace(body, @\"([\\s:]0)(px|pt|%|em)\", \"$1\");\r\n\r\n \r\n\r\n // Remove comments from CSS\r\n\r\n body = Regex.Replace(body, @\"/\\*[\\d\\D]*?\\*/\", string.Empty);\r\n\r\n \r\n\r\n return body;\r\n\r\n}\r\n"; string expected = "public static string RemoveWhiteSpaceFromStylesheets(string body)\r\n{\r\n body = Regex.Replace(body, @\"[a-zA-Z]+#\", \"#\");\r\n body = Regex.Replace(body, @\"[\\n\\r]+\\s*\", string.Empty);\r\n body = Regex.Replace(body, @\"\\s+\", \" \");\r\n body = Regex.Replace(body, @\"\\s?([:,;{}])\\s?\", \"$1\");\r\n body = body.Replace(\";}\", \"}\");\r\n body = Regex.Replace(body, @\"([\\s:]0)(px|pt|%|em)\", \"$1\");\r\n \r\n // Remove comments from CSS\r\n body = Regex.Replace(body, @\"/\\*[\\d\\D]*?\\*/\", string.Empty);\r\n \r\n return body;\r\n}"; _cleaner = new PasteCleaner(raw); _cleaner.IsDirty(); string actual = _cleaner.Clean(); Assert.AreEqual(expected, actual); }
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(); }