AvalonEdit:对于大型突出显示的文本文件,复制将永远花费 [英] AvalonEdit: Copy takes forever for large highlighted text files

查看:330
本文介绍了AvalonEdit:对于大型突出显示的文本文件,复制将永远花费的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,这是在 http://community.sharpdevelop.net上提出的/forums/p/21949/56153.aspx#56153 ,但尚无答案-所以我在这里尝试.

Actually this was asked on http://community.sharpdevelop.net/forums/p/21949/56153.aspx#56153 but with no answer yet - so I try it here.

我在WPF 4.0应用程序中使用Avalon Edit(ICSharpCode.AvalonEdit.dll 4.4.2). 我已经将文本文件(〜7 MB)加载到了编辑器中.当我应用语法突出显示然后应对(Control-A和Control-C)时,整个文本将永远花光(不突出显示将在一秒钟内完成)

I'm using Avalon Edit (ICSharpCode.AvalonEdit.dll 4.4.2) in a WPF 4.0 application. I have loaded a text file (~7 MBytes) into the editor. When I apply syntax highlighting and then coping (Control-A and Control-C) the whole text it takes forever (without highlighting it's done in a second)

当我进入调试器时,会得到以下调用堆栈(简称):

When I break into debugger I get the following callstack (shortened):

System.Text.RegularExpressions.RegexInterpreter.Go() 
System.Text.RegularExpressions.RegexRunner.Scan(regex, text, textbeg, textend, textstart, prevlen, quick, timeout) 
System.Text.RegularExpressions.Regex.Run(quick, prevlen, input, beginning, length, startat) 
System.Text.RegularExpressions.Regex.Match(input, beginning, length) 
ICSharpCode.AvalonEdit.Highlighting.DocumentHighlighter.HighlightNonSpans(until) 
ICSharpCode.AvalonEdit.Highlighting.DocumentHighlighter.HighlightLineInternal(line) 
ICSharpCode.AvalonEdit.Highlighting.DocumentHighlighter.HighlightLineAndUpdateTreeList(line, lineNumber) 
ICSharpCode.AvalonEdit.Highlighting.DocumentHighlighter.HighlightLine(lineNumber) 
ICSharpCode.AvalonEdit.Highlighting.HtmlClipboard.CreateHtmlFragment(document, highlighter, segment, options) 
ICSharpCode.AvalonEdit.Editing.Selection.CreateHtmlFragment(options) 
ICSharpCode.AvalonEdit.Editing.Selection.CreateDataObject(textArea) 
ICSharpCode.AvalonEdit.Editing.EditingCommandHandler.CopySelectedText(textArea) 
ICSharpCode.AvalonEdit.Editing.EditingCommandHandler.OnCopy(target, args) 

似乎编辑器为剪贴板创建了基于html的内容,并使用了RegularExpressions,这需要花费很长的时间(约30秒).

It seems the editor creates html-based content for the clipboard and uses RegularExpressions which takes forever (~30 seconds).

问题:有谁知道有可能禁用复制操作的语法高亮显示,以便仅将纯文本复制到剪贴板.

Question: Does anyone know a possibility to disable the syntax highlighting for the copy action so that only pure text is copied to the clipboard.

推荐答案

DanielGrunwald在SharpDevelop上得到了我想分享的答案: 在avalonedit 4.X中,不能不能禁用html复制到剪贴板.但是在5.X中,您可以做到这一点.

I got the answer from DanielGrunwald on SharpDevelop that I want to share: In avalonedit 4.X it's not possible to disable html copy to clipboard. But in 5.X you can do that.

使用:

AvalonEdit.TextEditor TextView

编写以下内容以注册复制前事件的回调:

write the following to register the callback for the before-copy event:

DataObject.AddSettingDataHandler(TextView, onTextViewSettingDataHandler);

注册在处理爬板复制之前调用的用户处理程序.在该处理程序中,取消html格式(例如,取决于文档大小).示例:

to register a user handler that is called before cliboard copying is processed. In that handler cancel the html format (e.g. depending on the document size). Example:

static public void onTextViewSettingDataHandler(object sender, DataObjectSettingDataEventArgs e)
{
  var textView = sender as TextEditor;
  if (textView != null && e.Format == DataFormats.Html && textView.Text.Count() > MaxDocByteSizeForHtmlCopy)
  {        
    e.CancelCommand();
  }
}

使用该代码,您可以防止使用该衣架,但是在粘贴内容(例如,将其粘贴到Word中)时,当然不会保留格式.

With that code you can prevent that hanger, but of course formatting is not preserved when the content is pasted (e.g. into Word).

这篇关于AvalonEdit:对于大型突出显示的文本文件,复制将永远花费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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