Scintilla.NET 自动完成自动选择第一个元素 (C#)

发布于 2025-01-01 15:03:42 字数 927 浏览 2 评论 0原文

我目前正在使用 Scintilla 为 Text 组件创建一个 IDE。但自动完成有一些问题我没有得到解决。

我输入后自动显示提案列表。在对象或类名之后。

然后我调用以下内容:

int pos = _editor.NativeInterface.GetCurrentPos();
string word = _editor.GetWordFromPosition(pos - 1);
if (string.IsNullOrEmpty(word))
    return;
if (Objects.Keys.Contains(word))
{
    System.Reflection.MemberInfo[] memberInfos = Reflector.PublicMembersOf(Objects[word]);
    List<String> proposals = new List<string>();
    foreach (System.Reflection.MemberInfo mi in memberInfos)
    {
        string member = mi.ToString();
        if (Reflector.IsRealMethod(mi))
        proposals.Add(mi.ToString().Split(" ".ToCharArray(), 2)[1].Replace(" ", ""));
    }
    proposals.Sort();
    _editor.AutoComplete.Show(0, proposals);
}

Objects 是一个HashMap,其中存储所有对象和相应的类型。

当我第一次调用自动完成功能时,它工作正常。但第二次使用它只会自动完成提案的第一个元素。

I am currently creating an IDE using Scintilla for the Text component. But autocomplete has some problem I do't get fixed.

I automatically show the proposal list after entering . after an object or class name.

Then I call the following:

int pos = _editor.NativeInterface.GetCurrentPos();
string word = _editor.GetWordFromPosition(pos - 1);
if (string.IsNullOrEmpty(word))
    return;
if (Objects.Keys.Contains(word))
{
    System.Reflection.MemberInfo[] memberInfos = Reflector.PublicMembersOf(Objects[word]);
    List<String> proposals = new List<string>();
    foreach (System.Reflection.MemberInfo mi in memberInfos)
    {
        string member = mi.ToString();
        if (Reflector.IsRealMethod(mi))
        proposals.Add(mi.ToString().Split(" ".ToCharArray(), 2)[1].Replace(" ", ""));
    }
    proposals.Sort();
    _editor.AutoComplete.Show(0, proposals);
}

Objects is a HashMap<String, Type> where all objects and there corresponding types are stored.

When I call the autocomplete the first time it works fine. But using it the second time just autocompletes the first element of proposals.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与往事干杯 2025-01-08 15:03:42

我认为这个问题是因为你试图在“.”之后使用打开的自动完成功能。象征。您可以注意到,在您输入“.”后,自动完成功能将关闭。或“(”并选择当前单词作为自动完成的结果。
我需要做同样的事情:在“.”之后打开自动完成列表象征。解决办法很简单,10毫秒后打开即可。例如使用以下代码:

    private void scintillaCs_CharAdded(object sender, ScintillaNET.CharAddedEventArgs e)
    {
        ScintillaNET.Scintilla editor = sender as ScintillaNET.Scintilla;

        if (e.Ch == '.')
        {
            Timer t = new Timer();

            t.Interval = 10;
            t.Tag = editor;
            t.Tick += new EventHandler((obj, ev) =>
            {
                // make a new autocomplete list if needed
                List<string> s = new List<string>();
                s.Add("test");
                s.Add("test2");
                s.Add("test3");
                s.Sort(); // don't forget to sort it

                editor.AutoComplete.ShowUserList(0, s);

                t.Stop();
                t.Enabled = false;
                t.Dispose();
            });
            t.Start();
        }
    }
}

I think that the problem it because you are trying to use open autocomplete after '.' symbol. As you can notice autocomplete will be closed after you will type '.' or '(' and select the current word as a result of autocomplete.
I was needed to do the same thing: open autocomplete list after '.' symbol. Solution is very simple you can open it after 10 milliseconds. For example use this code:

    private void scintillaCs_CharAdded(object sender, ScintillaNET.CharAddedEventArgs e)
    {
        ScintillaNET.Scintilla editor = sender as ScintillaNET.Scintilla;

        if (e.Ch == '.')
        {
            Timer t = new Timer();

            t.Interval = 10;
            t.Tag = editor;
            t.Tick += new EventHandler((obj, ev) =>
            {
                // make a new autocomplete list if needed
                List<string> s = new List<string>();
                s.Add("test");
                s.Add("test2");
                s.Add("test3");
                s.Sort(); // don't forget to sort it

                editor.AutoComplete.ShowUserList(0, s);

                t.Stop();
                t.Enabled = false;
                t.Dispose();
            });
            t.Start();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文