From fcd032d26362ca5feac9511fc29bde71da205f91 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Sat, 21 Sep 2019 22:16:17 +0100 Subject: [PATCH] JS code tidy and put function back in --- lib/ice-coder.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/ice-coder.js b/lib/ice-coder.js index 0a63a59..a16619a 100644 --- a/lib/ice-coder.js +++ b/lib/ice-coder.js @@ -3115,7 +3115,6 @@ var ICEcoder = { if (["object","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) { console.log(statusObj); } - // If error, show that, otherwise do whatever we're required to do next if (statusObj.status.error) { top.ICEcoder.message(statusObj.status.errorMsg); @@ -3564,7 +3563,7 @@ var ICEcoder = { outputMsg: function(msg) { top.ICEcoder.output.innerHTML += msg + "
"; }, - + // Show a message message: function(msg) { alert(msg); @@ -4258,7 +4257,6 @@ var ICEcoder = { top.ICEcoder.cmdKey = true; } - // F1 (zoom code out non declaration lines) if (key === 112) { if (top.ICEcoder.codeZoomedOut) { @@ -4283,7 +4281,7 @@ var ICEcoder = { cM.refresh(); return false; }; - + // DEL (Delete file) if (key==46 && area == "files") { top.ICEcoder.deleteFiles(); @@ -4537,6 +4535,29 @@ var ICEcoder = { top.ICEcoder.cmdKey = false; }, + // Add snippet code completion + addSnippet: function() { + var cM, cMdiff, thisCM, lineNo, whiteSpace, content; + + // Get line content after trimming whitespace + cM = ICEcoder.getcMInstance(); + cMdiff = ICEcoder.getcMdiffInstance(); + thisCM = top.ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? cMdiff : cM; + lineNo = thisCM.getCursor().line; + whiteSpace = thisCM.getLine(lineNo).length - thisCM.getLine(lineNo).replace(/^\s\s*/, '').length; + content = thisCM.getLine(lineNo).slice(whiteSpace); + // function snippet + if (content.slice(0,8)=="function") { + top.ICEcoder.doSnippet('function','function VAR() {\nINDENT\tCURSOR\nINDENT}'); + // if snippet + } else if (content.slice(0,2)=="if") { + top.ICEcoder.doSnippet('if','if (CURSOR) {\nINDENT\t\nINDENT}'); + // for snippet + } else if (content.slice(0,3)=="for") { + top.ICEcoder.doSnippet('for','for (var i=0; i