Bug fix for you

Feb 22, 2008 at 3:09 PM
I fixed this in the Puzzel version and noticed your code is also broken for the autolist.

Here is what I sent to the Puzzel framework maintainer:

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();
}

Feb 22, 2008 at 9:36 PM
Hi,
Sorry about this, but the first InsertAutolistText method I posted didn't work right, this one does:

public void InsertAutolistText()
{
int caretx = 0;
TextRange tr = new TextRange();
tr.FirstRow = Caret.Position.Y;
tr.LastRow = Caret.Position.Y;
if (Caret.CurrentWord != null && Caret.CurrentWord.Type == WordType.xtWord)
{
tr.FirstColumn = Caret.CurrentWord.Column;
tr.LastColumn = Caret.CurrentWord.Column + Caret.CurrentWord.Text.Length;
caretx = Caret.CurrentWord.Column + AutoList.SelectedText.Length;
}
else
{
tr.FirstColumn = AutoListStartPos.X;
tr.LastColumn = Caret.Position.X;
caretx = tr.FirstColumn + AutoList.SelectedText.Length+1;
}
Document.DeleteRange(tr, true);
Caret.Position.X = caretx;
this.InsertText(AutoList.SelectedText);
SetFocus();
}