AvalonEdit icon indicating copy to clipboard operation
AvalonEdit copied to clipboard

Text not displayed in code completion window when AvalonEdit used from c# code

Open ankyo opened this issue 1 year ago • 0 comments

20241102203136

public class VariableCompletionData : ICompletionData
{
  public IImage? Image => null;

  public string Text { get; }

  // Use this property if you want to show a fancy UIElement in the list.
  public object Content => Text;

  public object Description => "Description for " + Text;

  public double Priority { get; } = 0;

  public VariableCompletionData(string text)
  {
    Text = text;
  }

  public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs)
  {
    textArea.Document.Replace(completionSegment, Text);
  }
}
private void TextArea_TextEntering(object? sender, TextInputEventArgs e)
{
  if (e.Text?.Length > 0 && _completionWindow != null)
  {
    if (!char.IsLetterOrDigit(e.Text[0]))
    {
      // Whenever a non-letter is typed while the completion window is open,
      // insert the currently selected element.
      _completionWindow.CompletionList.RequestInsertion(e);
    }
  }
}

private void TextArea_TextEntered(object? sender, TextInputEventArgs e)
{
  if (e.Text == ".")
  {
    _completionWindow = new CompletionWindow(Editor.TextArea);
    _completionWindow.Closed += (o, args) => _completionWindow = null;

    var data = _completionWindow.CompletionList.CompletionData;

    data.Add(new VariableCompletionData("Item1"));
    data.Add(new VariableCompletionData("Item2"));
    data.Add(new VariableCompletionData("Item3"));
    data.Add(new VariableCompletionData("Item4"));
    data.Add(new VariableCompletionData("Item5"));
    data.Add(new VariableCompletionData("Item6"));
    data.Add(new VariableCompletionData("Item7"));
    data.Add(new VariableCompletionData("Item8"));
    data.Add(new VariableCompletionData("Item9"));
    data.Add(new VariableCompletionData("Item10"));
    data.Add(new VariableCompletionData("Item11"));
    data.Add(new VariableCompletionData("Item12"));
    data.Add(new VariableCompletionData("Item13"));

    _completionWindow.Show();
  }
}

ankyo avatar Nov 02 '24 12:11 ankyo