Does AvalonEdit :TextEditor has quick search/replace functionality?

There isn't much documentation about it, but AvalonEdit does have a built in SearchPanel class that sounds exactly like what you want. There is even a SearchInputHandler class that makes it trivial to get it hooked up to your editor, responding to keyboard shortcuts, etc. Here is some sample code that attached the standard search logic to an editor:

myEditor.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(myEditor.TextArea));

Here is a screenshot of what it will look like (this is taken from ILSpy which uses AvalonEdit). You can see the search control in the top right, the search options it supports, and the automatic highlighting it does of matching results.

Searching in ILSpy with SearchPanel

There isn't any support for replace...but if you just need searching, this can be a great solution.


For Avalon Edit Version 5.0.1.0 and up, just do this:

SearchPanel.Install(XTBAvalonEditor);

Where XTBAvalonEditor is the WPF AvalonEdit control name.

Make sure to add this using statement:

using ICSharpCode.AvalonEdit.Search;

Then when the editor has focus, press CTL-F: You'll see the find control pop up in upper right hand corner.

enter image description here


In the TextEditor constructor in the ICSharpCode.AvalonEdit project, add SearchPanel.Install(this.TextArea); and voila, using ctrl+f opens the search window.

(using the line from Stephen McDaniel's post (replace myEditor with this) also works, but the support for SearchInputHandler is being removed)

(works well with AvalonEdit inside AvalonDock with MVVM)

From:

public TextEditor() : this(new TextArea())
{
}

To:

public TextEditor() : this(new TextArea())
{
  SearchPanel.Install(this.TextArea);
}