Plugin samples

Manipulating auto-complete

This plugin demonstrates adding a new item to auto-complete. It adds new tag bs3-table to list of HTML tags that pops up get when typing < in HTML code.

function OnAutoComplete(CodeType, ACType, Strings, AKey, &AllowPopup, ShowImages) {
    var i;

    if (ACType == 4) {
        //add this experimental HTML tag
        i = AutoComplete.AddItem(Strings, "bs3-table", "bs3-table");
        AutoComplete.SetImageIndex(i, 8);
    }
}

function OnAutoCompleteInsert(ACType, ListItemAtCursorAC, &s, &ACWordStart, &ACWordLength, &ACLineOffset, &Handled) {

    var table_snippet = "<table class=\"table\">\n"
                + "<thead>\n"
                + "  <tr>\n"
                + "    <th></th>\n"
                + "  </tr>\n"
                + "</thead>\n"
                + "<tbody>\n"
                + "  <tr>\n"
                + "    <td></td>\n"
                + "  </tr>\n"
                + "</tbody>\n"
                + "</table>\n";

    if (ACType == 4) {
        if (s == "bs3-table") {
            //"eat" opening "<" by moving cursor to left; another way to do it would be to not include opening "<" in snippet
            ACWordStart = ACWordStart - 1;
            ACWordLength = ACWordLength + 1;
            s = table_snippet;
            Handled = true;
        }
    }
}

Script.ConnectSignal("auto_complete", &OnAutoComplete);
Script.ConnectSignal("auto_complete_insert", &OnAutoCompleteInsert);