mirror of
https://github.com/icecoder/ICEcoder.git
synced 2026-03-03 07:13:59 +01:00
Nest hover/click function, better code folding plus error catching
You can now hover mouse over nest positions to have them selected Can also click to set cursor position to within that nest Removed old code folding function in favour of lib that comes with CodeMirror Errors catched so clicking on a blank area of the file manager doesn't attempt anything
This commit is contained in:
118
lib/coder.js
118
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.length;i++) {
|
||||
ICEcoder.nestDisplay.innerHTML += ICEcoder.htmlTagArray[i];
|
||||
ICEcoder.nestDisplay.innerHTML += '<a onMouseover="top.ICEcoder.highlightBlock('+i+')" onMouseout="top.ICEcoder.highlightBlock('+i+',\'hide\')" onClick="top.ICEcoder.setPosition('+i+',top.ICEcoder.startPosLine,\''+ICEcoder.htmlTagArray[i]+'\')" style="cursor: pointer">'+ICEcoder.htmlTagArray[i]+'</a>';
|
||||
if(i<ICEcoder.htmlTagArray.length-1) {ICEcoder.nestDisplay.innerHTML += " > "};
|
||||
}
|
||||
}
|
||||
@@ -604,7 +604,7 @@ var ICEcoder = {
|
||||
// Set our array to contain 0 items
|
||||
top.ICEcoder.selectedFiles.length = 0;
|
||||
}
|
||||
} else {
|
||||
} else if (top.ICEcoder.thisFileFolderLink) {
|
||||
// We clicked a file/folder. Work out a shortened URL for the file, with pipes instead of slashes
|
||||
shortURL = top.ICEcoder.thisFileFolderLink.substr((top.ICEcoder.thisFileFolderLink.indexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.thisFileFolderLink.length).replace(/\//g,"|");
|
||||
|
||||
@@ -733,6 +733,7 @@ var ICEcoder = {
|
||||
var saveType;
|
||||
|
||||
saveAs ? saveType = "saveAs" : saveType = "save";
|
||||
|
||||
top.ICEcoder.serverQueue("add","lib/file-control.php?action=save&file="+ICEcoder.openFiles[ICEcoder.selectedTab-1].replace(/\//g,"|")+"&saveType="+saveType);
|
||||
top.ICEcoder.serverMessage('<b>Saving</b><br>'+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]+">")+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("</"+collapseTag+">",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("</"+collapseTag+">",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<lastLine;i++) {
|
||||
cM.hideLine(i);
|
||||
}
|
||||
}
|
||||
// Finally, set the marker in the gutter and return our cursor to the original position
|
||||
cM.setMarker(lineNo, "<span style=\"color: #ffffff; cursor: pointer\">+</span> %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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user