1
Vote

Code Completion/Autolist not working properly in Syntax Editor

description

The current implementation of the autolist selected text and the inserttext method is not working correctly.
First it's not using the first few letters typed before CTRL+SPACE is hit to find the nearest item and select it.
Secondly it's not replacing the first few letters when a seletion is made.
for example:
 
the user types ins then hits ctrl+space, then selects INSERT from the autolist, the insert method then does this:
insINSERT which is of course totally wrong. I discovered this on the Puzzel version and checked your code to see if you had fixed it and it's not been corrected, anyway, here is the fix I came up with and it works good for me.
 
Below is what I sent to the Puzzel maintainers:
 
The next problem I ran into was the code completion autolist was not working properly.
Basicly it was not using the first few words of typing to select the closest match in the autolist box.
 
I had to make a few mods to get this working the way I was expecting it to work first:
 
protected override void OnKeyPress(KeyPressEventArgs e)
 
which is in EditViewControl.cs. In the OnKeyPress method there the following if statement:
if (AutoListVisible && !e.Handled && _SyntaxBox.AutoListAutoSelect)
 
Which I changed to:
 
if (AutoListVisible && !e.Handled && _SyntaxBox.AutoListAutoSelect)
{
try
{
string s = “”;
if (Caret.CurrentWord != null)
s = Caret.CurrentWord.Text;
AutoList.SelectItem(s);
}
catch
{
}
}
 
It was using the X coordinate where the user initiated the autolist, and this of course was always blank, unless the user typed
after the list was displayed and it would never grab whatever they typed before starting the autolist.
 
The next fix involves the InsertAutolistText method in EditViewControl.cs. Again this method was not taking into account if
the user had typed a few chars and was inserting the selection after instead of replacing it. Changed to:
 
public void InsertAutolistText()
{
int startpos = 0;
startpos = AutoListStartPos.X;
//is there a current word?
if (Caret.CurrentWord != null)
{
int ccol = Caret.CurrentWord.Column;
if (ccol != startpos && Caret.CurrentWord.Text != ” “)
{
int cwlength = 0;
cwlength = Caret.CurrentWord.Text.Length;
startpos = startpos - cwlength;
}
}
 
TextRange tr = new TextRange();
tr.FirstRow = Caret.Position.Y;
tr.LastRow = Caret.Position.Y;
tr.FirstColumn = startpos;
tr.LastColumn = Caret.Position.X;
Document.DeleteRange(tr, true);
Caret.Position.X = startpos;
this.InsertText(AutoList.SelectedText);
SetFocus();
}

comments