Skip to content

Commit dce7cde

Browse files
committed
update from dabbler0/droplet on 12-1-14
1 parent 11b5002 commit dce7cde

File tree

5 files changed

+229
-49
lines changed

5 files changed

+229
-49
lines changed

blockly/lib/droplet/droplet-full.js

Lines changed: 110 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,6 +2589,28 @@ QUAD.init = function (args) {
25892589
return this.notifyChange();
25902590
};
25912591

2592+
Container.prototype.getNewlineBefore = function(n) {
2593+
var head, lines;
2594+
head = this.start;
2595+
lines = 0;
2596+
while (!(lines === n || head === this.end)) {
2597+
head = head.next;
2598+
if (head.type === 'newline') {
2599+
lines++;
2600+
}
2601+
}
2602+
return head;
2603+
};
2604+
2605+
Container.prototype.getNewlineAfter = function(n) {
2606+
var head;
2607+
head = this.getNewlineBefore(n).next;
2608+
while (!(start.type === 'newline' || head === this.end)) {
2609+
head = head.next;
2610+
}
2611+
return head;
2612+
};
2613+
25922614
Container.prototype.getLeadingText = function() {
25932615
if (this.start.next.type === 'text') {
25942616
return this.start.next.value;
@@ -5729,9 +5751,9 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
57295751
LVALUE = ['lvalue'];
57305752
FORBID_ALL = ['forbid-all'];
57315753
PROPERTY_ACCESS = ['prop-access'];
5732-
BLOCK_FUNCTIONS = ['fd', 'bk', 'rt', 'lt', 'slide', 'movexy', 'moveto', 'jump', 'jumpto', 'turnto', 'home', 'pen', 'fill', 'dot', 'box', 'mirror', 'twist', 'scale', 'pause', 'st', 'ht', 'cs', 'cg', 'ct', 'pu', 'pd', 'pe', 'pf', 'play', 'tone', 'silence', 'speed', 'wear', 'drawon', 'label', 'reload', 'see', 'sync', 'send', 'recv', 'click', 'mousemove', 'mouseup', 'mousedown', 'keyup', 'keydown', 'keypress', 'alert', 'prompt', 'done', 'tick'];
5733-
VALUE_FUNCTIONS = ['abs', 'acos', 'asin', 'atan', 'atan2', 'cos', 'sin', 'tan', 'ceil', 'floor', 'round', 'exp', 'ln', 'log10', 'pow', 'sqrt', 'max', 'min', 'random', 'pagexy', 'getxy', 'direction', 'distance', 'shown', 'hidden', 'inside', 'touches', 'within', 'notwithin', 'nearest', 'pressed', 'canvas', 'hsl', 'hsla', 'rgb', 'rgba', 'cell'];
5734-
EITHER_FUNCTIONS = ['button', 'read', 'readstr', 'readnum', 'write', 'table', 'append', 'finish', 'loadscript'];
5754+
BLOCK_FUNCTIONS = ['fd', 'bk', 'rt', 'lt', 'slide', 'move', 'movexy', 'moveto', 'jump', 'jumpxy', 'jumpto', 'turnto', 'home', 'pen', 'fill', 'dot', 'box', 'mirror', 'twist', 'scale', 'pause', 'st', 'ht', 'cs', 'cg', 'ct', 'pu', 'pd', 'pe', 'pf', 'play', 'tone', 'silence', 'speed', 'wear', 'drawon', 'label', 'reload', 'see', 'sync', 'send', 'recv', 'click', 'mousemove', 'mouseup', 'mousedown', 'keyup', 'keydown', 'keypress', 'alert', 'prompt', 'done', 'tick', 'type', 'log'];
5755+
VALUE_FUNCTIONS = ['abs', 'acos', 'asin', 'atan', 'atan2', 'cos', 'sin', 'tan', 'ceil', 'floor', 'round', 'exp', 'ln', 'log10', 'pow', 'sqrt', 'max', 'min', 'random', 'pagexy', 'getxy', 'direction', 'distance', 'shown', 'hidden', 'inside', 'touches', 'within', 'notwithin', 'nearest', 'pressed', 'canvas', 'hsl', 'hsla', 'rgb', 'rgba', 'cell', '$', 'match', 'toString', 'charCodeAt', 'fromCharCode', 'split', 'join', 'sort'];
5756+
EITHER_FUNCTIONS = ['button', 'read', 'readstr', 'readnum', 'write', 'table', 'append', 'finish', 'loadscript', 'text', 'html'];
57355757
STATEMENT_KEYWORDS = ['break', 'continue'];
57365758
OPERATOR_PRECEDENCES = {
57375759
'||': 1,
@@ -9911,12 +9933,23 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
99119933
return this;
99129934
}
99139935

9914-
Editor.prototype.setMode = function(mode) {
9915-
var _ref1;
9916-
this.mode = (_ref1 = modes[this.options.mode = mode]) != null ? _ref1 : null;
9936+
Editor.prototype.setMode = function(mode, modeOptions) {
9937+
var modeClass;
9938+
modeClass = modes[mode];
9939+
if (modeClass) {
9940+
this.options.mode = mode;
9941+
this.mode = new modeClass(modeOptions);
9942+
} else {
9943+
this.options.mode = null;
9944+
this.mode = null;
9945+
}
99179946
return this.setValue(this.getValue());
99189947
};
99199948

9949+
Editor.prototype.getMode = function() {
9950+
return this.options.mode;
9951+
};
9952+
99209953
Editor.prototype.resizeTextMode = function() {
99219954
this.resizeAceElement();
99229955
return this.aceEditor.resize(true);
@@ -10058,7 +10091,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1005810091
}
1005910092
};
1006010093
Editor.prototype.redrawHighlights = function() {
10061-
var id, info, line, path, _ref1, _ref2;
10094+
var id, info, line, path, _ref1, _ref2, _ref3;
1006210095
this.clearHighlightCanvas();
1006310096
_ref1 = this.markedLines;
1006410097
for (line in _ref1) {
@@ -10070,9 +10103,19 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1007010103
delete this.markedLines[line];
1007110104
}
1007210105
}
10073-
_ref2 = this.extraMarks;
10106+
_ref2 = this.markedBlocks;
1007410107
for (id in _ref2) {
1007510108
info = _ref2[id];
10109+
if (this.inTree(info.model)) {
10110+
path = this.getHighlightPath(info.model, info.style);
10111+
path.draw(this.highlightCtx);
10112+
} else {
10113+
delete this.markedLines[id];
10114+
}
10115+
}
10116+
_ref3 = this.extraMarks;
10117+
for (id in _ref3) {
10118+
info = _ref3[id];
1007610119
if (this.inTree(info.model)) {
1007710120
path = this.getHighlightPath(info.model, info.style);
1007810121
path.draw(this.highlightCtx);
@@ -10371,7 +10414,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1037110414
this.highlightCanvas = document.createElement('canvas');
1037210415
this.highlightCanvas.className = 'droplet-highlight-canvas';
1037310416
this.highlightCtx = this.highlightCanvas.getContext('2d');
10374-
document.body.appendChild(this.dragCanvas);
10417+
this.wrapperElement.appendChild(this.dragCanvas);
1037510418
return this.dropletElement.appendChild(this.highlightCanvas);
1037610419
});
1037710420
Editor.prototype.clearHighlightCanvas = function() {
@@ -10413,6 +10456,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1041310456
this.dumpNodeForDebug(hitTestResult, line);
1041410457
}
1041510458
if (hitTestResult != null) {
10459+
this.setTextInputFocus(null);
1041610460
this.clickedBlock = hitTestResult;
1041710461
this.clickedBlockIsPaletteBlock = false;
1041810462
this.moveCursorTo(this.clickedBlock.start.next);
@@ -10520,11 +10564,13 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1052010564
}
1052110565
};
1052210566
hook('mousemove', 0, function(point, event, state) {
10523-
var best, head, mainPoint, min, palettePoint, position, testPoints, _ref1, _ref2, _ref3;
10567+
var best, head, mainPoint, min, palettePoint, position, rect, testPoints, _ref1, _ref2, _ref3;
1052410568
if (this.draggingBlock != null) {
1052510569
position = new this.draw.Point(point.x + this.draggingOffset.x, point.y + this.draggingOffset.y);
10526-
this.dragCanvas.style.top = "" + (position.y + window.pageYOffset) + "px";
10527-
this.dragCanvas.style.left = "" + (position.x + window.pageXOffset) + "px";
10570+
rect = this.wrapperElement.getBoundingClientRect();
10571+
console.log(position.x - this.wrapperElement.getBoundingClientRect().left, position.y - this.wrapperElement.getBoundingClientRect().top);
10572+
this.dragCanvas.style.top = "" + (position.y - rect.top) + "px";
10573+
this.dragCanvas.style.left = "" + (position.x - rect.left) + "px";
1052810574
mainPoint = this.trackerPointToMain(position);
1052910575
best = null;
1053010576
min = Infinity;
@@ -10765,6 +10811,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1076510811
record = _ref1[i];
1076610812
hitTestResult = this.hitTest(this.trackerPointToMain(point), record.block);
1076710813
if (hitTestResult != null) {
10814+
this.setTextInputFocus(null);
1076810815
this.clickedBlock = record.block;
1076910816
this.clickedPoint = point;
1077010817
state.consumedHitTest = true;
@@ -10903,6 +10950,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1090310950
block = _ref3[_i];
1090410951
hitTestResult = this.hitTest(palettePoint, block);
1090510952
if (hitTestResult != null) {
10953+
this.setTextInputFocus(null);
1090610954
this.clickedBlock = block;
1090710955
this.clickedPoint = point;
1090810956
this.clickedBlockIsPaletteBlock = true;
@@ -11036,9 +11084,18 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1103611084
var event, _i, _len, _ref1, _results;
1103711085
this.hiddenInput = document.createElement('textarea');
1103811086
this.hiddenInput.className = 'droplet-hidden-input';
11087+
this.hiddenInput.addEventListener('focus', (function(_this) {
11088+
return function() {
11089+
var bounds;
11090+
if (_this.textFocus != null) {
11091+
bounds = _this.view.getViewNodeFor(_this.textFocus).bounds[0];
11092+
_this.hiddenInput.style.left = (bounds.x + _this.mainCanvas.offsetLeft) + 'px';
11093+
return _this.hiddenInput.style.top = bounds.y + 'px';
11094+
}
11095+
};
11096+
})(this));
1103911097
this.dropletElement.appendChild(this.hiddenInput);
1104011098
this.textFocus = null;
11041-
this.textFocus = null;
1104211099
this.textInputAnchor = null;
1104311100
this.textInputSelecting = false;
1104411101
this.oldFocusValue = null;
@@ -11304,7 +11361,6 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1130411361
hitTestResult = this.hitTestTextInput(mainPoint, this.tree);
1130511362
}
1130611363
if (hitTestResult != null) {
11307-
this.hiddenInput.focus();
1130811364
if (hitTestResult !== this.textFocus) {
1130911365
this.setTextInputFocus(hitTestResult);
1131011366
this.redrawMain();
@@ -11314,6 +11370,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1131411370
this.redrawTextInput();
1131511371
this.textInputSelecting = true;
1131611372
}
11373+
this.hiddenInput.focus();
1131711374
return state.consumedHitTest = true;
1131811375
}
1131911376
});
@@ -11578,6 +11635,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1157811635
return;
1157911636
}
1158011637
if ((this.lassoSegment != null) && (this.hitTest(this.trackerPointToMain(point), this.lassoSegment) != null)) {
11638+
this.setTextInputFocus(null);
1158111639
this.clickedBlock = this.lassoSegment;
1158211640
this.clickedBlockIsPaletteBlock = false;
1158311641
this.clickedPoint = point;
@@ -11940,7 +11998,6 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1194011998
this.addMicroUndoOperation(new PickUpOperation(blockEnd.container.parent));
1194111999
this.spliceOut(blockEnd.container.parent);
1194212000
this.moveCursorTo(before);
11943-
console.log('moving cursor to', before);
1194412001
return this.redrawMain();
1194512002
}
1194612003
};
@@ -12122,8 +12179,8 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1212212179
head = this.tree.start;
1212312180
aceSession = this.aceEditor.session;
1212412181
state = {
12125-
x: (this.aceEditor.container.getBoundingClientRect().left - getOffsetLeft(this.aceElement) + this.aceEditor.renderer.$gutterLayer.gutterWidth) - this.gutter.offsetWidth + 5,
12126-
y: (this.aceEditor.container.getBoundingClientRect().top - getOffsetTop(this.aceElement)) - aceSession.getScrollTop(),
12182+
x: (this.aceEditor.container.getBoundingClientRect().left - this.aceElement.getBoundingClientRect().left + this.aceEditor.renderer.$gutterLayer.gutterWidth) - this.gutter.offsetWidth + 5,
12183+
y: (this.aceEditor.container.getBoundingClientRect().top - this.aceElement.getBoundingClientRect().top) - aceSession.getScrollTop(),
1212712184
indent: 0,
1212812185
lineHeight: this.aceEditor.renderer.layerConfig.lineHeight,
1212912186
leftEdge: (this.aceEditor.container.getBoundingClientRect().left - getOffsetLeft(this.aceElement) + this.aceEditor.renderer.$gutterLayer.gutterWidth) - this.gutter.offsetWidth + 5
@@ -12565,6 +12622,8 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1256512622
};
1256612623
hook('populate', 0, function() {
1256712624
this.markedLines = {};
12625+
this.markedBlocks = {};
12626+
this.nextMarkedBlockId = 0;
1256812627
return this.extraMarks = {};
1256912628
});
1257012629
Editor.prototype.getHighlightPath = function(model, style) {
@@ -12586,14 +12645,45 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
1258612645
style: style
1258712646
};
1258812647
}
12589-
return this.redrawMain();
12648+
return this.redrawHighlights();
12649+
};
12650+
Editor.prototype.mark = function(line, col, style) {
12651+
var chars, head, key, lineStart, parent;
12652+
lineStart = this.tree.getNewlineBefore(line);
12653+
chars = 0;
12654+
parent = lineStart.parent;
12655+
while (parent !== this.tree) {
12656+
if (parent.type === 'indent') {
12657+
chars += parent.prefix.length;
12658+
}
12659+
parent = parent.parent;
12660+
}
12661+
head = lineStart.next;
12662+
while (!((chars >= col && head.type === 'blockStart') || head.type === 'newline')) {
12663+
chars += head.stringify().length;
12664+
head = head.next;
12665+
}
12666+
if (head.type === 'newline') {
12667+
return false;
12668+
}
12669+
key = this.nextMarkedBlockId++;
12670+
this.markedBlocks[key] = {
12671+
model: head.container,
12672+
style: style
12673+
};
12674+
this.redrawHighlights();
12675+
return key;
12676+
};
12677+
Editor.prototype.unmark = function(key) {
12678+
delete this.markedBlocks[key];
12679+
return true;
1259012680
};
1259112681
Editor.prototype.unmarkLine = function(line) {
1259212682
delete this.markedLines[line];
1259312683
return this.redrawMain();
1259412684
};
12595-
Editor.prototype.clearLineMarks = function(tag) {
12596-
this.markedLines = {};
12685+
Editor.prototype.clearLineMarks = function() {
12686+
this.markedLines = this.markedBlocks = {};
1259712687
return this.redrawMain();
1259812688
};
1259912689
hook('populate', 0, function() {

blockly/lib/droplet/droplet-full.min.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blockly/lib/droplet/droplet-full.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)