diff --git a/lib/coder.js b/lib/coder.js index 787ada6..5f9ae76 100644 --- a/lib/coder.js +++ b/lib/coder.js @@ -108,71 +108,17 @@ var ICEcoder = { // Work out the nesting depth location on demand and update our display if required getNestLocation: function(updateNestDisplay) { - var cM, openTag, nestCheck, startPos, tagStart, canDoTheEndTag, tagEnd, tagEndJS, fileName; + var cM, state, nestCheck, startPos, fileName; cM = ICEcoder.getcMInstance(); + + // Set up array to store nest data + ICEcoder.htmlTagArray = []; + state = cM.getTokenAt(cM.getCursor()).state, ICEcoder.htmlTagArray = []; + for (var cx = state.curState.context; cx; cx = cx.prev) ICEcoder.htmlTagArray.unshift(cx.tagName); + nestCheck = cM.getValue(); - // Set up array to store nest data, a var to establish if a tag is open and another to establish if we're in a code block - ICEcoder.htmlTagArray = [], openTag = false, ICEcoder.codeBlock = false; - - // For every character from the start to our caret position - for(var i=0;i<=ICEcoder.caretPos;i++) { - - // If we find a < tag and we're not within a tag, change the open tag state & set our start position - if(nestCheck.charAt(i)=="<" && openTag==false) { - openTag=true; - startPos=i+1; - - // Get the tag name and if it's the start of a code block, set the var for that - tagStart=nestCheck.substr(startPos,nestCheck.length).split(" ")[0].split(">")[0].split("\n")[0]; - if (tagStart=="script"||tagStart=="?php"||tagStart=="?"||tagStart=="%") {ICEcoder.codeBlock=true} - if (tagStart!="") {ICEcoder.tagStart=tagStart} - }; - - // If we find a > tag and we're within a tag or codeblock - if(nestCheck.charAt(i)==">" && (openTag||ICEcoder.codeBlock)) { - - // Get the tag name - tagString=nestCheck.substr(0,i); - tagString=tagString.substr(tagString.lastIndexOf('<')+1,tagString.length); - tagString=tagString.split(" ")[0]; - ICEcoder.tagString = tagString; - canDoTheEndTag=true; - - // Check it's not on our list of exceptions - if (ICEcoder.tagNestExceptions.indexOf(tagString)>-1) { - canDoTheEndTag=false; - } - - if (canDoTheEndTag) { - // Get this end tag name - tagEnd=nestCheck.substr(0,i); - tagEndJS=tagEnd.substr(tagEnd.lastIndexOf('<')); - tagEnd=tagEnd.substr(tagEnd.lastIndexOf('<')+1); - tagEnd=tagEnd.substr(tagEnd.lastIndexOf(' ')+1); - tagEnd=tagEnd.substr(tagEnd.lastIndexOf('\t')+1); - tagEnd=tagEnd.substr(tagEnd.lastIndexOf('\n')+1); - tagEnd=tagEnd.substr(tagEnd.lastIndexOf(';')+1); - - if (!ICEcoder.codeBlock) { - // OK, we can do something further as we're not in a code block - // If it's the same as the previously logged tag preceeded by /, it's the equivalent end tag - // so remove the last logged tag, thereby going up one in the nest, otherwise it's a different tag, add it to the end - tagEnd=="/"+ICEcoder.htmlTagArray[ICEcoder.htmlTagArray.length-1] ? ICEcoder.htmlTagArray.pop() : ICEcoder.htmlTagArray.push(tagString); - } else if ( - ((ICEcoder.tagStart=="script"||ICEcoder.tagStart=="/script")&&tagEndJS=="