I am using AvalonEdit as my TextEditor and is not showing the data in the CodeCompletionWindow when it is called from Key_Down button, however everything works fine when handled as Text_Entered event. Below is the sample code
[Serializable]
public class CodeEditor : TextEditor
{
public CompletionWindow CompletionWindow = null;
public CodeEditor()
{
//CompletionWindow pops up without any data.
this.TextArea.KeyDown += TextArea_KeyDown;
//CompletionWindow pops up and data is displayed.
this.TextArea.TextEntered += this.OnTextEntered;
}
void TextArea_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
{
ShowCompletion("");
}
}
void OnTextEntered(object sender, TextCompositionEventArgs e)
{
//e.Handled = true;
if (e.Text == "\n" || e.Text == "\t" || e.Text == " ")
{
return;
}
this.ShowCompletion(e.Text);
}
private void ShowCompletion(string enteredText)
{
CompletionWindow = new CompletionWindow(TextArea);
IList<ICompletionData> data = CompletionWindow.CompletionList.CompletionData;
data.Add("ABC");
CompletionWindow.Show();
CompletionWindow.Closed += delegate
{
CompletionWindow = null;
};
}
}
Got the answer. Added e.Handled = true
in KeyDown Event Handler.
Working code.
void TextArea_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
{
ShowCompletion("");
e.Handled = true;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With