Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
* Simple Devices: new device type (HTML)
* Simple Devices: optimizing
* Blockly: html-editor fix
* 3rdparty: CodeMirror update
  • Loading branch information
sergejey committed Apr 25, 2019
1 parent d24b2bb commit 52f1bfe
Show file tree
Hide file tree
Showing 102 changed files with 11,349 additions and 8,578 deletions.
45 changes: 29 additions & 16 deletions 3rdparty/codemirror/addon/comment/comment.js
@@ -1,5 +1,5 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // Distributed under an MIT license: https://codemirror.net/LICENSE


(function(mod) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
Expand Down Expand Up @@ -44,9 +44,22 @@
} }
}); });


// Rough heuristic to try and detect lines that are part of multi-line string
function probablyInsideString(cm, pos, line) {
return /\bstring\b/.test(cm.getTokenTypeAt(Pos(pos.line, 0))) && !/^[\'\"\`]/.test(line)
}

function getMode(cm, pos) {
var mode = cm.getMode()
return mode.useInnerComments === false || !mode.innerMode ? mode : cm.getModeAt(pos)
}

CodeMirror.defineExtension("lineComment", function(from, to, options) { CodeMirror.defineExtension("lineComment", function(from, to, options) {
if (!options) options = noOptions; if (!options) options = noOptions;
var self = this, mode = self.getModeAt(from); var self = this, mode = getMode(self, from);
var firstLine = self.getLine(from.line);
if (firstLine == null || probablyInsideString(self, from, firstLine)) return;

var commentString = options.lineComment || mode.lineComment; var commentString = options.lineComment || mode.lineComment;
if (!commentString) { if (!commentString) {
if (options.blockCommentStart || mode.blockCommentStart) { if (options.blockCommentStart || mode.blockCommentStart) {
Expand All @@ -55,8 +68,7 @@
} }
return; return;
} }
var firstLine = self.getLine(from.line);
if (firstLine == null) return;
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line + 1 : to.line, self.lastLine() + 1); var end = Math.min(to.ch != 0 || to.line == from.line ? to.line + 1 : to.line, self.lastLine() + 1);
var pad = options.padding == null ? " " : options.padding; var pad = options.padding == null ? " " : options.padding;
var blankLines = options.commentBlankLines || from.line == to.line; var blankLines = options.commentBlankLines || from.line == to.line;
Expand Down Expand Up @@ -88,14 +100,15 @@


CodeMirror.defineExtension("blockComment", function(from, to, options) { CodeMirror.defineExtension("blockComment", function(from, to, options) {
if (!options) options = noOptions; if (!options) options = noOptions;
var self = this, mode = self.getModeAt(from); var self = this, mode = getMode(self, from);
var startString = options.blockCommentStart || mode.blockCommentStart; var startString = options.blockCommentStart || mode.blockCommentStart;
var endString = options.blockCommentEnd || mode.blockCommentEnd; var endString = options.blockCommentEnd || mode.blockCommentEnd;
if (!startString || !endString) { if (!startString || !endString) {
if ((options.lineComment || mode.lineComment) && options.fullLines != false) if ((options.lineComment || mode.lineComment) && options.fullLines != false)
self.lineComment(from, to, options); self.lineComment(from, to, options);
return; return;
} }
if (/\bcomment\b/.test(self.getTokenTypeAt(Pos(from.line, 0)))) return


var end = Math.min(to.line, self.lastLine()); var end = Math.min(to.line, self.lastLine());
if (end != from.line && to.ch == 0 && nonWS.test(self.getLine(end))) --end; if (end != from.line && to.ch == 0 && nonWS.test(self.getLine(end))) --end;
Expand All @@ -121,7 +134,7 @@


CodeMirror.defineExtension("uncomment", function(from, to, options) { CodeMirror.defineExtension("uncomment", function(from, to, options) {
if (!options) options = noOptions; if (!options) options = noOptions;
var self = this, mode = self.getModeAt(from); var self = this, mode = getMode(self, from);
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line : to.line - 1, self.lastLine()), start = Math.min(from.line, end); var end = Math.min(to.ch != 0 || to.line == from.line ? to.line : to.line - 1, self.lastLine()), start = Math.min(from.line, end);


// Try finding line comments // Try finding line comments
Expand All @@ -133,7 +146,7 @@
var line = self.getLine(i); var line = self.getLine(i);
var found = line.indexOf(lineString); var found = line.indexOf(lineString);
if (found > -1 && !/comment/.test(self.getTokenTypeAt(Pos(i, found + 1)))) found = -1; if (found > -1 && !/comment/.test(self.getTokenTypeAt(Pos(i, found + 1)))) found = -1;
if (found == -1 && (i != end || i == start) && nonWS.test(line)) break lineComment; if (found == -1 && nonWS.test(line)) break lineComment;
if (found > -1 && nonWS.test(line.slice(0, found))) break lineComment; if (found > -1 && nonWS.test(line.slice(0, found))) break lineComment;
lines.push(line); lines.push(line);
} }
Expand All @@ -155,15 +168,15 @@
var endString = options.blockCommentEnd || mode.blockCommentEnd; var endString = options.blockCommentEnd || mode.blockCommentEnd;
if (!startString || !endString) return false; if (!startString || !endString) return false;
var lead = options.blockCommentLead || mode.blockCommentLead; var lead = options.blockCommentLead || mode.blockCommentLead;
var startLine = self.getLine(start), endLine = end == start ? startLine : self.getLine(end); var startLine = self.getLine(start), open = startLine.indexOf(startString)
var open = startLine.indexOf(startString), close = endLine.lastIndexOf(endString); if (open == -1) return false
if (close == -1 && start != end) { var endLine = end == start ? startLine : self.getLine(end)
endLine = self.getLine(--end); var close = endLine.indexOf(endString, end == start ? open + startString.length : 0);
close = endLine.lastIndexOf(endString); var insideStart = Pos(start, open + 1), insideEnd = Pos(end, close + 1)
} if (close == -1 ||
if (open == -1 || close == -1 || !/comment/.test(self.getTokenTypeAt(insideStart)) ||
!/comment/.test(self.getTokenTypeAt(Pos(start, open + 1))) || !/comment/.test(self.getTokenTypeAt(insideEnd)) ||
!/comment/.test(self.getTokenTypeAt(Pos(end, close + 1)))) self.getRange(insideStart, insideEnd, "\n").indexOf(endString) > -1)
return false; return false;


// Avoid killing block comments completely outside the selection. // Avoid killing block comments completely outside the selection.
Expand Down
37 changes: 15 additions & 22 deletions 3rdparty/codemirror/addon/comment/continuecomment.js
@@ -1,5 +1,5 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // Distributed under an MIT license: https://codemirror.net/LICENSE


(function(mod) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
Expand All @@ -9,39 +9,32 @@
else // Plain browser env else // Plain browser env
mod(CodeMirror); mod(CodeMirror);
})(function(CodeMirror) { })(function(CodeMirror) {
var modes = ["clike", "css", "javascript"];

for (var i = 0; i < modes.length; ++i)
CodeMirror.extendMode(modes[i], {blockCommentContinue: " * "});

function continueComment(cm) { function continueComment(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass; if (cm.getOption("disableInput")) return CodeMirror.Pass;
var ranges = cm.listSelections(), mode, inserts = []; var ranges = cm.listSelections(), mode, inserts = [];
for (var i = 0; i < ranges.length; i++) { for (var i = 0; i < ranges.length; i++) {
var pos = ranges[i].head, token = cm.getTokenAt(pos); var pos = ranges[i].head
if (token.type != "comment") return CodeMirror.Pass; if (!/\bcomment\b/.test(cm.getTokenTypeAt(pos))) return CodeMirror.Pass;
var modeHere = CodeMirror.innerMode(cm.getMode(), token.state).mode; var modeHere = cm.getModeAt(pos)
if (!mode) mode = modeHere; if (!mode) mode = modeHere;
else if (mode != modeHere) return CodeMirror.Pass; else if (mode != modeHere) return CodeMirror.Pass;


var insert = null; var insert = null;
if (mode.blockCommentStart && mode.blockCommentContinue) { if (mode.blockCommentStart && mode.blockCommentContinue) {
var end = token.string.indexOf(mode.blockCommentEnd); var line = cm.getLine(pos.line).slice(0, pos.ch)
var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found; var end = line.lastIndexOf(mode.blockCommentEnd), found
if (end != -1 && end == token.string.length - mode.blockCommentEnd.length && pos.ch >= end) { if (end != -1 && end == pos.ch - mode.blockCommentEnd.length) {
// Comment ended, don't continue it // Comment ended, don't continue it
} else if (token.string.indexOf(mode.blockCommentStart) == 0) { } else if ((found = line.lastIndexOf(mode.blockCommentStart)) > -1 && found > end) {
insert = full.slice(0, token.start); insert = line.slice(0, found)
if (!/^\s*$/.test(insert)) { if (/\S/.test(insert)) {
insert = ""; insert = ""
for (var j = 0; j < token.start; ++j) insert += " "; for (var j = 0; j < found; ++j) insert += " "
} }
} else if ((found = full.indexOf(mode.blockCommentContinue)) != -1 && } else if ((found = line.indexOf(mode.blockCommentContinue)) > -1 && !/\S/.test(line.slice(0, found))) {
found + mode.blockCommentContinue.length > token.start && insert = line.slice(0, found)
/^\s*$/.test(full.slice(0, found))) {
insert = full.slice(0, found);
} }
if (insert != null) insert += mode.blockCommentContinue; if (insert != null) insert += mode.blockCommentContinue
} }
if (insert == null && mode.lineComment && continueLineCommentEnabled(cm)) { if (insert == null && mode.lineComment && continueLineCommentEnabled(cm)) {
var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment); var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment);
Expand Down
6 changes: 5 additions & 1 deletion 3rdparty/codemirror/addon/dialog/dialog.js
@@ -1,5 +1,5 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // Distributed under an MIT license: https://codemirror.net/LICENSE


// Open simple dialogs on top of an editor. Relies on dialog.css. // Open simple dialogs on top of an editor. Relies on dialog.css.


Expand All @@ -25,6 +25,7 @@
} else { // Assuming it's a detached DOM element. } else { // Assuming it's a detached DOM element.
dialog.appendChild(template); dialog.appendChild(template);
} }
CodeMirror.addClass(wrap, 'dialog-opened');
return dialog; return dialog;
} }


Expand All @@ -47,6 +48,7 @@
} else { } else {
if (closed) return; if (closed) return;
closed = true; closed = true;
CodeMirror.rmClass(dialog.parentNode, 'dialog-opened');
dialog.parentNode.removeChild(dialog); dialog.parentNode.removeChild(dialog);
me.focus(); me.focus();


Expand Down Expand Up @@ -102,6 +104,7 @@
function close() { function close() {
if (closed) return; if (closed) return;
closed = true; closed = true;
CodeMirror.rmClass(dialog.parentNode, 'dialog-opened');
dialog.parentNode.removeChild(dialog); dialog.parentNode.removeChild(dialog);
me.focus(); me.focus();
} }
Expand Down Expand Up @@ -141,6 +144,7 @@
if (closed) return; if (closed) return;
closed = true; closed = true;
clearTimeout(doneTimer); clearTimeout(doneTimer);
CodeMirror.rmClass(dialog.parentNode, 'dialog-opened');
dialog.parentNode.removeChild(dialog); dialog.parentNode.removeChild(dialog);
} }


Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/codemirror/addon/display/autorefresh.js
@@ -1,5 +1,5 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // Distributed under an MIT license: https://codemirror.net/LICENSE


(function(mod) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/codemirror/addon/display/fullscreen.js
@@ -1,5 +1,5 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // Distributed under an MIT license: https://codemirror.net/LICENSE


(function(mod) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
Expand Down
23 changes: 19 additions & 4 deletions 3rdparty/codemirror/addon/display/panel.js
@@ -1,5 +1,5 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // Distributed under an MIT license: https://codemirror.net/LICENSE


(function(mod) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
Expand All @@ -17,13 +17,15 @@
var info = this.state.panels; var info = this.state.panels;
var wrapper = info.wrapper; var wrapper = info.wrapper;
var cmWrapper = this.getWrapperElement(); var cmWrapper = this.getWrapperElement();
var replace = options.replace instanceof Panel && !options.replace.cleared;


if (options.after instanceof Panel && !options.after.cleared) { if (options.after instanceof Panel && !options.after.cleared) {
wrapper.insertBefore(node, options.before.node.nextSibling); wrapper.insertBefore(node, options.before.node.nextSibling);
} else if (options.before instanceof Panel && !options.before.cleared) { } else if (options.before instanceof Panel && !options.before.cleared) {
wrapper.insertBefore(node, options.before.node); wrapper.insertBefore(node, options.before.node);
} else if (options.replace instanceof Panel && !options.replace.cleared) { } else if (replace) {
wrapper.insertBefore(node, options.replace.node); wrapper.insertBefore(node, options.replace.node);
info.panels++;
options.replace.clear(); options.replace.clear();
} else if (options.position == "bottom") { } else if (options.position == "bottom") {
wrapper.appendChild(node); wrapper.appendChild(node);
Expand All @@ -37,7 +39,12 @@


var height = (options && options.height) || node.offsetHeight; var height = (options && options.height) || node.offsetHeight;
this._setSize(null, info.heightLeft -= height); this._setSize(null, info.heightLeft -= height);
info.panels++; if (!replace) {
info.panels++;
}
if (options.stable && isAtTop(this, node))
this.scrollTo(null, this.getScrollInfo().top + height)

return new Panel(this, node, options, height); return new Panel(this, node, options, height);
}); });


Expand All @@ -54,14 +61,16 @@
this.cleared = true; this.cleared = true;
var info = this.cm.state.panels; var info = this.cm.state.panels;
this.cm._setSize(null, info.heightLeft += this.height); this.cm._setSize(null, info.heightLeft += this.height);
if (this.options.stable && isAtTop(this.cm, this.node))
this.cm.scrollTo(null, this.cm.getScrollInfo().top - this.height)
info.wrapper.removeChild(this.node); info.wrapper.removeChild(this.node);
if (--info.panels == 0) removePanels(this.cm); if (--info.panels == 0) removePanels(this.cm);
}; };


Panel.prototype.changed = function(height) { Panel.prototype.changed = function(height) {
var newHeight = height == null ? this.node.offsetHeight : height; var newHeight = height == null ? this.node.offsetHeight : height;
var info = this.cm.state.panels; var info = this.cm.state.panels;
this.cm._setSize(null, info.height += (newHeight - this.height)); this.cm._setSize(null, info.heightLeft -= (newHeight - this.height));
this.height = newHeight; this.height = newHeight;
}; };


Expand Down Expand Up @@ -109,4 +118,10 @@
cm.setSize = cm._setSize; cm.setSize = cm._setSize;
cm.setSize(); cm.setSize();
} }

function isAtTop(cm, dom) {
for (var sibling = dom.nextSibling; sibling; sibling = sibling.nextSibling)
if (sibling == cm.getWrapperElement()) return true
return false
}
}); });
5 changes: 4 additions & 1 deletion 3rdparty/codemirror/addon/display/placeholder.js
@@ -1,5 +1,5 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // Distributed under an MIT license: https://codemirror.net/LICENSE


(function(mod) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
Expand All @@ -14,10 +14,12 @@
if (val && !prev) { if (val && !prev) {
cm.on("blur", onBlur); cm.on("blur", onBlur);
cm.on("change", onChange); cm.on("change", onChange);
cm.on("swapDoc", onChange);
onChange(cm); onChange(cm);
} else if (!val && prev) { } else if (!val && prev) {
cm.off("blur", onBlur); cm.off("blur", onBlur);
cm.off("change", onChange); cm.off("change", onChange);
cm.off("swapDoc", onChange);
clearPlaceholder(cm); clearPlaceholder(cm);
var wrapper = cm.getWrapperElement(); var wrapper = cm.getWrapperElement();
wrapper.className = wrapper.className.replace(" CodeMirror-empty", ""); wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
Expand All @@ -36,6 +38,7 @@
clearPlaceholder(cm); clearPlaceholder(cm);
var elt = cm.state.placeholder = document.createElement("pre"); var elt = cm.state.placeholder = document.createElement("pre");
elt.style.cssText = "height: 0; overflow: visible"; elt.style.cssText = "height: 0; overflow: visible";
elt.style.direction = cm.getOption("direction");
elt.className = "CodeMirror-placeholder"; elt.className = "CodeMirror-placeholder";
var placeHolder = cm.getOption("placeholder") var placeHolder = cm.getOption("placeholder")
if (typeof placeHolder == "string") placeHolder = document.createTextNode(placeHolder) if (typeof placeHolder == "string") placeHolder = document.createTextNode(placeHolder)
Expand Down
40 changes: 14 additions & 26 deletions 3rdparty/codemirror/addon/display/rulers.js
@@ -1,5 +1,5 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others // CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE // Distributed under an MIT license: https://codemirror.net/LICENSE


(function(mod) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
Expand All @@ -11,30 +11,26 @@
})(function(CodeMirror) { })(function(CodeMirror) {
"use strict"; "use strict";


CodeMirror.defineOption("rulers", false, function(cm, val, old) { CodeMirror.defineOption("rulers", false, function(cm, val) {
if (old && old != CodeMirror.Init) { if (cm.state.rulerDiv) {
clearRulers(cm); cm.state.rulerDiv.parentElement.removeChild(cm.state.rulerDiv)
cm.off("refresh", refreshRulers); cm.state.rulerDiv = null
cm.off("refresh", drawRulers)
} }
if (val && val.length) { if (val && val.length) {
setRulers(cm); cm.state.rulerDiv = cm.display.lineSpace.parentElement.insertBefore(document.createElement("div"), cm.display.lineSpace)
cm.on("refresh", refreshRulers); cm.state.rulerDiv.className = "CodeMirror-rulers"
drawRulers(cm)
cm.on("refresh", drawRulers)
} }
}); });


function clearRulers(cm) { function drawRulers(cm) {
for (var i = cm.display.lineSpace.childNodes.length - 1; i >= 0; i--) { cm.state.rulerDiv.textContent = ""
var node = cm.display.lineSpace.childNodes[i];
if (/(^|\s)CodeMirror-ruler($|\s)/.test(node.className))
node.parentNode.removeChild(node);
}
}

function setRulers(cm) {
var val = cm.getOption("rulers"); var val = cm.getOption("rulers");
var cw = cm.defaultCharWidth(); var cw = cm.defaultCharWidth();
var left = cm.charCoords(CodeMirror.Pos(cm.firstLine(), 0), "div").left; var left = cm.charCoords(CodeMirror.Pos(cm.firstLine(), 0), "div").left;
var minH = cm.display.scroller.offsetHeight + 30; cm.state.rulerDiv.style.minHeight = (cm.display.scroller.offsetHeight + 30) + "px";
for (var i = 0; i < val.length; i++) { for (var i = 0; i < val.length; i++) {
var elt = document.createElement("div"); var elt = document.createElement("div");
elt.className = "CodeMirror-ruler"; elt.className = "CodeMirror-ruler";
Expand All @@ -49,15 +45,7 @@
if (conf.width) elt.style.borderLeftWidth = conf.width; if (conf.width) elt.style.borderLeftWidth = conf.width;
} }
elt.style.left = (left + col * cw) + "px"; elt.style.left = (left + col * cw) + "px";
elt.style.top = "-50px"; cm.state.rulerDiv.appendChild(elt)
elt.style.bottom = "-20px";
elt.style.minHeight = minH + "px";
cm.display.lineSpace.insertBefore(elt, cm.display.cursorDiv);
} }
} }

function refreshRulers(cm) {
clearRulers(cm);
setRulers(cm);
}
}); });

0 comments on commit 52f1bfe

Please sign in to comment.