From 880e04d7605abc5244aa85e43d2ac6c89839bccf Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Wed, 3 Oct 2012 19:39:11 +0100 Subject: [PATCH] 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) --- lib/coder.js | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/lib/coder.js b/lib/coder.js index a67d06b..f83747d 100644 --- a/lib/coder.js +++ b/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")+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;