Basic Autocomplete

Topics: User Forum
Jul 26, 2010 at 12:33 PM
Edited Jul 26, 2010 at 7:51 PM

I haven't been able to find a discussion or an example of how to do basic auto complete.  Here is what I have so far.

I am handling the "CharAdded" event so that I have:

void scintillaInputBox_CharAdded(object sender, ScintillaNet.CharAddedEventArgs e)
{           
    scintillaInputBox.AutoComplete.Show();
}


My xml looks something like this:

<AutoComplete>
    <List>
        foo bar
    </List>
</AutoComplete>


This all works.  The autocomplete box comes up as I type and it seems to find matches correctly.

However there are a couple of issues that I can't seem to resolve.

1) The AutoHide does not seem to work.  It always shows the auto complete box regardless of whether there are matches or not.

2) It has problems with values that contain special characters.  For example if I put something like "math.abs" into my list, then type "math" it will find it no problem.  But if I type "math." then it loses the match and goes back to the beginning of the list.  I am guessing this happens because it matches on word boundaries but if there is a way around this I would be interested in hearing it.

I have verified that my list is correctly sorted (realized that problem early on).  The settings for my Auto complete are:

 

AutoHide = True

AutomaticLengthEntered = True

CancelAtStart = True

DropRestOfWord = False

FillUpCharacters = ""

ImageSeparator = ?

IsCaseSensitive = True

ListSeparator = {SPACE}

MaxHeight = 5

MaxWidth = 0

SingleLineAccept = False

StopCharacters = ""

 

Jul 26, 2010 at 7:50 PM
Edited Jul 26, 2010 at 7:52 PM

Not sure if this is the best way but I managed to get the autohide to work using:

 

int pos = scintillaInputBox.NativeInterface.GetCurrentPos();

int length = pos - scintillaInputBox.NativeInterface.WordStartPosition(pos, true);

scintillaInputBox.AutoComplete.Show(length);

 

Still haven't figured out the second issue though.

Coordinator
Jul 26, 2010 at 10:18 PM
Edited Jul 26, 2010 at 10:19 PM

See this for the first issue (look down to the last post)

http://scintillanet.codeplex.com/Thread/View.aspx?ThreadId=57703

For the 2nd it depends on what you have in your autocomplete list and what you want to do when something like that happens. Can you give me some more backround on what specificly you are trying to do and what language you're autocompleting for?

Jul 27, 2010 at 12:27 PM

Incidentally I have looked at the link you provided several times while working on this.  Perhaps I am missing it but I don't see anywhere that it explains why AutoHide doesn't work or how to make it work.  Throughout that post it is just using "Show()".  However using "Show()" as is causes it to always show the dialog regardless of the value of AutoHide.  At least that has been my experience.  If you provide a length then it actually seems to use AutoHide.  However there is nothing in that post that indicates how that length should be calculated.  I obtained my solution by looking at the source code for the AutoComplete.  As I said I don't know if it is the ideal solution but it does seem to work.

Now for the 2nd issue, the language I am working with is Lua.  There are several commands like math.abs, math.min, math.max etc.  What I would like is for someone to be able to type "math.a" and get listings for math.abs, math.acos, math.asin etc.

I also want to add some custom functions to the list (functions we have that are commonly used).  So you might see something like Thread.Sleep etc.  I could add Thread, and Sleep to the list and it would then work if they typed "Thread.S" however in this case it would also match "Sl" to Sleep which is not what I want because that is not a valid call.

Developer
Apr 2, 2011 at 11:59 PM
Edited Apr 3, 2011 at 4:53 PM

Just as a note, this is what i'm currently working on adding to the 4.0 branch. I currently have it narrowing, and widening the list of options based on what's typed, (narrowing when you type anything once the list's down, and widening when you hit backspace) I still have to find the right location to pass the keypress calls back to the base scintilla control, as well as fix an offset issue that causes the dropdown to dissapear when there's only 1 letter left as the start of the word (this one might take a bit to track down), but once I have that all I need to do is wire the characters that cause the dropdown menu to appear into the config files, and it should be ready for use. (4.0 also has legacy support, it supports the xml files from scintilla 1.2 (minus the menu configuration, which I plan to add soon))

 

 

EDIT:

I now have the highlighting working again, it was because of the differences between version 2.12 and 2.20 (the next released version) of scintilla. I have made the same changes i did with 2.25 in 2.12 and also enabled speed optimizations. Just need to get it reading the trigger characters from an xml file and it will be ready for a check-in.

 

Another Edit:

I worked out the cause of 1 bug, (that was bugging me to death :P), which caused the auto-complete box to disappear 1 character after the start of the word, if you were using the backspace key. I still need to hook it into the xml properly.

Oct 28, 2011 at 10:26 PM

Did you ever get any further with the 2nd issue.  I am trying to populate the intellisense list with a columsn and tables from a database.  Everything works great when it is a single word object like Table1 or Column1, but when i want to show all the columns for a table i see the same problem.

It doesn't appear that the CharAdded event is fired when you type a . (period), so limiting the intellisense to just the fields on that table isn't really an option.  I also noticed that when you look at the words collection of a line, it will break out a word like "table1.column1" into 2 words. 

If anyone has found a way around this, I am all ears...  Thanks in advance...