Nest display & find/replace improvements

Loaded code no longer has & converted to & so code is not messed with
Nesting only displays if you don't have include, include_once (PHP), plus must have html or body tag (HTML)
Found count display now updates on switching tabs
findReplace updated to take 3rd param, detecting how it was triggered
Find is now case-sensitive by default
Code realigned in findReplace to work more specifically with 'this document'
Extra code also added to replace all
Display count now fixed to be accurate
Multiple results screen show shows when not finding within current document
Function to deal with updating and showing/hiding of results count display
This commit is contained in:
Matt Pass
2012-05-05 17:36:13 +01:00
parent 83085c4c1f
commit 8c97be00dc

View File

@@ -93,7 +93,6 @@ var ICEcoder = {
if (fileName.indexOf(".js")<0&&fileName.indexOf(".rb")&&fileName.indexOf(".css")<0) {
cM = ICEcoder.getcMInstance();
content = cM.getValue();
if (top.ICEcoder.codeAssist) {content = content.replace(/ & /g,' &amp; ');};
content = content.replace(/<ICEcoder:\/:textarea>/g,'</textarea>');
// Then set the content in the editor & clear the history
@@ -178,12 +177,13 @@ var ICEcoder = {
// Now we've built up our nest depth array, if we're due to show it in the display
if (updateNestDisplay && !top.ICEcoder.dontUpdateNest) {
// Clear the display
ICEcoder.nestDisplay.innerHTML = "";
if ("undefined" != typeof ICEcoder.openFiles[ICEcoder.selectedTab-1]) {
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
if (fileName.indexOf(".js")<0&&fileName.indexOf(".rb")<0&&fileName.indexOf(".css")<0) {
if (fileName.indexOf(".js")<0&&fileName.indexOf(".rb")<0&&fileName.indexOf(".css")<0&&
(nestCheck.indexOf("include(")==-1)&&(nestCheck.indexOf("include_once(")==-1)&&
(nestCheck.indexOf("<html")>-1||nestCheck.indexOf("<body")>-1)) {
// Then for all the array items, output as the nest display
for (var i=0;i<ICEcoder.htmlTagArray.length;i++) {
@@ -360,7 +360,8 @@ var ICEcoder = {
ICEcoder.redoTabHighlight(ICEcoder.selectedTab);
// Redo our find display
ICEcoder.findReplace('find',true);
top.ICEcoder.findMode = false;
ICEcoder.findReplace('find',true,false);
}
},
@@ -845,30 +846,42 @@ var ICEcoder = {
},
// Find & replace text according to user selections
findReplace: function(action,resultsOnly) {
var find, findLen, cM, content, lineCount, numChars, charsToCursor, charCount, startPos, endPos;
findReplace: function(action,resultsOnly,buttonClick) {
var find, findLen, replaceLen, cM, content, lineCount, numChars, charsToCursor, charCount, startPos, endPos, replaceQS;
// Determine our find string, in lowercase and the length of that
find = parent.parent.document.getElementById('find').value.toLowerCase();
find = top.document.getElementById('find').value;
findLen = find.length;
replaceLen = top.document.getElementById('replace').value.length;
// If we have something to find
if (findLen>0) {
// If we have something to find in currrent document
if (findLen>0 && document.findAndReplace.target.value=="this document") {
cM = ICEcoder.getcMInstance();
content = cM.getValue().toLowerCase();
content = cM.getValue();
// Find & replace the next instance?
if (document.findAndReplace.connector.value=="and" && cM.getSelection()==find) {
cM.replaceSelection(document.getElementById('replace').value);
// Find & replace the next instance, or all?
if (document.findAndReplace.connector.value=="and") {
if (document.findAndReplace.replaceAction.value=="replace" && cM.getSelection()==find) {
cM.replaceSelection(document.getElementById('replace').value);
}
if (document.findAndReplace.replaceAction.value=="replace all" && buttonClick) {
var rExp = new RegExp(find,"g");
cM.setValue(cM.getValue().replace(rExp,document.getElementById('replace').value));
}
}
// Get the content again, as it might of changed
content = cM.getValue();
if (!top.ICEcoder.findMode||parent.parent.document.getElementById('find').value!=ICEcoder.lastsearch) {
ICEcoder.results = [];
for (var i=0;i<content.length;i++) {
if (content.substr(i,findLen)==find) {
if (content.substr(i,findLen)==find && i!= ICEcoder.findResult) {
ICEcoder.results.push(i);
i+=findLen-1;
}
}
// Also remember the last search term made
ICEcoder.lastsearch = find;
}
@@ -893,7 +906,7 @@ var ICEcoder = {
charsToCursor = numChars+cM.getCursor().ch;
ICEcoder.findResult = 0;
for (var i=0;i<ICEcoder.results.length;i++) {
if (ICEcoder.results[i]<=charsToCursor) {
if (ICEcoder.results[i]<charsToCursor) {
ICEcoder.findResult++;
}
}
@@ -908,13 +921,17 @@ var ICEcoder = {
}
}
charCount = ICEcoder.results[ICEcoder.findResult]-content.lastIndexOf('\n',ICEcoder.results[ICEcoder.findResult])-1;
charCount = ICEcoder.results[ICEcoder.findResult];
startPos = new Object();
startPos.line = lineCount;
startPos.ch = charCount;
endPos = new Object();
endPos.line = lineCount;
endPos.ch = charCount+findLen;
if (document.findAndReplace.connector.value=="and" && document.findAndReplace.replaceAction.value=="replace all" && buttonClick) {
endPos.ch = charCount+replaceLen;
} else {
endPos.ch = charCount+findLen;
}
// Finally, highlight our selection
cM = ICEcoder.getcMInstance();
@@ -926,7 +943,14 @@ var ICEcoder = {
parent.parent.document.getElementById('results').innerHTML = "No results";
}
} else {
parent.parent.document.getElementById('results').innerHTML = "";
// Show the relevant multiple results popup
if (find != "" && buttonClick) {
replaceQS = "";
if (document.findAndReplace.connector.value=="and") {
replaceQS = "&replace="+document.getElementById('replace').value;
}
top.document.getElementById('mediaContainer').innerHTML = '<iframe src="lib/multiple-results.php?find='+find+replaceQS+'" class="whiteGlow" style="width: 700px; height: 500px"></iframe>';
}
}
},
@@ -1447,5 +1471,11 @@ var ICEcoder = {
// Finally, refresh the file manager if we need to
if (refreshFM) {top.ICEcoder.refreshFileManager()};
},
// Update and show/hide found results display?
updateResultsDisplay: function(showHide) {
ICEcoder.findReplace('find',true,false);
document.getElementById('results').style.display = showHide == "show" ? 'inline-block' : 'none';
}
};