AvalonEdit: copy is done forever for large text files with highlight

This was actually asked at http://community.sharpdevelop.net/forums/p/21949/56153.aspx#56153 , but there is no answer yet - so I'll try it here.

I am using Avalon Edit (ICSharpCode.AvalonEdit.dll 4.4.2) in a WPF 4.0 application. I have uploaded a text file (~ 7MB) to the editor. When I apply syntax highlighting and then copy (Control-A and Control-C) all the text it takes forever (without highlighting it for a second)

When I broke into the debugger, I get the following column (shorthand):

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) 

      

The editor seems to be creating html content for the clipboard and using RegularExpressions which takes forever (~ 30 seconds).

Question: Does anyone know of an option to turn off syntax highlighting for a copy action so that only plain text is copied to the clipboard.

+3


source to share


1 answer


I got a response from DanielGrunwald on SharpDevelop that I want to share: In avalonedit 4.X, it can not turn off html copy to clipboard. But in 5.X you can do it.

FROM

AvalonEdit.TextEditor TextView

      

write the following to register a callback for the event before copying:



DataObject.AddSettingDataHandler(TextView, onTextViewSettingDataHandler);

      

to register a user handler, which is called before the jib copy is processed. This handler overrides html format (eg depending on 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();
  }
}

      

With this code you can prevent this hanger, but of course the formatting is not preserved when pasting content (like in Word).

+1


source







All Articles