我对文本排版VS2008插件是非常缓慢 [英] my vs2008 addin for textformatting is awfully slow

查看:204
本文介绍了我对文本排版VS2008插件是非常缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个小插件,这确实是我的C#代码一些格式。
在加载项Exec方法我做以下

i wrote a little addin, which does some formatting of my C# code. in the 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;
}

在与代码行SelectedText.Text = foobar的;为号召,VS重建选择一步一步的每一行,您可以轻松地看着它做这一步,但是我不明白,为什么它是缓慢的。

when the line with the code "SelectedText.Text = foobar;" is call, VS rebuilds each line of the selection step by step. You can easily watch it doing this step. But i don't get, why it is that slow.

任何提示?
TIA

Any hints? TIA

推荐答案

JFTR:
我不得不使用TextSelection.Insert(...),但也得到缩进的视觉工作室深度,我也只好乱用选定的文本跨越的选择也是在整个第一和最后一行:

JFTR: I had to use TextSelection.Insert(...), but to also get visual studios depth of indention, i also had to mess with the selected text to span the selection also over the full first and last line:

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,但它工作正常,并这样比原来的插件代码快

I don't really know wether this is a good way to alter textselections but it works fine and is way faster than the original addin code

这篇关于我对文本排版VS2008插件是非常缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆