I can't insert a char into my AvalonEdit TextEditor.
void editor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
{
if (e.Text == "{" || e.Text == "(" || e.Text == "[" || e.Text == "\"" || e.Text == "\'")
{
switch (e.Text)
{
case "{":
int i = editor.TextArea.Caret.Offset;
editor.Text.Insert(i, "}");
break;
case "(":
editor.Text.Insert(editor.CaretOffset, ")");
break;
case "[":
editor.Text.Insert(editor.CaretOffset, "]");
break;
case "\"":
editor.Text.Insert(editor.CaretOffset, "\"");
break;
case "\'":
editor.Text.Insert(editor.CaretOffset, "\'");
break;
}
}
}
I have no idea why it doesnt work. Please help me.
try this:
editor.Document.Insert(editor.TextArea.Caret.Offset, "\'");