Fixed autocomplete issue #68

This commit is contained in:
walterhiggins 2013-03-02 18:46:50 +00:00
parent 1eb6756204
commit 6e113a2eca

View file

@ -223,7 +223,7 @@ There are a couple of special javascript variables available in ScriptCraft...
***/ ***/
var global = this; var global = this;
var verbose = true; //verbose || false; var verbose = verbose || false;
/* /*
wph 20130124 - make self, plugin and server public - these are far more useful now that tab-complete works. wph 20130124 - make self, plugin and server public - these are far more useful now that tab-complete works.
*/ */
@ -492,6 +492,9 @@ var server = org.bukkit.Bukkit.server;
result.push(i); result.push(i);
} }
}else{ }else{
if (o.constructor == Array)
return result;
for (var i in o){ for (var i in o){
if (i.match(/^[^_]/)){ if (i.match(/^[^_]/)){
if (typeof o[i] == "function") if (typeof o[i] == "function")
@ -578,6 +581,7 @@ var server = org.bukkit.Bukkit.server;
break; break;
lastGoodSymbol = symbol; lastGoodSymbol = symbol;
} }
//print("debug:name["+name+"]lastSymbol["+lastSymbol+"]symbol["+symbol+"]");
if (typeof symbol == "undefined"){ if (typeof symbol == "undefined"){
// //
// look up partial matches against last good symbol // look up partial matches against last good symbol
@ -587,32 +591,47 @@ var server = org.bukkit.Bukkit.server;
// if the last symbol looks like this.. // if the last symbol looks like this..
// ScriptCraft. // ScriptCraft.
// //
for (var i =0;i < objectProps.length;i++)
propsOfLastArg.push(statement+objectProps[i]); for (var i =0;i < objectProps.length;i++){
var candidate = lastSymbol + objectProps[i];
propsOfLastArg.push(candidate);
}
}else{ }else{
// it looks like this.. // it looks like this..
// ScriptCraft.co // ScriptCraft.co
// //
//print("debug:case Y: ScriptCraft.co");
var li = statement.lastIndexOf(name); var li = statement.lastIndexOf(name);
statement = statement.substring(0,li); statement = statement.substring(0,li);
for (var i = 0; i < objectProps.length;i++) for (var i = 0; i < objectProps.length;i++){
if (objectProps[i].indexOf(name) == 0) if (objectProps[i].indexOf(name) == 0)
propsOfLastArg.push(statement + objectProps[i]); {
var candidate = lastSymbol.substring(0,lastSymbol.lastIndexOf(name));
candidate = candidate + objectProps[i];
propsOfLastArg.push(candidate);
}
}
} }
}else{ }else{
//print("debug:case Z:ScriptCraft");
var objectProps = _getProperties(symbol); var objectProps = _getProperties(symbol);
for (var i = 0; i < objectProps.length; i++){ for (var i = 0; i < objectProps.length; i++){
propsOfLastArg.push(statement + "." + objectProps[i]); propsOfLastArg.push(lastSymbol + "." + objectProps[i]);
} }
} }
}else{ }else{
//print("debug:case AB:ScriptCr");
// loop thru globalSymbols looking for a good match // loop thru globalSymbols looking for a good match
for (var i = 0;i < _globalSymbols.length; i++) for (var i = 0;i < _globalSymbols.length; i++){
if (_globalSymbols[i].indexOf(lastSymbol) == 0) if (_globalSymbols[i].indexOf(lastSymbol) == 0){
propsOfLastArg.push(statement.replace(lastSymbol,_globalSymbols[i])); var possibleCompletion = _globalSymbols[i];
propsOfLastArg.push(possibleCompletion);
}
}
} }
} }