New Feature: Auto Launch AutoComplete

Topics: Developer Forum
Aug 16, 2013 at 3:50 AM
Edited Aug 16, 2013 at 3:52 AM
By default, we have to manually run 'AutoComplete.Show()' in the 'CharAdded' event.

However, I would like to suggest it to be auto-launch.

Default behaviour:
  • If the AutoComplete.List is empty, AutoComplete will not launch.
  • If the AutoComplete.List is not empty, it will launch for matched character enter by user.
  • If the developer want to implement different behaviour, he/she can override the methods or turn it off.
This is the sample codes patch that I can come out with:

This is the original codes of the method of OnCharAdded() in ScintillaNET.Scintilla
/// <summary>
///     Raises the <see cref="CharAdded"/> event.
/// </summary>
/// <param name="e">An <see cref="CharAddedEventArgs"/> that contains the event data.</param>
protected virtual void OnCharAdded(CharAddedEventArgs e)
{
    EventHandler<CharAddedEventArgs> handler = Events[_charAddedEventKey] as EventHandler<CharAddedEventArgs>;
    if (handler != null)
        handler(this, e);

    if (_indentation.SmartIndentType != SmartIndent.None)
        _indentation.CheckSmartIndent(e.Ch);
}
Patches:
private Bool _autoLaunchAutoComplete = true;

public Bool AutoLaunchAutoComplete 
{ 
    get { return _autoLaunchAutoComplete; } 
    set { _autoLaunchAutoComplete = value; } 
}

/// <summary>
///     Raises the <see cref="CharAdded"/> event.
/// </summary>
/// <param name="e">An <see cref="CharAddedEventArgs"/> that contains the event data.</param>
protected virtual void OnCharAdded(CharAddedEventArgs e)
{
    EventHandler<CharAddedEventArgs> handler = Events[_charAddedEventKey] as EventHandler<CharAddedEventArgs>;
    if (handler != null)
        handler(this, e);

    if (_indentation.SmartIndentType != SmartIndent.None)
        _indentation.CheckSmartIndent(e.Ch);

    if (_autoLaunchAutoComplete)
        LaunchAutoComplete();
}

public virtual void LaunchAutoComplete()
{
    if (this.AutoComplete.List.Count == 0)
        return;

    int pos = this.NativeInterface.GetCurrentPos();
    int length = pos - this.NativeInterface.WordStartPosition(pos, true);
    if (length == 0)
        return;

    this.AutoComplete.Show(length);
}
If the developer don't want automatic launch AutoComplete or he/she want to implement different behaviour, he/she may do this to suspend default behaviour:
ScintillaNET.Scintilla scintilla1 = new ScintillaNET.Scintilla();
scintilla1.AutoLaunchAutoComplete = false;