Question

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.

Was it helpful?

Solution

try this:

   editor.Document.Insert(editor.TextArea.Caret.Offset, "\'");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top