Skip to content

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

Open
@ankyo

Description

@ankyo

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();
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ankyo

        Issue actions

          Text not displayed in code completion window when AvalonEdit used from c# code · Issue #433 · icsharpcode/AvalonEdit