diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 75b47c8..fe49fed 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,9 @@
-
+
@@ -160,7 +160,16 @@
-
+
+
+
+
+
+
+
+
+
+
1564063805490
diff --git a/dist/block_mirror.js b/dist/block_mirror.js
index 7f1edd0..5c90249 100644
--- a/dist/block_mirror.js
+++ b/dist/block_mirror.js
@@ -356,7 +356,6 @@ BlockMirror.prototype.VISIBLE_MODES = {
BlockMirror.prototype.BREAK_WIDTH = 675;
BlockMirror.prototype.setHighlightedLines = function (lines, style) {
- this.textEditor.clearHighlightedLines();
this.textEditor.setHighlightedLines(lines, style); //this.blockEditor.highlightLines(lines, style);
};
@@ -594,11 +593,21 @@ BlockMirrorTextEditor.prototype.setHighlightedLines = function (lines, style) {
BlockMirrorTextEditor.prototype.clearHighlightedLines = function () {
var _this3 = this;
- return this.highlightedHandles.map(function (h) {
- _this3.codeMirror.doc.removeLineClass(h.handle, "background", h.style);
+ if (this.highlightedHandles) {
+ var removed = this.highlightedHandles.map(function (h) {
+ _this3.codeMirror.doc.removeLineClass(h.handle, "background", h.style);
- return _this3.codeMirror.doc.lineInfo(h.handle).line + 1;
- });
+ var info = _this3.codeMirror.doc.lineInfo(h.handle);
+
+ if (info) {
+ return info.line + 1;
+ } else {
+ return info;
+ }
+ });
+ this.highlightedHandles = [];
+ return removed;
+ }
};
/**
* Worth noting - Blockly uses a setTimeOut of 0 steps to make events
@@ -1272,7 +1281,12 @@ BlockMirrorTextToBlocks.prototype.convertBody = function (node, parent) {
if (lastLineNumber in this.comments) {
var _commentChild = this.ast_Comment(this.comments[lastLineNumber], lastLineNumber);
- nestChild(_commentChild);
+ if (is_top_level && !previousWasStatement) {
+ addPeer(_commentChild);
+ } else {
+ nestChild(_commentChild);
+ }
+
delete this.comments[lastLineNumber];
} // Handle any extra comments that stuck around
diff --git a/src/block_mirror.js b/src/block_mirror.js
index 8bc2100..4bae3bc 100644
--- a/src/block_mirror.js
+++ b/src/block_mirror.js
@@ -217,7 +217,6 @@ BlockMirror.prototype.VISIBLE_MODES = {
BlockMirror.prototype.BREAK_WIDTH = 675;
BlockMirror.prototype.setHighlightedLines = function(lines, style) {
- this.textEditor.clearHighlightedLines();
this.textEditor.setHighlightedLines(lines, style);
//this.blockEditor.highlightLines(lines, style);
};
diff --git a/src/text_editor.js b/src/text_editor.js
index 731e69a..822e9ea 100644
--- a/src/text_editor.js
+++ b/src/text_editor.js
@@ -217,8 +217,17 @@ BlockMirrorTextEditor.prototype.setHighlightedLines = function (lines, style) {
};
BlockMirrorTextEditor.prototype.clearHighlightedLines = function () {
- return this.highlightedHandles.map((h) => {
- this.codeMirror.doc.removeLineClass(h.handle, "background", h.style);
- return this.codeMirror.doc.lineInfo(h.handle).line+1;
- });
+ if (this.highlightedHandles) {
+ let removed = this.highlightedHandles.map((h) => {
+ this.codeMirror.doc.removeLineClass(h.handle, "background", h.style);
+ var info = this.codeMirror.doc.lineInfo(h.handle);
+ if (info) {
+ return info.line + 1;
+ } else {
+ return info;
+ }
+ });
+ this.highlightedHandles = [];
+ return removed;
+ }
};
\ No newline at end of file
diff --git a/src/text_to_blocks.js b/src/text_to_blocks.js
index e18a85f..d36550d 100644
--- a/src/text_to_blocks.js
+++ b/src/text_to_blocks.js
@@ -7,13 +7,13 @@ function BlockMirrorTextToBlocks(blockMirror) {
BlockMirrorTextToBlocks.xmlToString = function (xml) {
return new XMLSerializer().serializeToString(xml);
-}
+};
BlockMirrorTextToBlocks.prototype.convertSourceToCodeBlock = function (python_source) {
var xml = document.createElement("xml");
xml.appendChild(BlockMirrorTextToBlocks.raw_block(python_source));
return BlockMirrorTextToBlocks.xmlToString(xml);
-}
+};
/**
* The main function for converting a string representation of Python
@@ -245,13 +245,13 @@ BlockMirrorTextToBlocks.prototype.convertBody = function (node, parent) {
// Handle top-level expression blocks
if (is_top_level && newChild.constructor === Array) {
addPeer(newChild[0]);
- // Handle skipped line
+ // Handle skipped line
} else if (is_top_level && skipped_line && visitedFirstLine) {
addPeer(newChild);
- // The previous line was not a Peer
+ // The previous line was not a Peer
} else if (is_top_level && !previousWasStatement) {
addPeer(newChild);
- // Otherwise, always embed it in there.
+ // Otherwise, always embed it in there.
} else {
nestChild(newChild);
}
@@ -265,7 +265,11 @@ BlockMirrorTextToBlocks.prototype.convertBody = function (node, parent) {
var lastLineNumber = lineNumberInProgram + 1;
if (lastLineNumber in this.comments) {
let commentChild = this.ast_Comment(this.comments[lastLineNumber], lastLineNumber);
- nestChild(commentChild);
+ if (is_top_level && !previousWasStatement) {
+ addPeer(commentChild);
+ } else {
+ nestChild(commentChild);
+ }
delete this.comments[lastLineNumber];
}