public override System.Windows.Forms.Control Browse(Action<double> progressUpdateCallback = null)
{
var box = new BetterRichTextBox() {
Multiline = true,
ReadOnly = true,
WordWrap = true,
};
bool recurse = false;
box.SelectionChanged += (object sender, EventArgs args) => {
if (recurse)
return;
try {
Point scrollPosition = box.ScrollPosition;
int resetStart = box.SelectionStart, resetLength = box.SelectionLength;
box.BeginUpdate();
recurse = true;
var start = box.SelectionStart;
string text = box.Text;
if (!IsIdentifier(text, start) && !IsIdentifier(text, start - 1))
return;
while (IsIdentifier(text, start - 1))
start--;
int end = box.SelectionStart;
while (IsIdentifier(text, end))
end++;
string searchText = text.Substring(start, end - start);
box.SelectAll();
//box.SelectionFont = normal;
box.SelectionBackColor = Color.Transparent;
start = 0;
while (true) {
start = text.IndexOf(searchText, start);
if (start < 0)
break;
if (!IsIdentifier(text, start - 1) && !IsIdentifier(text, start + searchText.Length)) {
box.Select(start, searchText.Length);
//box.SelectionFont = underlined;
box.SelectionBackColor = Color.Yellow;
}
start += searchText.Length;
}
box.Select(resetStart, resetLength);
box.ScrollPosition = scrollPosition;
} finally {
box.EndUpdate();
box.Invalidate();
recurse = false;
}
};
RichTextBuilder builder = new RichTextBuilder();
foreach (EffectInstruction instruction in Instructions) {
instruction.ToRichText(builder);
builder.Append("\n");
}
box.Rtf = builder.ToString();
return box;
}