My vs2008 addin for text formatting is awfully slow

I wrote a small addition that does some formatting of my C # code. in addins exec method i do the following

try {
    TextSelection selection = (EnvDTE.TextSelection)_applicationObject.ActiveDocument.Selection;
    String foo = String.Empty;                      
    if (!text.IsEmpty) {                            
    foo = someCoolObjectThatFormatsText.Format(selection.Text);
    selection.Text = foo;  // here everything gets painfully slow :-(
    }
}
catch (Exception) {
    throw;
}

when the line with the code is "SelectedText.Text = foobar;" challenge, VS rebuilds each selection line step by step. You can easily watch how he takes this step. But I don’t understand why it is so slow.

Any clues? TIA

+3
source share
2 answers

JFTR: TextSelection.Insert(...), , , , :

TextSelection text = (EnvDTE.TextSelection)_applicationObject.ActiveDocument.Selection;
text.SmartFormat(); //  sets the correct indention als studio
/* the following lines will expand the selection to whole lines: */
int lineSpan = text.BottomPoint.Line - text.TopPoint.Line;
text.MoveToPoint(text.TopPoint,false);                      
text.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn,false);                       
text.LineDown(true,lineSpan);                       
text.EndOfLine(true);
/* and now my custom textformatting */
text.Insert(someCoolObjectThatFormatsText.Format(text.Text),(int)vsInsertFlags.vsInsertFlagsContainNewText);                                                                                    
text.Collapse();

, textselections, ,

+2

, "", .

.

" Text , Text , , , , . , , , (.. -). 128- ."

, , , ​​ , . , -.

, PasteMethod .

0

Source: https://habr.com/ru/post/1711583/


All Articles