diff --git a/lib/coder.js b/lib/coder.js index 3db024c..a9a03fb 100644 --- a/lib/coder.js +++ b/lib/coder.js @@ -167,7 +167,7 @@ var ICEcoder = { } // Now we've built up our nest depth array, if we're due to show it in the display - if (updateNestDisplay) { + if (updateNestDisplay && !top.ICEcoder.dontUpdateNest) { // Clear the display ICEcoder.nestDisplay.innerHTML = ""; @@ -177,7 +177,7 @@ var ICEcoder = { // Then for all the array items, output as the nest display for (var i=0;i'+ICEcoder.htmlTagArray[i]+''; if(iSaving
'+ICEcoder.openFiles[ICEcoder.selectedTab-1]); }, @@ -1239,62 +1240,65 @@ var ICEcoder = { setTimeout(function() {top.ICEcoder.serverMessage();},2000); }, - // Fold or show code by clicking line nos in the gutter - foldCode: function(instance,lineNo,mouseEvt) { - var cM, string, origLine, origChar, collapseTag, nestDepth, cursor, lastLine; + // Highlight or hide block upon roll over/out of nest positions + highlightBlock: function(nestPos,hide) { + var cM; - cM = top.ICEcoder.getcMInstance(); + cM = ICEcoder.getcMInstance(); + // Hiding the block + if (hide) { + // Either set our cursor back to the orig position if we have't clicked or redo the nest display if we have + top.ICEcoder.dontUpdateNest ? cM.setCursor(top.ICEcoder.cursorOrigLine,top.ICEcoder.cursorOrigCh) : top.ICEcoder.getNestLocation('updateNestDisplay'); + top.ICEcoder.dontUpdateNest = false; + } else { + // Showing the block, get orig cursor position + top.ICEcoder.cursorOrigCh = cM.getCursor().ch; + top.ICEcoder.cursorOrigLine = cM.getCursor().line; + top.ICEcoder.dontUpdateNest = true; + + // Set a cursor position object to begin with + searchPos = new Object(); + searchPos.ch = cM.getCursor().ch; + searchPos.line = cM.getCursor().line; + // Then find our cursor position for our target nest depth + for (var i=top.ICEcoder.htmlTagArray.length-1;i>=nestPos;i--) { + cursor = cM.getSearchCursor("<"+top.ICEcoder.htmlTagArray[i],searchPos); + cursor.findPrevious(); + searchPos.ch = cursor.from().ch; + searchPos.line = cursor.from().line; + } + // Once we've found our tag + if (cursor.from()) { + // Set our vars to match the start position + startPos = new Object(); + top.ICEcoder.startPosCh = startPos.ch = cursor.from().ch; + top.ICEcoder.startPosLine = startPos.line = cursor.from().line; + // Now set an end position object that matches this start tag + endPos = new Object(); + endPos.line = top.ICEcoder.content.contentWindow.CodeMirror.tagRangeFinder(cM,startPos.line)-1 || startPos.line; + endPos.ch = cM.getLine(endPos.line).indexOf("")+top.ICEcoder.htmlTagArray[nestPos].length+3; + // Set the selection or escape out of not selecting + !top.ICEcoder.dontSelect ? cM.setSelection(startPos,endPos) : top.ICEcoder.dontSelect = false; + } + } + }, - setTimeout(function() { - // If the next line is hidden, unhide lines until we reach a line that isn't hidden - if (cM.lineInfo(lineNo+1).handle.hidden) { - for (var i=lineNo;i<=1000000;i++) { - cM.lineInfo(i+1).handle.hidden ? cM.showLine(i+1) : i=1000000; - if (!cM.lineInfo(i+1).handle.hidden) { - cM.clearMarker(i); - } - } - // Clear the gutter marker - cM.clearMarker(lineNo); - } else { - // Get the line of text, plus set our original (current) line & char position - string = cM.getLine(lineNo); - origLine = cM.getCursor().line; - origChar = cM.getCursor().ch; + // Set our cursor position upon mouse click of the nest position + setPosition: function(nestPos,line,tag) { + var cM; - // Then shoft the cursor to just after the first > char - cM.setCursor(lineNo,string.indexOf(">")+1); - - setTimeout(function() { - // Get the tag we're collapsing on and it's nest depth - collapseTag = top.ICEcoder.htmlTagArray[top.ICEcoder.htmlTagArray.length-1]; - nestDepth = top.ICEcoder.htmlTagArray.length; - - setTimeout(function() { - // If we don't have the end tag on the same line - if (string.indexOf("",string.indexOf("<"+collapseTag+">"))==-1) { - // Find each matching end tag in turn and if it's the same nest depth, we have the correct one - cursor = cM.getSearchCursor("",cM.getCursor()); - for (var i=0;i<=1000000;i++) { - lastLine = cursor.findNext(); - lastLine = cursor.to().line; - cM.setCursor(cursor.to().line,cursor.to().ch); - if (top.ICEcoder.htmlTagArray.length==nestDepth-1) { - i=1000000; - } - } - // Now we can hide lines in that range - for (i=lineNo+1;i+ %N%") - cM.setCursor(origLine,origChar); - },1); - - },1); - }; - },1); + cM = ICEcoder.getcMInstance(); + // Set out char position just after the tag, and refocus on the editor + char = cM.getLine(line).indexOf(">",cM.getLine(line).indexOf("<"+tag))+1; + cM.setCursor(line,char); + cM.focus(); + // Now update the nest display up to this nest depth & without any HTML tags to kill further interactivity + charPos = 0; + for (i=0;i<=nestPos;i++) { + charPos = ICEcoder.nestDisplay.innerHTML.indexOf(">",charPos+1); + } + ICEcoder.nestDisplay.innerHTML = ICEcoder.nestDisplay.innerHTML.substr(0,charPos).replace(/<(?:.|\n)*?>/gm, ''); + top.ICEcoder.dontUpdateNest = false; + top.ICEcoder.dontSelect = true; } }; \ No newline at end of file