This repository has been archived on 2021-07-14. You can view files and clone it, but cannot push or open issues or pull requests.
scriptcraft/src/main/js/lib/tabcomplete-jsp.js

49 lines
1 KiB
JavaScript

'use strict';
var _commands = require('command').commands;
/*
Tab completion for the /jsp commmand
*/
var __onTabCompleteJSP = function( result, cmdSender, pluginCmd, cmdAlias, cmdArgs ) {
var cmdInput = cmdArgs[0],
opts,
cmd,
len,
i;
cmd = _commands[cmdInput];
if ( cmd ) {
opts = cmd.options;
len = opts.length;
if ( cmdArgs.length == 1 ) {
for ( i = 0; i < len; i++ ) {
result.add( opts[i] );
}
} else {
// partial e.g. /jsp chat_color dar
for ( i = 0; i < len; i++ ) {
if ( opts[i].indexOf( cmdArgs[1] ) == 0 ) {
result.add( opts[i] );
}
}
}
} else {
if ( cmdArgs.length == 0 ) {
for ( i in _commands ) {
result.add( i );
}
} else {
// partial e.g. /jsp ho
// should tabcomplete to home
//
for ( i in _commands ) {
if ( i.indexOf( cmdInput ) == 0 ) {
result.add( i );
}
}
}
}
return result;
};
module.exports = __onTabCompleteJSP;