icsharpcode / AvalonEdit

The WPF-based text editor component used in SharpDevelop
http://avalonedit.net/
MIT License
1.85k stars 469 forks source link

How can I use the code completion by press Tab key other than input dot? #406

Open xiaoxstz opened 1 year ago

xiaoxstz commented 1 year ago

I have realized code completion according to the related document.

But I want the completion window to appear when I am typing, or after I press the Tab key.

My try

Delete if (e.Text == ".") of the original code.

void textEditor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
{
    if (e.Text == ".") {
        // Open code completion after the user has pressed dot:
        completionWindow = new CompletionWindow(textEditor.TextArea);
        IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
        data.Add(new MyCompletionData("Item1"));
        data.Add(new MyCompletionData("Item2"));
        data.Add(new MyCompletionData("Item3"));
        completionWindow.Show();
        completionWindow.Closed += delegate {
            completionWindow = null;
        };
    }
}

Then, the complete window will appear whatever I input. It's great!

However, if I input "It", and then choose "Item1" from the complete window. The content will turn to "IItem1"

An easy way to reproduce it

Download the source code of this repository, and then you can find the related code in Window1.xaml.cs of the project ICSharpCode.AvalonEdit.Sample

The original effect: Run the project and then input “.” in the text editor

image

Try to realize "completion when typing"

Delete if (e.Text == ".") in the function textEditor_TextArea_TextEntered in Window1.xaml.cs

image