mirror of
https://github.com/icecoder/ICEcoder.git
synced 2026-03-03 07:13:59 +01:00
Anon objects & CM's searchCursor used, fixed nest
Now just usage anonymous objects inline instead of creating for single use (saves adding extra vars and is less code) Removed findLen and replaceLen as only findLen was being used twice Replaced how we find & replace by using CM's searchcursor Fix to the selection on hover over nest items, doesn't need -1 (This is because I fixed CM's tagRangeFinder to include last line)
This commit is contained in:
43
lib/coder.js
43
lib/coder.js
@@ -444,16 +444,13 @@ var ICEcoder = {
|
||||
|
||||
// Indicate if the nesting structure of the code is OK
|
||||
updateNestingIndicator: function () {
|
||||
var cM, nestOK, fileName, endDoc;
|
||||
var cM, nestOK, fileName;
|
||||
|
||||
cM = ICEcoder.getcMInstance();
|
||||
nestOK = true;
|
||||
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
|
||||
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;
|
||||
nestOK = cM.getTokenAt({line:cM.lineCount(),ch:cM.lineInfo(cM.lineCount()-1).text.length}).className != "error" ? true : false;
|
||||
}
|
||||
ICEcoder.nestValid.style.backgroundColor = nestOK ? "#0b0" : "#f00";
|
||||
ICEcoder.nestValid.innerHTML = nestOK ? "Nesting OK" : "Nesting Broken";
|
||||
@@ -858,16 +855,10 @@ var ICEcoder = {
|
||||
|
||||
// Highlight specified line
|
||||
highlightLine: function(line) {
|
||||
var cM, selStart, selEnd;
|
||||
var cM;
|
||||
|
||||
cM = top.ICEcoder.getcMInstance();
|
||||
selStart = new Object();
|
||||
selStart.line = line;
|
||||
selStart.ch = 0;
|
||||
selEnd = new Object();
|
||||
selEnd.line = line;
|
||||
selEnd.ch = cM.lineInfo(line).text.length;
|
||||
cM.setSelection(selStart, selEnd);
|
||||
cM.setSelection({line:line,ch:0}, {line:line,ch:cM.lineInfo(line).text.length});
|
||||
},
|
||||
|
||||
// Update find & replace options based on user selection
|
||||
@@ -881,17 +872,15 @@ var ICEcoder = {
|
||||
|
||||
// Find & replace text according to user selections
|
||||
findReplace: function(action,resultsOnly,buttonClick) {
|
||||
var find, findLen, replace, replaceLen, results, cM, content, lineCount, numChars, charsToCursor, charCount, startPos, endPos, replaceQS, targetQS;
|
||||
var find, replace, results, cM, content, lineCount, numChars, charsToCursor, charCount, cursor, replaceQS, targetQS;
|
||||
|
||||
// Determine our find & replace strings and the length of them
|
||||
find = top.document.getElementById('find').value;
|
||||
findLen = find.length;
|
||||
replace = top.document.getElementById('replace').value;
|
||||
replaceLen = replace.length;
|
||||
results = top.document.getElementById('results');
|
||||
|
||||
// If we have something to find in currrent document
|
||||
if (findLen>0 && document.findAndReplace.target.value=="this document") {
|
||||
if (find.length>0 && document.findAndReplace.target.value=="this document") {
|
||||
cM = ICEcoder.getcMInstance();
|
||||
content = cM.getValue();
|
||||
|
||||
@@ -911,7 +900,7 @@ var ICEcoder = {
|
||||
ICEcoder.results = [];
|
||||
|
||||
for (var i=0;i<content.length;i++) {
|
||||
if (content.substr(i,findLen)==find && i!= ICEcoder.findResult) {
|
||||
if (content.substr(i,find.length)==find && i!= ICEcoder.findResult) {
|
||||
ICEcoder.results.push(i);
|
||||
}
|
||||
}
|
||||
@@ -961,15 +950,15 @@ var ICEcoder = {
|
||||
if (ICEcoder.results[ICEcoder.findResult]<=cM.lineInfo(0).text.length) {
|
||||
charCount++;
|
||||
}
|
||||
startPos = new Object();
|
||||
startPos.line = lineCount;
|
||||
startPos.ch = charCount;
|
||||
endPos = new Object();
|
||||
endPos.line = lineCount;
|
||||
endPos.ch = charCount+findLen;
|
||||
|
||||
cursor = cM.getSearchCursor(find,cM.getCursor());
|
||||
cursor.findNext();
|
||||
if (!cursor.from()) {
|
||||
cursor = cM.getSearchCursor(find,{line:0,ch:0});
|
||||
cursor.findNext();
|
||||
}
|
||||
// Finally, highlight our selection
|
||||
cM = ICEcoder.getcMInstance();
|
||||
cM.setSelection(startPos, endPos);
|
||||
cM.setSelection(cursor.from(), cursor.to());
|
||||
cM.focus();
|
||||
top.ICEcoder.findMode = true;
|
||||
}
|
||||
@@ -1422,7 +1411,7 @@ var ICEcoder = {
|
||||
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.line = top.ICEcoder.content.contentWindow.CodeMirror.tagRangeFinder(cM,startPos.line) || 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;
|
||||
|
||||
Reference in New Issue
Block a user