Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
acbart committed Oct 6, 2019
1 parent 38ac1d1 commit 01cd27e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 19 deletions.
13 changes: 11 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 20 additions & 6 deletions dist/block_mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/block_mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
17 changes: 13 additions & 4 deletions src/text_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
16 changes: 10 additions & 6 deletions src/text_to_blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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];
}

Expand Down

0 comments on commit 01cd27e

Please sign in to comment.