Question

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.

Was it helpful?

Solution

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();
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top