From 967d5ebc8395f6d246db20ed2c40a5a2684666d1 Mon Sep 17 00:00:00 2001 From: Kyle Miller Date: Wed, 1 Jun 2016 16:27:28 -0500 Subject: [PATCH 1/5] Fixed parsons indent bug --- runestone/parsons/js/parsons.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/runestone/parsons/js/parsons.js b/runestone/parsons/js/parsons.js index 96b4b812b..e7b64a606 100644 --- a/runestone/parsons/js/parsons.js +++ b/runestone/parsons/js/parsons.js @@ -820,8 +820,12 @@ // Consecutive lines to be dragged as a single block of code have strings "\\n" to // represent newlines => replace them with actual new line characters "\n" //codestring = codestring.replace(/\\n\s+/g,"\\n"); // remove leading spaced if more than one line in a code block - added in below to not change the codestring - this.code = code.replace(trimRegexp, "$1").replace(/\\n\s+/g,"\\n").replace(/\\n+/g,"\n"); + this.code = code.replace(trimRegexp, "$1").replace(/\\n+/g,"\n"); this.indent = codestring.length - codestring.replace(/^\s+/, "").length; + alert("Code"); + alert(this.code); + alert("Codestring"); + alert(codestring); } }; ParsonsCodeline.prototype.elem = function() { From 936017e8acba258c7f56b22c6845c5e53eb03385 Mon Sep 17 00:00:00 2001 From: Kyle Miller Date: Wed, 1 Jun 2016 16:28:26 -0500 Subject: [PATCH 2/5] Removed alert messages --- runestone/parsons/js/parsons.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/runestone/parsons/js/parsons.js b/runestone/parsons/js/parsons.js index e7b64a606..654d4fae9 100644 --- a/runestone/parsons/js/parsons.js +++ b/runestone/parsons/js/parsons.js @@ -822,10 +822,7 @@ //codestring = codestring.replace(/\\n\s+/g,"\\n"); // remove leading spaced if more than one line in a code block - added in below to not change the codestring this.code = code.replace(trimRegexp, "$1").replace(/\\n+/g,"\n"); this.indent = codestring.length - codestring.replace(/^\s+/, "").length; - alert("Code"); - alert(this.code); - alert("Codestring"); - alert(codestring); + } }; ParsonsCodeline.prototype.elem = function() { From a41dbde9a68dcf483434112c2bd8803365b42ff3 Mon Sep 17 00:00:00 2001 From: Kyle Miller Date: Thu, 2 Jun 2016 15:08:40 -0500 Subject: [PATCH 3/5] Fixed problem deciding when to indent --- runestone/parsons/js/parsons.js | 39 ++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/runestone/parsons/js/parsons.js b/runestone/parsons/js/parsons.js index 654d4fae9..6bf4d5d68 100644 --- a/runestone/parsons/js/parsons.js +++ b/runestone/parsons/js/parsons.js @@ -820,9 +820,46 @@ // Consecutive lines to be dragged as a single block of code have strings "\\n" to // represent newlines => replace them with actual new line characters "\n" //codestring = codestring.replace(/\\n\s+/g,"\\n"); // remove leading spaced if more than one line in a code block - added in below to not change the codestring - this.code = code.replace(trimRegexp, "$1").replace(/\\n+/g,"\n"); this.indent = codestring.length - codestring.replace(/^\s+/, "").length; + var linelist = []; + var line = ""; + + for (char in code) { + + if (code[char] == 'n') { + if (code[char-1] == '\\') { + line = line + 'n'; + linelist.push(line); + line = ""; + } else { + + line = line + code[char]; + } + + } else { + + line = line + code[char]; + } + } + linelist.push(line); + + var indentFlag = false; + for (lineindex in linelist) { + var line = linelist[lineindex]; + var numSpaces = line.length - line.replace(/^\s+/, "").length; + if (numSpaces != this.indent) { + indentFlag = true; + } + } + + if (indentFlag) { + //Only strip leading white space on the first line of the code block + this.code = code.replace(trimRegexp, "$1").replace(/\\n+/g,"\n"); + } else { + //strip all leading white space on each line of the code block + this.code = code.replace(trimRegexp, "$1").replace(/\\n\s+/g,"\\n").replace(/\\n+/g,"\n"); + } } }; ParsonsCodeline.prototype.elem = function() { From 918a2201416d9dd6ca1cda5e6b26061ec14f51ce Mon Sep 17 00:00:00 2001 From: Kyle Miller Date: Fri, 3 Jun 2016 11:49:46 -0500 Subject: [PATCH 4/5] Fixed alignment but now appending extra function --- runestone/parsons/js/parsons.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/runestone/parsons/js/parsons.js b/runestone/parsons/js/parsons.js index 6bf4d5d68..77962640d 100644 --- a/runestone/parsons/js/parsons.js +++ b/runestone/parsons/js/parsons.js @@ -821,7 +821,6 @@ // represent newlines => replace them with actual new line characters "\n" //codestring = codestring.replace(/\\n\s+/g,"\\n"); // remove leading spaced if more than one line in a code block - added in below to not change the codestring this.indent = codestring.length - codestring.replace(/^\s+/, "").length; - var linelist = []; var line = ""; @@ -854,8 +853,16 @@ } if (indentFlag) { - //Only strip leading white space on the first line of the code block + if (this.indent > 0) { + code = ""; + for (lineindex in linelist) { + code = code + linelist[lineindex].slice(this.indent); + } + } + this.code = code.replace(trimRegexp, "$1").replace(/\\n+/g,"\n"); + + } else { //strip all leading white space on each line of the code block this.code = code.replace(trimRegexp, "$1").replace(/\\n\s+/g,"\\n").replace(/\\n+/g,"\n"); From 81ad3ceaae47693ae6f41436749c3c9a54811036 Mon Sep 17 00:00:00 2001 From: Kyle Miller Date: Fri, 3 Jun 2016 12:58:35 -0500 Subject: [PATCH 5/5] Fixed weird behavior of appending functions --- runestone/parsons/js/parsons.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/runestone/parsons/js/parsons.js b/runestone/parsons/js/parsons.js index 77962640d..b0acb035b 100644 --- a/runestone/parsons/js/parsons.js +++ b/runestone/parsons/js/parsons.js @@ -824,28 +824,28 @@ var linelist = []; var line = ""; - for (char in code) { + for (i=0; i 0) { code = ""; - for (lineindex in linelist) { - code = code + linelist[lineindex].slice(this.indent); + for (i=0;i