Populate new results bar. plus tweak & bug fix

lineCount and charCount are var's no longer used, removed
Add scrollBarVisible var, is true or false depending on if we have a
scrollbar
Removed numChars and charsToCursor vars as we're now using
cM.indexFromPos which gives the same result, but using CodeMirror so
probably more efficient
A new ICEcoder.resultsLines array is now available, populated with
unique line numbers of found results
4 other new vars added for new functionality and also filesQS which I'd
missed adding before
New functionality to create colored blocks and add into the container,
at heights determined by the amount of content and colored according to
which line we're on
Else clause added to clear results and this container if we have a blank
find string
This commit is contained in:
Matt Pass
2013-08-07 18:47:21 +01:00
parent 5e4a185e9d
commit ce62da5b5c

View File

@@ -1041,7 +1041,7 @@ var ICEcoder = {
// Find & replace text according to user selections
findReplace: function(findString,resultsOnly,buttonClick) {
var find, replace, results, cM, content, lineCount, numChars, charsToCursor, charCount, cursor, replaceQS, targetQS;
var find, replace, results, cM, content, scrollBarVisible, cursor, avgBlockH, addPadding, rBlocks, blockColor, replaceQS, targetQS, filesQS;
// Determine our find & replace strings and results display
find = findString.toLowerCase();
@@ -1066,10 +1066,14 @@ var ICEcoder = {
content = cM.getValue().toLowerCase();
if (!top.ICEcoder.findMode||find!=top.ICEcoder.lastsearch) {
ICEcoder.results = [];
ICEcoder.resultsLines = [];
for (var i=0;i<content.length;i++) {
if (content.substr(i,find.length)==find && ICEcoder.results.indexOf(i) == -1) {
ICEcoder.results.push(i);
if (ICEcoder.resultsLines.indexOf(cM.posFromIndex(i).line+1)==-1) {
ICEcoder.resultsLines.push(cM.posFromIndex(i).line+1);
}
}
}
@@ -1079,23 +1083,18 @@ var ICEcoder = {
// If we have results
if (ICEcoder.results.length>0) {
// Detect if we have a scrollbar
scrollBarVisible = cM.getScrollInfo().height > cM.getScrollInfo().clientHeight;
// Show results only
if (resultsOnly) {
results.innerHTML = ICEcoder.results.length + " results";
// We need to take action instead
} else {
// Get the no of chars to our cursor
numChars=-1;
for (var i=0;i<cM.getCursor().line;i++) {
numChars += cM.getLine(i).length+1;
}
if (numChars==-1) {numChars=0};
charsToCursor = numChars+cM.getCursor().ch+1;
// Find our cursor position relative to results
ICEcoder.findResult = 0;
for (var i=0;i<ICEcoder.results.length;i++) {
if (ICEcoder.results[i]<charsToCursor) {
if (ICEcoder.results[i]<cM.indexFromPos(cM.getCursor())) {
ICEcoder.findResult++;
}
}
@@ -1115,9 +1114,27 @@ var ICEcoder = {
top.ICEcoder.focus();
top.ICEcoder.findMode = true;
}
// Display the find results bar
// The avg block is either line height or fraction of space available
avgBlockH = !scrollBarVisible ? cM.defaultTextHeight() : parseInt(top.ICEcoder.content.style.height,10)/cM.lineCount();
// Need to add padding if there's no scrollbar, so current line highlighting lines up with it
addPadding = !scrollBarVisible ? cM.heightAtLine(0) : 0;
// Place to edge of screen or scrollbar
top.ICEcoder.content.contentWindow.document.getElementById('resultsBar').style.right = !scrollBarVisible ? "0" : "17px";
rBlocks = "";
for (var i=1; i<=cM.lineCount(); i++) {
blockColor = ICEcoder.resultsLines.indexOf(i)>-1 ? cM.getCursor().line+1 == i ? "#b00" : "#888" : "transparent"
rBlocks += '<div style="position: absolute; display: block; width: 5px; height:'+avgBlockH+'px; background: '+blockColor+'; top: '+parseInt((avgBlockH*(i-1))+addPadding,10)+'px"></div>';
}
top.ICEcoder.content.contentWindow.document.getElementById('resultsBar').innerHTML = rBlocks;
top.ICEcoder.content.contentWindow.document.getElementById('resultsBar').style.display = "inline-block";
return true;
} else {
results.innerHTML = "No results";
top.ICEcoder.content.contentWindow.document.getElementById('resultsBar').innerHTML = "";
top.ICEcoder.content.contentWindow.document.getElementById('resultsBar').style.display = "none";
return false;
}
} else {
@@ -1139,6 +1156,11 @@ var ICEcoder = {
find != encodeURIComponent(find) ? find = 'ICEcoder:'+encodeURIComponent(find) : find;
top.ICEcoder.showHide('show',top.get('loadingMask'));
top.get('mediaContainer').innerHTML = '<iframe src="lib/multiple-results.php?find='+find+replaceQS+targetQS+filesQS+'" class="whiteGlow" style="width: 700px; height: 500px"></iframe>';
// We have nothing to search for, blank it all out
} else {
results.innerHTML = "No results";
top.ICEcoder.content.contentWindow.document.getElementById('resultsBar').innerHTML = "";
top.ICEcoder.content.contentWindow.document.getElementById('resultsBar').style.display = "none";
}
}
},