Write text at syntaxEdit's cursor location programmatically

Hi.
How can I write text on syntaxEdit’s cursor location programmatically?
I know that the syntaxEdit has a method to get text at cursor location:
var text = syntaxEdit1.GetTextAtCursor();

but how to set text at cursor?

Thanks

Hi,

you can try such code:

int left, right;
            if (syntaxEdit1.GetWordAt(syntaxEdit1.Lines.GetItem(syntaxEdit1.Position.Y), syntaxEdit1.Position.X, out left, out right))
            {
                syntaxEdit1.Selection.SetSelection(Alternet.Editor.SelectionType.Stream, new Point(left, syntaxEdit1.Position.Y), new Point(right + 1, syntaxEdit1.Position.Y));
                syntaxEdit1.Selection.InsertString("your own text");
            }

Regards,
Andrew

Thanks Andrew,
I’ve replaced
syntaxEdit1.Selection.SetSelection(Alternet.Editor.SelectionType.Stream, new Point(left, syntaxEdit1.Position.Y), new Point(right + 1, syntaxEdit1.Position.Y));

with:
syntaxEdit1.Selection.SetSelection(Alternet.Editor.SelectionType.Stream, new Point(left, syntaxEdit1.Position.Y), new Point(left, syntaxEdit1.Position.Y));

and now it works as expected. Thanks so much

Hi,

You should use GetWordAt and SetSelection methods only if you need to replace text at the cursor with your own text.
Otherwise you can use these one:
syntaxEdit1.Insert("your own text");
or
syntaxEdit1.Selection.InsertString("your own text");

Regards,
Andrew

1 Like

Hi Andrew,
This is exactly what I was looking for.

Thanks a lot