From 244e1af2705eb264897054f1e8e38f934f971e4b Mon Sep 17 00:00:00 2001 From: walterhiggins Date: Sun, 7 Apr 2013 20:09:04 +0100 Subject: [PATCH] Fixed problems with AutoComplete --- src/main/javascript/core/_scriptcraft.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/javascript/core/_scriptcraft.js b/src/main/javascript/core/_scriptcraft.js index 036ec48..502c855 100644 --- a/src/main/javascript/core/_scriptcraft.js +++ b/src/main/javascript/core/_scriptcraft.js @@ -556,15 +556,19 @@ var server = org.bukkit.Bukkit.server; var _globalSymbols = _getProperties(global) var result = global.__onTC_result; var args = global.__onTC_args; + var lastArg = args.length?args[args.length-1]+"":null; var propsOfLastArg = []; var statement = args.join(" "); + statement = statement.replace(/^\s+/,"").replace(/\s+$/,""); + if (statement.length == 0) propsOfLastArg = _globalSymbols; else{ var statementSyms = statement.split(/[^\$a-zA-Z0-9_\.]/); var lastSymbol = statementSyms[statementSyms.length-1]; + //print("DEBUG: lastSymbol=[" + lastSymbol + "]"); // // try to complete the object ala java IDEs. // @@ -594,7 +598,8 @@ var server = org.bukkit.Bukkit.server; for (var i =0;i < objectProps.length;i++){ var candidate = lastSymbol + objectProps[i]; - propsOfLastArg.push(candidate); + var re = new RegExp(lastSymbol + "$","g"); + propsOfLastArg.push(lastArg.replace(re,candidate)); } }else{ @@ -604,14 +609,14 @@ var server = org.bukkit.Bukkit.server; //print("debug:case Y: ScriptCraft.co"); var li = statement.lastIndexOf(name); - statement = statement.substring(0,li); - for (var i = 0; i < objectProps.length;i++){ if (objectProps[i].indexOf(name) == 0) { var candidate = lastSymbol.substring(0,lastSymbol.lastIndexOf(name)); candidate = candidate + objectProps[i]; - propsOfLastArg.push(candidate); + var re = new RegExp(lastSymbol+ "$","g"); + //print("DEBUG: re=" + re + ",lastSymbol="+lastSymbol+",lastArg=" + lastArg + ",candidate=" + candidate); + propsOfLastArg.push(lastArg.replace(re,candidate)); } } @@ -620,7 +625,8 @@ var server = org.bukkit.Bukkit.server; //print("debug:case Z:ScriptCraft"); var objectProps = _getProperties(symbol); for (var i = 0; i < objectProps.length; i++){ - propsOfLastArg.push(lastSymbol + "." + objectProps[i]); + var re = new RegExp(lastSymbol+ "$","g"); + propsOfLastArg.push(lastArg.replace(re,lastSymbol + "." + objectProps[i])); } } }else{ @@ -629,7 +635,8 @@ var server = org.bukkit.Bukkit.server; for (var i = 0;i < _globalSymbols.length; i++){ if (_globalSymbols[i].indexOf(lastSymbol) == 0){ var possibleCompletion = _globalSymbols[i]; - propsOfLastArg.push(possibleCompletion); + var re = new RegExp(lastSymbol+ "$","g"); + propsOfLastArg.push(lastArg.replace(re,possibleCompletion)); } }