Skip to content

Commit

Permalink
allow line highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
acbart committed Aug 31, 2019
1 parent 4b0f3d7 commit 38ac1d1
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 15 deletions.
14 changes: 2 additions & 12 deletions .idea/workspace.xml

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

41 changes: 40 additions & 1 deletion dist/block_mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,21 @@ 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);
};

BlockMirror.prototype.clearHighlightedLines = function () {
this.textEditor.clearHighlightedLines(); //this.blockEditor.unhighlightLines(lines, style);
};

function BlockMirrorTextEditor(blockMirror) {
this.blockMirror = blockMirror;
this.textContainer = blockMirror.tags.textContainer;
this.textArea = blockMirror.tags.textArea;
this.textSidebar = blockMirror.tags.textSidebar; // notification
this.textSidebar = blockMirror.tags.textSidebar;
this.highlightedHandles = []; // notification

this.silentEvents_ = false; // Do we need to force an update?

Expand Down Expand Up @@ -568,6 +578,28 @@ BlockMirrorTextEditor.prototype.changed = function (codeMirror, event) {
BlockMirrorTextEditor.prototype.isVisible = function () {
return this.blockMirror.VISIBLE_MODES.text.indexOf(this.blockMirror.mode_) !== -1;
};

BlockMirrorTextEditor.prototype.setHighlightedLines = function (lines, style) {
var _this2 = this;

var handles = lines.map(function (l) {
return {
"handle": _this2.codeMirror.doc.addLineClass(l - 1, "background", style),
"style": style
};
});
this.highlightedHandles = this.highlightedHandles.concat(handles);
};

BlockMirrorTextEditor.prototype.clearHighlightedLines = function () {
var _this3 = this;

return this.highlightedHandles.map(function (h) {
_this3.codeMirror.doc.removeLineClass(h.handle, "background", h.style);

return _this3.codeMirror.doc.lineInfo(h.handle).line + 1;
});
};
/**
* Worth noting - Blockly uses a setTimeOut of 0 steps to make events
* wait. That has some confusing interaction with trying to make things percolate.
Expand Down Expand Up @@ -933,6 +965,13 @@ BlockMirrorBlockEditor.prototype.getPngFromBlocks = function (callback) {
}
};

BlockMirrorBlockEditor.prototype.highlightLines = function (lines, style) {// Make some kind of block map?

/*this.workspace.getAllBlocks().map((block) => {
block
});*/
};

function BlockMirrorTextToBlocks(blockMirror) {
this.blockMirror = blockMirror;
this.hiddenImports = ["plt"];
Expand Down
9 changes: 8 additions & 1 deletion src/block_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,11 @@ BlockMirrorBlockEditor.prototype.getPngFromBlocks = function(callback) {
callback("", document.createElement("img"));
console.error("PNG image creation not supported!", e);
}
}
};

BlockMirrorBlockEditor.prototype.highlightLines = function(lines, style) {
// Make some kind of block map?
/*this.workspace.getAllBlocks().map((block) => {
block
});*/
};
13 changes: 12 additions & 1 deletion src/block_mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,15 @@ BlockMirror.prototype.VISIBLE_MODES = {
'text': ['text', 'split']
};

BlockMirror.prototype.BREAK_WIDTH = 675;
BlockMirror.prototype.BREAK_WIDTH = 675;

BlockMirror.prototype.setHighlightedLines = function(lines, style) {
this.textEditor.clearHighlightedLines();
this.textEditor.setHighlightedLines(lines, style);
//this.blockEditor.highlightLines(lines, style);
};

BlockMirror.prototype.clearHighlightedLines = function() {
this.textEditor.clearHighlightedLines();
//this.blockEditor.unhighlightLines(lines, style);
};
17 changes: 17 additions & 0 deletions src/text_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ function BlockMirrorTextEditor(blockMirror) {
this.textArea = blockMirror.tags.textArea;
this.textSidebar = blockMirror.tags.textSidebar;

this.highlightedHandles = [];

// notification
this.silentEvents_ = false;

Expand Down Expand Up @@ -204,4 +206,19 @@ BlockMirrorTextEditor.prototype.changed = function (codeMirror, event) {

BlockMirrorTextEditor.prototype.isVisible = function () {
return this.blockMirror.VISIBLE_MODES.text.indexOf(this.blockMirror.mode_) !== -1;
};

BlockMirrorTextEditor.prototype.setHighlightedLines = function (lines, style) {
let handles = lines.map((l) => { return {
"handle": this.codeMirror.doc.addLineClass(l-1, "background", style),
"style": style
}});
this.highlightedHandles = this.highlightedHandles.concat(handles);
};

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;
});
};

0 comments on commit 38ac1d1

Please sign in to comment.