@@ -2589,6 +2589,28 @@ QUAD.init = function (args) {
2589
2589
return this.notifyChange();
2590
2590
};
2591
2591
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
+
2592
2614
Container.prototype.getLeadingText = function() {
2593
2615
if (this.start.next.type === 'text') {
2594
2616
return this.start.next.value;
@@ -5729,9 +5751,9 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
5729
5751
LVALUE = ['lvalue'];
5730
5752
FORBID_ALL = ['forbid-all'];
5731
5753
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' ];
5735
5757
STATEMENT_KEYWORDS = ['break', 'continue'];
5736
5758
OPERATOR_PRECEDENCES = {
5737
5759
'||': 1,
@@ -9911,12 +9933,23 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
9911
9933
return this;
9912
9934
}
9913
9935
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
+ }
9917
9946
return this.setValue(this.getValue());
9918
9947
};
9919
9948
9949
+ Editor.prototype.getMode = function() {
9950
+ return this.options.mode;
9951
+ };
9952
+
9920
9953
Editor.prototype.resizeTextMode = function() {
9921
9954
this.resizeAceElement();
9922
9955
return this.aceEditor.resize(true);
@@ -10058,7 +10091,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
10058
10091
}
10059
10092
};
10060
10093
Editor.prototype.redrawHighlights = function() {
10061
- var id, info, line, path, _ref1, _ref2;
10094
+ var id, info, line, path, _ref1, _ref2, _ref3 ;
10062
10095
this.clearHighlightCanvas();
10063
10096
_ref1 = this.markedLines;
10064
10097
for (line in _ref1) {
@@ -10070,9 +10103,19 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
10070
10103
delete this.markedLines[line];
10071
10104
}
10072
10105
}
10073
- _ref2 = this.extraMarks ;
10106
+ _ref2 = this.markedBlocks ;
10074
10107
for (id in _ref2) {
10075
10108
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];
10076
10119
if (this.inTree(info.model)) {
10077
10120
path = this.getHighlightPath(info.model, info.style);
10078
10121
path.draw(this.highlightCtx);
@@ -10371,7 +10414,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
10371
10414
this.highlightCanvas = document.createElement('canvas');
10372
10415
this.highlightCanvas.className = 'droplet-highlight-canvas';
10373
10416
this.highlightCtx = this.highlightCanvas.getContext('2d');
10374
- document.body .appendChild(this.dragCanvas);
10417
+ this.wrapperElement .appendChild(this.dragCanvas);
10375
10418
return this.dropletElement.appendChild(this.highlightCanvas);
10376
10419
});
10377
10420
Editor.prototype.clearHighlightCanvas = function() {
@@ -10413,6 +10456,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
10413
10456
this.dumpNodeForDebug(hitTestResult, line);
10414
10457
}
10415
10458
if (hitTestResult != null) {
10459
+ this.setTextInputFocus(null);
10416
10460
this.clickedBlock = hitTestResult;
10417
10461
this.clickedBlockIsPaletteBlock = false;
10418
10462
this.moveCursorTo(this.clickedBlock.start.next);
@@ -10520,11 +10564,13 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
10520
10564
}
10521
10565
};
10522
10566
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;
10524
10568
if (this.draggingBlock != null) {
10525
10569
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";
10528
10574
mainPoint = this.trackerPointToMain(position);
10529
10575
best = null;
10530
10576
min = Infinity;
@@ -10765,6 +10811,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
10765
10811
record = _ref1[i];
10766
10812
hitTestResult = this.hitTest(this.trackerPointToMain(point), record.block);
10767
10813
if (hitTestResult != null) {
10814
+ this.setTextInputFocus(null);
10768
10815
this.clickedBlock = record.block;
10769
10816
this.clickedPoint = point;
10770
10817
state.consumedHitTest = true;
@@ -10903,6 +10950,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
10903
10950
block = _ref3[_i];
10904
10951
hitTestResult = this.hitTest(palettePoint, block);
10905
10952
if (hitTestResult != null) {
10953
+ this.setTextInputFocus(null);
10906
10954
this.clickedBlock = block;
10907
10955
this.clickedPoint = point;
10908
10956
this.clickedBlockIsPaletteBlock = true;
@@ -11036,9 +11084,18 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
11036
11084
var event, _i, _len, _ref1, _results;
11037
11085
this.hiddenInput = document.createElement('textarea');
11038
11086
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));
11039
11097
this.dropletElement.appendChild(this.hiddenInput);
11040
11098
this.textFocus = null;
11041
- this.textFocus = null;
11042
11099
this.textInputAnchor = null;
11043
11100
this.textInputSelecting = false;
11044
11101
this.oldFocusValue = null;
@@ -11304,7 +11361,6 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
11304
11361
hitTestResult = this.hitTestTextInput(mainPoint, this.tree);
11305
11362
}
11306
11363
if (hitTestResult != null) {
11307
- this.hiddenInput.focus();
11308
11364
if (hitTestResult !== this.textFocus) {
11309
11365
this.setTextInputFocus(hitTestResult);
11310
11366
this.redrawMain();
@@ -11314,6 +11370,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
11314
11370
this.redrawTextInput();
11315
11371
this.textInputSelecting = true;
11316
11372
}
11373
+ this.hiddenInput.focus();
11317
11374
return state.consumedHitTest = true;
11318
11375
}
11319
11376
});
@@ -11578,6 +11635,7 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
11578
11635
return;
11579
11636
}
11580
11637
if ((this.lassoSegment != null) && (this.hitTest(this.trackerPointToMain(point), this.lassoSegment) != null)) {
11638
+ this.setTextInputFocus(null);
11581
11639
this.clickedBlock = this.lassoSegment;
11582
11640
this.clickedBlockIsPaletteBlock = false;
11583
11641
this.clickedPoint = point;
@@ -11940,7 +11998,6 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
11940
11998
this.addMicroUndoOperation(new PickUpOperation(blockEnd.container.parent));
11941
11999
this.spliceOut(blockEnd.container.parent);
11942
12000
this.moveCursorTo(before);
11943
- console.log('moving cursor to', before);
11944
12001
return this.redrawMain();
11945
12002
}
11946
12003
};
@@ -12122,8 +12179,8 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
12122
12179
head = this.tree.start;
12123
12180
aceSession = this.aceEditor.session;
12124
12181
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(),
12127
12184
indent: 0,
12128
12185
lineHeight: this.aceEditor.renderer.layerConfig.lineHeight,
12129
12186
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
12565
12622
};
12566
12623
hook('populate', 0, function() {
12567
12624
this.markedLines = {};
12625
+ this.markedBlocks = {};
12626
+ this.nextMarkedBlockId = 0;
12568
12627
return this.extraMarks = {};
12569
12628
});
12570
12629
Editor.prototype.getHighlightPath = function(model, style) {
@@ -12586,14 +12645,45 @@ if(i=this.variable instanceof Z){if(this.variable.isArray()||this.variable.isObj
12586
12645
style: style
12587
12646
};
12588
12647
}
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;
12590
12680
};
12591
12681
Editor.prototype.unmarkLine = function(line) {
12592
12682
delete this.markedLines[line];
12593
12683
return this.redrawMain();
12594
12684
};
12595
- Editor.prototype.clearLineMarks = function(tag ) {
12596
- this.markedLines = {};
12685
+ Editor.prototype.clearLineMarks = function() {
12686
+ this.markedLines = this.markedBlocks = {};
12597
12687
return this.redrawMain();
12598
12688
};
12599
12689
hook('populate', 0, function() {
0 commit comments