mirror of
https://github.com/icecoder/ICEcoder.git
synced 2026-03-07 17:16:47 +01:00
htmlTagArray defined in top settings now
updateNestingIndicator now setup on a setInterval every 30 ms (This is due to timing issues and solves this without being noticable) Only if we have a context for the given tag build up the array If so, reset htmlTagArray and build up the array again This means we stick with the old array if we're in a script or style block (for example) Set the tagString to be the last item in the array If caretLocType is JS, set the tagString to script (This is because CodeMirror doesn't recognise this as a tag) updateNestingIndicator now works by: - checking if we have a cM instance and not in JS, Coffee etc filetypes - gets token information for the very end of the document - detects if it's className is an error or not to determin if the nesting is broken Fix to detecting the code type we're in as without -1, JavaScript is ignored as it's array item 0
This commit is contained in:
37
lib/coder.js
37
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;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user