NeedCodeCompletion - delete text in SyntaxEdit

Good day,

we test your product Syntax Edit. We would need it for our simple MSSQL editor.

Almost everything works for us, we have a problem anyway.
If i am at the beginning of a word ("select * from Subject") and i am before the Subject. So after activating the Completion window. And selecting item replaces the Subject text. We would need to never delete any text, but insert it at the cursor position. Is it possible to block the deletion of any text?
Hi Karel,
You should handle NeedCodeCompletion event where e.EndPosition should be changed like this:
if ((e.Provider != null) && (e.CompletionType == Alternet.Syntax.CodeCompletionType.ListMembers))
{
e.EndPosition = syntaxEdit1.Position;
}
I've uploaded sample project to demonstrate this approach here:
https://drive.google.com/file/d/1V1FbKoQzCymzSWw8UabVuseqpXSVp7BM/view?usp=sharing
Regards,
Andrew
Good day,
I continue for my colleague.

We found a problem, we edit StartPosition and EndPosition and thus the text is deleted.

We edit StartPosition and EndPosition for this because we have removed the attribute: Alternet.Syntax.SyntaxOptions.CodeCompletion in mssqlParsert.Options.

We do not want CodeConpletion to open after pressing the space key. But only after pressing the keys listed in CodeCompletionChars.
Unfortunately, then CodeCompletion does not work, the first letter written is ignored.
https://drive.google.com/file/d/1100lFc9YVHehDmC61lr9Axqy8Vrw8UMj/view?usp=sharing
Hello Krandák,
When Alternet.Syntax.SyntaxOptions.CodeCompletion is switched on, parser automatically set codeCompletionArgs.StartPosition and CompletionType properties.
As you switch this option off, you should set these properties manually like this:
private void SyntaxEdit1_NeedCodeCompletion(object sender, Alternet.Syntax.CodeCompletionArgs e)
{
if (txtCode.IsCodeCompletionWindowFocused)
{
e.Handled = true;
return;
}
...
e.CompletionType = GetCompletionType(e.KeyChar);
if ((e.Provider != null) && (e.CompletionType == Alternet.Syntax.CodeCompletionType.ListMembers))
{
e.StartPosition = new Point(Math.Max(0, txtCode.Position.X - 1), txtCode.Position.Y);
e.EndPosition = txtCode.Position;
}
}
private CodeCompletionType GetCompletionType(char ch)
{
switch (ch)
{
case '.':
return CodeCompletionType.ListMembers;
default:
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
return CodeCompletionType.ListMembers;
break;
}
return CodeCompletionType.None;
}


Regards,
Andrew
Thank you,
it's working pretty well now.

One more little thing. If I type on the keyboard at "normal" speed. Thus, the NeedCodeCompletion event is fired only after the second letter. i.e., the CompletionWindow does not work. It's just that if I write join, it looks up to oin.
Hello Krandák,
you can start CodeCompletion immediately using this code:
Alternet.Editor.EditConsts.DefaultCompletionStartDelay = 0;
Regards,
Andrew
Hello Krandák,
You can also calculate StartPosition taking into account all typed letters like in this example:
https://drive.google.com/file/d/1v0LWm1u9rJ_qyLzF_T2It-2DoXifcuTo/view?usp=sharing
Regards,
Andrew