Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ankyo opened this issue Nov 2, 2024 · 0 comments

Comments

@ankyo
Copy link

ankyo commented Nov 2, 2024

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();
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant