public bool make(TextDocument textDocument, String orgText, String newText)
        {
            Document           hDocument = textDocument.Parent as Document;
            BreakpointsManager hBPMgr    = new BreakpointsManager(m_serviceProvider);
            BookmarkManager    hBMMgr    = new BookmarkManager();

            hBPMgr.Save(hDocument.FullName, false);
            hBMMgr.Save(textDocument);

            int iLine           = textDocument.Selection.ActivePoint.Line;
            int iLineCharOffset = textDocument.Selection.ActivePoint.LineCharOffset;

            int findOptions = (int)(vsFindOptions.vsFindOptionsFromStart | vsFindOptions.vsFindOptionsMatchInHiddenText);

            textDocument.ReplaceText(orgText, newText, findOptions);

            // set by EditPoint didn't work correctly :|
            int iMinLine = Math.Min(iLine, textDocument.EndPoint.Line);

            textDocument.Selection.GotoLine(iMinLine, false); // MoveToLineAndOffset( iMinLine, 1, false );

            int iCharOffset = Math.Min(iLineCharOffset, textDocument.Selection.ActivePoint.LineLength);

            textDocument.Selection.MoveToLineAndOffset(iMinLine, iCharOffset == 0 ? 1 : iCharOffset, false);

            hBPMgr.Restore();
            hBMMgr.Restore();

            return(true);
        }
        public bool make(TextDocument textDocument, String orgText, String newText)
        {
            BreakpointsManager hBPMgr    = new BreakpointsManager(m_serviceProvider);
            BookmarkManager    hBMMgr    = new BookmarkManager();
            Document           hDocument = textDocument.Parent as Document;

            DiffPlex.Differ           diff   = new DiffPlex.Differ();
            DiffPlex.Model.DiffResult result = diff.CreateLineDiffs(orgText, newText, false, false);

            hBPMgr.Save(hDocument.FullName, false);
            hBMMgr.Save(textDocument);

            textDocument.DTE.UndoContext.Open("CodeBeautiful");
            try
            {
                int lineOffset = 0;
                foreach (var diffBlock in result.DiffBlocks)
                {
                    EnvDTE80.EditPoint2 editpoint = textDocument.CreateEditPoint() as EnvDTE80.EditPoint2;
                    EnvDTE80.EditPoint2 endLine   = textDocument.CreateEditPoint() as EnvDTE80.EditPoint2;
                    editpoint.MoveToLineAndOffset(diffBlock.DeleteStartA + lineOffset + 1, 1);
                    try
                    {
                        endLine.MoveToLineAndOffset(diffBlock.DeleteStartA + lineOffset + diffBlock.DeleteCountA + 1, 1);
                    }
                    catch (System.ArgumentException /*ex*/)
                    {
                        endLine.MoveToLineAndOffset(diffBlock.DeleteStartA + lineOffset + diffBlock.DeleteCountA, 1);
                        endLine.EndOfLine();
                    }

                    editpoint.Delete(endLine);
                    editpoint.InsertNewLine(diffBlock.InsertCountB);
                    for (int line = 0; line < diffBlock.InsertCountB; ++line)
                    {
                        editpoint.MoveToLineAndOffset(diffBlock.DeleteStartA + lineOffset + line + 1, 1);
                        editpoint.Insert(result.PiecesNew[diffBlock.InsertStartB + line]);
                    }
                    lineOffset += diffBlock.InsertCountB - diffBlock.DeleteCountA;
                }
            }
            catch (Exception e)
            {
                textDocument.DTE.UndoContext.Close();
                throw e;
            }

            textDocument.DTE.UndoContext.Close();

            // Restoring break points should take into consideration that some lines was changed or added
            hBPMgr.Restore();
            hBMMgr.Restore();

            return(true);
        }