Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit d78821a

Browse files
author
mattpass
committed
4 x functions tidied in icecoder.js
1 parent 8322e0b commit d78821a

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

assets/js/icecoder.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4925,39 +4925,40 @@ var ICEcoder = {
49254925

49264926
// Reset the state of keys back to the normal state
49274927
resetKeys: function(evt) {
4928-
var key, cM;
4928+
let key, thisCM;
49294929

49304930
key = evt.keyCode ?? evt.which ?? evt.charCode;
49314931

4932-
if (key == 112 && true === this.codeZoomedOut) {
4933-
cM = this.getcMInstance();
4932+
if (112 === key && true === this.codeZoomedOut) {
4933+
thisCM = this.getcMInstance();
49344934
// For every line in the current editor, remove code-zoomed-out class if not a function/class declaration line
4935-
for (var i=0; i<cM.lineCount(); i++) {
4936-
var nonDeclareLine = true;
4937-
for (var j=0; j<this.functionClassList.length; j++) {
4938-
if (this.functionClassList[j].line == i) {
4935+
for (let i = 0; i < thisCM.lineCount(); i++) {
4936+
let nonDeclareLine = true;
4937+
for (let j = 0; j < this.functionClassList.length; j++) {
4938+
if (i === this.functionClassList[j].line) {
49394939
nonDeclareLine = false;
49404940
}
49414941
}
4942-
if (nonDeclareLine) {
4943-
cM.removeLineClass(i, "wrap", "code-zoomed-out");
4942+
if (true === nonDeclareLine) {
4943+
thisCM.removeLineClass(i, "wrap", "code-zoomed-out");
49444944
}
49454945
}
49464946
// Refresh is necessary to re-draw lines
4947-
cM.refresh();
4947+
thisCM.refresh();
49484948

49494949
// Go to line chosen if any
4950-
var cursor = cM.getCursor();
4950+
let cursor = thisCM.getCursor();
49514951
this.goToLine(cursor.line + 1, cursor.ch, false);
49524952

49534953
this.codeZoomedOut = false;
49544954
}
49554955
this.cmdKey = false;
49564956
},
49574957

4958+
// Handle Enter and Escape keys in modals
49584959
handleModalKeyUp: function(evt, page) {
49594960
const key = evt.keyCode ?? evt.which ?? evt.charCode;
4960-
const target = get('blackMask') ? get('blackMask') : parent.get('blackMask');
4961+
const target = get('blackMask') ?? parent.get('blackMask');
49614962

49624963
if ("settings" === page && 13 === key) {
49634964
get(page + 'IFrame').contentWindow.submitSettings();
@@ -4969,65 +4970,65 @@ var ICEcoder = {
49694970

49704971
// Add snippet code completion
49714972
addSnippet: function() {
4972-
var thisCM, lineNo, whiteSpace, content;
4973+
let thisCM, lineNo, whiteSpace, content;
49734974

49744975
// Get line content after trimming whitespace
49754976
thisCM = this.getThisCM();
49764977
lineNo = thisCM.getCursor().line;
49774978
whiteSpace = thisCM.getLine(lineNo).length - thisCM.getLine(lineNo).replace(/^\s\s*/, '').length;
49784979
content = thisCM.getLine(lineNo).slice(whiteSpace);
49794980
// function snippet
4980-
if (content.slice(0,8)=="function") {
4981-
this.doSnippet('function','function VAR() {\nINDENT\tCURSOR\nINDENT}');
4982-
// if snippet
4983-
} else if (content.slice(0,2)=="if") {
4984-
this.doSnippet('if','if (CURSOR) {\nINDENT\t\nINDENT}');
4985-
// for snippet
4986-
} else if (content.slice(0,3)=="for") {
4987-
this.doSnippet('for','for (let i = 0; i <CURSOR; i++) {\nINDENT\t\nINDENT}');
4981+
if ("function" === content.slice(0, 8)) {
4982+
this.doSnippet('function', 'function VAR() {\nINDENT\tCURSOR\nINDENT}');
4983+
// if snippet
4984+
} else if ("if" === content.slice(0, 2)) {
4985+
this.doSnippet('if', 'if (CURSOR) {\nINDENT\t\nINDENT}');
4986+
// for snippet
4987+
} else if ("for" === content.slice(0, 3)) {
4988+
this.doSnippet('for', 'for (let i = 0; i <CURSOR; i++) {\nINDENT\t\nINDENT}');
49884989
}
49894990
},
49904991

49914992
// Action a snippet
4992-
doSnippet: function(tgtString,replaceString) {
4993-
var thisCM, lineNo, lineContents, remainder, strPos, replacedLine, whiteSpace, curPos, sPos, lineNoCount;
4993+
doSnippet: function(tgtString, replaceString) {
4994+
let thisCM, lineNo, lineContents, remainder, strPos, replacedLine, whiteSpace, curPos, sPos, lineNoCount;
49944995

49954996
// Get line contents
49964997
thisCM = this.getThisCM();
49974998
lineNo = thisCM.getCursor().line;
49984999
lineContents = thisCM.getLine(lineNo);
49995000

50005001
// Find our target string
5001-
if (lineContents.indexOf(tgtString)>-1) {
5002+
if (-1 < lineContents.indexOf(tgtString)) {
50025003
// Get text on the line from our target to the end
50035004
remainder = thisCM.getLine(lineNo);
50045005
strPos = remainder.indexOf(tgtString);
5005-
remainder = remainder.slice(remainder.indexOf(tgtString)+tgtString.length+1);
5006+
remainder = remainder.slice(remainder.indexOf(tgtString) + tgtString.length + 1);
50065007
// Replace the function name if any
5007-
replaceString = replaceString.replace(/VAR/g,remainder);
5008+
replaceString = replaceString.replace(/VAR/g, remainder);
50085009
// Get replaced string from start to our strPos
5009-
replacedLine = thisCM.getLine(lineNo).slice(0,strPos);
5010+
replacedLine = thisCM.getLine(lineNo).slice(0, strPos);
50105011
// Trim whitespace from start
50115012
whiteSpace = thisCM.getLine(lineNo).length - thisCM.getLine(lineNo).replace(/^\s\s*/, '').length;
5012-
whiteSpace = thisCM.getLine(lineNo).slice(0,whiteSpace);
5013+
whiteSpace = thisCM.getLine(lineNo).slice(0, whiteSpace);
50135014
// Replace indent with whatever whitespace we have
5014-
replaceString = replaceString.replace(/INDENT/g,whiteSpace);
5015+
replaceString = replaceString.replace(/INDENT/g, whiteSpace);
50155016
replacedLine += replaceString;
50165017
// Get cursor position
50175018
curPos = replacedLine.indexOf("CURSOR");
50185019
sPos = 0;
50195020
lineNoCount = lineNo;
5020-
for (i=0;i<replacedLine.length;i++) {
5021-
if (replacedLine.indexOf("\n",sPos)<replacedLine.indexOf("CURSOR")) {
5022-
sPos = replacedLine.indexOf("\n",sPos)+1;
5023-
lineNoCount = lineNoCount+1;
5021+
for (let i = 0; i < replacedLine.length; i++) {
5022+
if (replacedLine.indexOf("\n", sPos) < replacedLine.indexOf("CURSOR")) {
5023+
sPos = replacedLine.indexOf("\n", sPos) + 1;
5024+
lineNoCount = lineNoCount + 1;
50245025
}
50255026
}
50265027
// Clear the cursor string and set the cursor there
5027-
thisCM.replaceRange(replacedLine.replace("CURSOR",""),{line:lineNo,ch:0},{line:lineNo,ch:1000000}, "+input");
5028-
thisCM.setCursor(lineNoCount,curPos);
5028+
thisCM.replaceRange(replacedLine.replace("CURSOR", ""), {line: lineNo, ch: 0}, {line: lineNo, ch: 1000000}, "+input");
5029+
thisCM.setCursor(lineNoCount, curPos);
50295030
// Finally, focus on the editor
5030-
this.focus(this.editorFocusInstance.indexOf('diff') > -1 ? true : false);
5031+
this.focus(-1 < this.editorFocusInstance.indexOf('diff') ? true : false);
50315032
}
50325033
},
50335034

0 commit comments

Comments
 (0)