diff --git a/lib/coder.js b/lib/coder.js index 5f9ae76..e0bb0f7 100644 --- a/lib/coder.js +++ b/lib/coder.js @@ -16,6 +16,7 @@ var ICEcoder = { selectedFiles: [], // Array of selected files findMode: false, // States if we're in find/replace mode lockedNav: true, // Nav is locked or not + htmlTagArray: [], // Array storing the nest of tags codeAssist: true, // Assist user with their coding mouseDown: false, // If the mouse is down or not draggingFilesW: false, // If we're dragging the file manager width or not @@ -57,6 +58,7 @@ var ICEcoder = { tab.addEventListener('drop', ICEcoder.handleDrop, false); tab.addEventListener('dragend', ICEcoder.handleDragEnd, false); }); + setInterval(ICEcoder.updateNestingIndicator,30); top.ICEcoder.ready = true; }, @@ -108,16 +110,23 @@ var ICEcoder = { // Work out the nesting depth location on demand and update our display if required getNestLocation: function(updateNestDisplay) { - var cM, state, nestCheck, startPos, fileName; + var cM, nestCheck, state, cx, startPos, fileName; cM = ICEcoder.getcMInstance(); + nestCheck = cM.getValue(); // 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(); + state = cM.getTokenAt(cM.getCursor()).state; + if ("undefined" != typeof state.curState.context) { + ICEcoder.htmlTagArray = []; + for (cx = state.curState.context; cx; cx = cx.prev) { + ICEcoder.htmlTagArray.unshift(cx.tagName); + } + } + ICEcoder.tagString = ICEcoder.htmlTagArray[ICEcoder.htmlTagArray.length-1]; + if (ICEcoder.caretLocType=="JavaScript") { + ICEcoder.tagString = "script"; + } // Now we've built up our nest depth array, if we're due to show it in the display if (updateNestDisplay && !top.ICEcoder.dontUpdateNest) { @@ -435,16 +444,16 @@ var ICEcoder = { // Indicate if the nesting structure of the code is OK updateNestingIndicator: function () { - var cM, fileName, nestOK; + var cM, fileName, nestOK, endDoc; cM = ICEcoder.getcMInstance(); + nestOK = true; fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1]; - ICEcoder.caretPos=cM.getValue().length; - ICEcoder.getNestLocation(); - nestOK = false; - // Nesting is OK if at the end of the file we have no nests left, or it's a JS, Ruby or CSS file - if (ICEcoder.htmlTagArray.length==0||["js","coffee","rb","css","less"].indexOf(fileName.split(".")[1])>0) { - nestOK = true; + if (cM && ["js","coffee","rb","css","less"].indexOf(fileName.split(".")[1])==-1) { + endDoc = new Object(); + endDoc.line = cM.lineCount(); + endDoc.ch = cM.lineInfo(endDoc.line-1).text.length; + nestOK = cM.getTokenAt(endDoc).className != "error" ? true : false; } ICEcoder.nestValid.style.backgroundColor = nestOK ? "#0b0" : "#f00"; ICEcoder.nestValid.innerHTML = nestOK ? "Nesting OK" : "Nesting Broken"; @@ -499,7 +508,7 @@ var ICEcoder = { ICEcoder.caretLocType = caretLocType; // If we're in a JS, CoffeeScript PHP or Ruby code block, add that to the nest display - if (["JavaScript","CoffeeScript","PHP","Ruby"].indexOf(caretLocType)) { + if (["JavaScript","CoffeeScript","PHP","Ruby"].indexOf(caretLocType)>-1) { ICEcoder.nestDisplay.innerHTML += " > " + caretLocType; } },