Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AvalonEdit insert text doesnt work

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.

like image 253
Giraffe Avatar asked Dec 22 '25 05:12

Giraffe


1 Answers

try this:

   editor.Document.Insert(editor.TextArea.Caret.Offset, "\'");
like image 126
Amir Avatar answered Dec 23 '25 20:12

Amir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!