-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.12.diff
More file actions
811 lines (767 loc) · 31.9 KB
/
5.12.diff
File metadata and controls
811 lines (767 loc) · 31.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
diff --git a/lib/codemirror.js b/lib/codemirror.js
old mode 100644
new mode 100755
index f7718804..d3a4b1d2
--- a/lib/codemirror.js
+++ b/lib/codemirror.js
@@ -6,6 +6,7 @@
//
// You can find some technical background for some of the code below
// at http://marijnhaverbeke.nl/blog/#cm-internals .
+// gitstalled?
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
@@ -127,6 +128,12 @@
display.lineDiv.style.textRendering = "auto";
}
+ // HACK
+ CodeMirror.mobile = mobile;
+ CodeMirror.mac = mac;
+ CodeMirror.windows = windows;
+ // END HACK
+
// DISPLAY CONSTRUCTOR
// The display handles the DOM integration, both for input reading
@@ -208,7 +215,7 @@
// this is false.
d.alignWidgets = false;
- d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
+ d.cachedCharWidth = d.cachedSpaceWidth = d.cachedTextHeight = d.cachedPaddingH = null; // HACK
// Tracks the maximum line length so that the horizontal scrollbar
// can be kept static when scrolling.
@@ -641,6 +648,8 @@
this.viewport = viewport;
// Store some values that we'll need later (but don't want to force a relayout for)
this.visible = visibleLines(display, cm.doc, viewport);
+ // HACK
+ this.positionLineWidgets = display.positionLineWidgets = [];
this.editorIsHidden = !display.wrapper.offsetWidth;
this.wrapperHeight = display.wrapper.clientHeight;
this.wrapperWidth = display.wrapper.clientWidth;
@@ -740,6 +749,33 @@
startWorker(cm, 400);
}
+ // HACK: JESSE
+ // calc positions in on step to avoid relayouts
+ var positionedWidgets = [], widgetWrapper;
+ var positionLineWidgets = display.positionLineWidgets || [];
+
+ for (var i = 0; i < positionLineWidgets.length; i++) {
+ widgetWrapper = positionLineWidgets[i].widget.node.parentNode;
+ positionedWidgets.push({
+ widgetWrapper: widgetWrapper,
+ position: positionLineWidgets[i].widget.positionWidget(widgetWrapper.offsetWidth, widgetWrapper.offsetHeight)
+ });
+ }
+
+ // apply positions in next step
+ for (var i = 0; i < positionedWidgets.length; i++) {
+ var position = positionedWidgets[i].position;
+ widgetWrapper = positionedWidgets[i].widgetWrapper;
+ if (position.top) widgetWrapper.style.top = position.top;
+ if (position.bottom) widgetWrapper.style.bottom = position.bottom;
+ if (position.left) widgetWrapper.style.left = position.left;
+ if (position.right) widgetWrapper.style.right = position.right;
+ if (position.marginLeft) widgetWrapper.style.marginLeft = position.marginLeft;
+ if (position.marginRight) widgetWrapper.style.marginRight = position.marginRight;
+ }
+
+ display.positionLineWidgets = null;
+ // END HACK
display.updateLineNumbers = null;
return true;
@@ -790,41 +826,63 @@
cm.display.sizer.style.minHeight = measure.docHeight + "px";
cm.display.heightForcer.style.top = measure.docHeight + "px";
cm.display.gutters.style.height = Math.max(measure.docHeight + cm.display.barHeight + scrollGap(cm),
- measure.clientHeight) + "px";
+ measure.clientHeight) + "px";
}
+ // HACK: Jesse
+ function updateHeightInViewport(cm, view, height) {
+ var display = cm.display;
+ var diff = view.line.height - height;
+ if (height < 2) height = textHeight(display);
+ if (diff > .001 || diff < -.001) {
+ updateLineHeight(view.line, height);
+ updateWidgetHeight(view.line);
+ if (view.rest) for (var j = 0; j < view.rest.length; j++)
+ updateWidgetHeight(view.rest[j]);
+ }
+ }
+ // END HACK
+
// Read the actual heights of the rendered lines, and update their
// stored heights to match.
function updateHeightsInViewport(cm) {
var display = cm.display;
var prevBottom = display.lineDiv.offsetTop;
+ // HACK
+ var prevHeight = 0;
+ var prev;
+
for (var i = 0; i < display.view.length; i++) {
- var cur = display.view[i], height;
+ var cur = display.view[i];
if (cur.hidden) continue;
- if (ie && ie_version < 8) {
- var bot = cur.node.offsetTop + cur.node.offsetHeight;
- height = bot - prevBottom;
- prevBottom = bot;
- } else {
- var box = cur.node.getBoundingClientRect();
- height = box.bottom - box.top;
- }
- var diff = cur.line.height - height;
- if (height < 2) height = textHeight(display);
- if (diff > .001 || diff < -.001) {
- updateLineHeight(cur.line, height);
- updateWidgetHeight(cur.line);
- if (cur.rest) for (var j = 0; j < cur.rest.length; j++)
- updateWidgetHeight(cur.rest[j]);
+ var offsetTop = cur.node.offsetTop;
+ var offsetHeight = cur.node.offsetHeight;
+ var offsetBottom = offsetTop + offsetHeight;
+ var gap = (offsetTop - prevBottom);
+ if (gap) {
+ updateHeightInViewport(cm, prev, prev.line.height + gap);
}
+ updateHeightInViewport(cm, cur, offsetHeight);
+ prevBottom = offsetBottom;
+ prevHeight = offsetHeight;
+ prev = cur;
}
+ // END HACK
}
// Read and store the height of line widgets associated with the
// given line.
function updateWidgetHeight(line) {
- if (line.widgets) for (var i = 0; i < line.widgets.length; ++i)
- line.widgets[i].height = line.widgets[i].node.parentNode.offsetHeight;
+ // HACK
+ if (line.widgets) for (var i = 0; i < line.widgets.length; ++i) {
+ var each = line.widgets[i];
+ if (each.overlay) {
+ each.height = 0;
+ } else {
+ each.height = each.node.offsetHeight;
+ }
+ }
+ // END HACK
}
// Do a bulk-read of the DOM positions and sizes needed to draw the
@@ -898,7 +956,7 @@
if (type == "text") updateLineText(cm, lineView);
else if (type == "gutter") updateLineGutter(cm, lineView, lineN, dims);
else if (type == "class") updateLineClasses(lineView);
- else if (type == "widget") updateLineWidgets(cm, lineView, dims);
+ else if (type == "widget") updateLineWidgets(cm, lineView, dims); // HACK
}
lineView.changes = null;
}
@@ -949,7 +1007,8 @@
if (lineView.text == lineView.node) lineView.node = built.pre;
lineView.text.parentNode.replaceChild(built.pre, lineView.text);
lineView.text = built.pre;
- if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
+ if (built.wrapClass != lineView.wrapClass || built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) { // HACK
+ lineView.wrapClass = built.wrapClass; // HACK
lineView.bgClass = built.bgClass;
lineView.textClass = built.textClass;
updateLineClasses(lineView);
@@ -960,8 +1019,10 @@
function updateLineClasses(lineView) {
updateLineBackground(lineView);
- if (lineView.line.wrapClass)
- ensureLineWrapped(lineView).className = lineView.line.wrapClass;
+
+ var wrapClass = lineView.wrapClass ? lineView.wrapClass + " " + (lineView.line.wrapClass || "") : lineView.line.wrapClass; // HACK
+ if (wrapClass) // HACK
+ ensureLineWrapped(lineView).className = wrapClass; // HACK
else if (lineView.node != lineView.text)
lineView.node.className = "";
var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
@@ -1008,54 +1069,62 @@
}
}
- function updateLineWidgets(cm, lineView, dims) {
+ function updateLineWidgets(cm, lineView, dims) { // HACK
if (lineView.alignable) lineView.alignable = null;
for (var node = lineView.node.firstChild, next; node; node = next) {
var next = node.nextSibling;
if (node.className == "CodeMirror-linewidget")
lineView.node.removeChild(node);
}
- insertLineWidgets(cm, lineView, dims);
+ insertLineWidgets(cm, lineView, dims); // HACK
}
// Build a line's DOM representation from scratch
function buildLineElement(cm, lineView, lineN, dims) {
var built = getLineContent(cm, lineView);
lineView.text = lineView.node = built.pre;
+ if (built.wrapClass) lineView.wrapClass = built.wrapClass; // HACK
if (built.bgClass) lineView.bgClass = built.bgClass;
if (built.textClass) lineView.textClass = built.textClass;
-
updateLineClasses(lineView);
updateLineGutter(cm, lineView, lineN, dims);
- insertLineWidgets(cm, lineView, dims);
+ insertLineWidgets(cm, lineView, dims); // HACK
return lineView.node;
}
// A lineView may contain multiple logical lines (when merged by
// collapsed spans). The widgets for all of them need to be drawn.
- function insertLineWidgets(cm, lineView, dims) {
- insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);
+ function insertLineWidgets(cm, lineView, dims) { // HACK
+ insertLineWidgetsFor(cm, lineView.line, lineView, dims, true, false); // HACK
if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
- insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false);
+ insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false, true); // HACK
}
- function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
+ function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove, isHidden) { // HACK
if (!line.widgets) return;
var wrap = ensureLineWrapped(lineView);
for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
- var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
+ // HACK
+ var widget = ws[i];
+ if (isHidden && !widget.showIfHidden)
+ continue;
+ // END HACK
+
+ var node = elt("div", [widget.node], "CodeMirror-linewidget"); // HACK
if (!widget.handleMouseEvents) node.setAttribute("cm-ignore-events", "true");
- positionLineWidget(widget, node, lineView, dims);
+ positionLineWidget(cm, widget, node, lineView, dims); // HACK
cm.display.input.setUneditable(node);
if (allowAbove && widget.above)
wrap.insertBefore(node, lineView.gutter || lineView.text);
- else
+ else if (widget.overlay) { // HACK
+ wrap.insertBefore(node, lineView.text); // HACK
+ } else // HACK
wrap.appendChild(node);
signalLater(widget, "redraw");
}
}
- function positionLineWidget(widget, node, lineView, dims) {
+ function positionLineWidget(cm, widget, node, lineView, dims) { // HACK
if (widget.noHScroll) {
(lineView.alignable || (lineView.alignable = [])).push(node);
var width = dims.wrapperWidth;
@@ -1071,6 +1140,15 @@
node.style.position = "relative";
if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px";
}
+ // HACK
+ if (widget.overlay) {
+ node.style.position = 'absolute';
+ }
+ if (widget.positionWidget && cm.display.positionLineWidgets) cm.display.positionLineWidgets.push({
+ widget : widget,
+ node : node
+ });
+ // END HACK
}
// POSITION OBJECT
@@ -1252,14 +1330,18 @@
});
on(te, "paste", function(e) {
- if (signalDOMEvent(cm, e) || handlePaste(e, cm)) return
+ // HACK: JESSE
+ if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return;
+ if (handlePaste(e, cm)) return true;
cm.state.pasteIncoming = true;
input.fastPoll();
});
function prepareCopyCut(e) {
- if (signalDOMEvent(cm, e)) return
+ // HACK: JESSE
+ if (signalDOMEvent(cm, e) || eventInWidget(d,e)) return;
+
if (cm.somethingSelected()) {
lastCopied = cm.getSelections();
if (input.inaccurateSelection) {
@@ -1287,7 +1369,7 @@
on(te, "copy", prepareCopyCut);
on(display.scroller, "paste", function(e) {
- if (eventInWidget(display, e) || signalDOMEvent(cm, e)) return;
+ if (signalDOMEvent(cm,e) || eventInWidget(display, e)) return; // HACK: JESSE
cm.state.pasteIncoming = true;
input.focus();
});
@@ -1298,6 +1380,8 @@
});
on(te, "compositionstart", function() {
+ cm.options.moveInputWithCursor = true; // HACK
+
var start = cm.getCursor("from");
if (input.composing) input.composing.range.clear()
input.composing = {
@@ -1310,6 +1394,7 @@
input.poll();
input.composing.range.clear();
input.composing = null;
+ cm.options.moveInputWithCursor = false; // HACK
}
});
},
@@ -1479,8 +1564,10 @@
// Reset the current text selection only if the click is done outside of the selection
// and 'resetSelectionOnContextMenu' option is true.
+ // HACK: Jesse
+ // or selection is empty, and 'resetSelectionOnContextMenu' option is true
var reset = cm.options.resetSelectionOnContextMenu;
- if (reset && cm.doc.sel.contains(pos) == -1)
+ if (reset && (!cm.doc.somethingSelected() || cm.doc.sel.contains(pos) == -1))
operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll);
var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText;
@@ -2398,19 +2485,44 @@
var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
var singleVLine = visualLine(fromLine) == visualLine(toLine);
var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
- var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
- if (singleVLine) {
- if (leftEnd.top < rightStart.top - 2) {
- add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
- add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
- } else {
- add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
+ // HACK
+ var fromArg = singleVLine ? 0 : null;
+ var toArg = sTo.ch;
+ var rightStart;
+
+ if (fromArg === null && toArg === 0) {
+ rightStart = charCoords(cm, Pos(sTo.line, sTo.ch), "div");
+ } else {
+ // END HACK
+ var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
+ if (singleVLine) {
+ if (leftEnd.top < rightStart.top - 2) {
+ add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
+ add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
+ } else {
+ add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
+ }
}
- }
+ } // HACK
if (leftEnd.bottom < rightStart.top)
- add(leftSide, leftEnd.bottom, null, rightStart.top);
+ add(leftSide, leftEnd.bottom, null, rightStart.top);
}
+ // HACK (Disabled)
+ //Progress on drawing selection rects.
+ //It's fast enough, but reported in wrong coord system.
+ /*var fragment = document.createDocumentFragment();
+ for (var i = 0; i < display.view.length; i++) {
+ var cur = display.view[i];
+ var offsetTop = 0;//cur.text.offsetTop;
+ var offsetLeft = 0;//cur.text.offsetLeft;
+ var rects = cur.text.firstChild.getClientRects();
+ for (var j = 0; j < rects.length; j++) {
+ var r = rects[j];
+ add(r.left - offsetLeft, r.top - offsetTop, r.width, r.bottom - offsetTop);
+ }
+ }*/
+
output.appendChild(fragment);
}
@@ -2701,6 +2813,20 @@
rect = nullRect;
} else {
rect = range(node, start, end).getBoundingClientRect() || nullRect;
+ // HACK:jesse
+ if (rect.width === 0) {
+ // Sometimes, such as when a space is at the end of a
+ // line that wraps there will be two zero width bounding rects. And
+ // when you call getBoundingClientRect() it returns a 0,0,0,0 rect.
+ // Can't seem to reproduce in strait CM, might be due to margin
+ // support in my modified version? Anyway this seems to fix.
+ var rects = range(node, start, end).getClientRects();
+ if (rects.length)
+ rect = rects[bias == "right" ? rects.length - 1 : 0];
+ else
+ rect = nullRect;
+ }
+ // END HACK
}
if (rect.left || rect.right || start == 0) break;
end = start;
@@ -2736,6 +2862,15 @@
if (!rect.left && !rect.right) result.bogus = true;
if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
+ // HACK: Jesse
+ var left = prepared.view.text.offsetLeft;
+ if (left) {
+ // hack so that possible to set margins in renderline
+ result.left += left;
+ result.right += left;
+ }
+ // END HACK
+
return result;
}
@@ -2769,7 +2904,7 @@
function clearCaches(cm) {
clearLineMeasurementCache(cm);
- cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
+ cm.display.cachedCharWidth = cm.display.cachedSpaceWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null; // HACK (cm.display.cachedSpaceWidth)
if (!cm.options.lineWrapping) cm.display.maxLineChanged = true;
cm.display.lineNumChars = null;
}
@@ -2976,6 +3111,19 @@
return width || 10;
}
+ // HACK: JESSE
+ // Compute the default space width.
+ function spaceWidth(display) {
+ if (display.cachedSpaceWidth != null) return display.cachedSpaceWidth;
+ var anchor = elt("span", " ");
+ var pre = elt("pre", [anchor]);
+ removeChildrenAndAdd(display.measure, pre);
+ var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
+ if (width > 2) display.cachedSpaceWidth = width;
+ return width || 10;
+ }
+ // END HACK
+
// OPERATIONS
// Operations are used to wrap a series of changes to the editor
@@ -3034,6 +3182,7 @@
// Finish an operation, updating the display and signalling delayed events
function endOperation(cm) {
+ signal(cm, "willEndOperation", cm); // HACK: JESSE
var op = cm.curOp, group = op.ownsGroup;
if (!group) return;
@@ -3148,8 +3297,9 @@
}
// If we need to scroll a specific position into view, do so.
if (op.scrollToPos) {
- var coords = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
- clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
+ // HACK: Jesse, Add Top and Bottom Margins
+ var coords = scrollPosIntoView(cm, clipPos(cm.doc, op.scrollToPos.from),
+ clipPos(cm.doc, op.scrollToPos.to), op.scrollToPos.topMargin, op.scrollToPos.bottomMargin);
if (op.scrollToPos.isCursor && cm.state.focused) maybeScrollWindow(cm, coords);
}
@@ -3508,6 +3658,8 @@
if (!value != !wasOn) {
var funcs = cm.display.dragFunctions;
var toggle = value ? on : off;
+ // NOT HACK: JESSE (If Drag bugs encountered, revisit this area)
+ // Original hack had drag, dragend events added to this list
toggle(cm.display.scroller, "dragstart", funcs.start);
toggle(cm.display.scroller, "dragenter", funcs.enter);
toggle(cm.display.scroller, "dragover", funcs.over);
@@ -3843,13 +3995,22 @@
clearDragCursor(cm);
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
return;
+
e_preventDefault(e);
if (ie) lastDrop = +new Date;
var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
if (!pos || cm.isReadOnly()) return;
+
+ // HACK: JESSE
+ var textForDropEvent = null;
+ if (cm.options.textForDropEvent) {
+ textForDropEvent = cm.options.textForDropEvent(e);
+ }
+ // END HACK
+
// Might be a file drop, in which case we simply extract the text
// and insert it.
- if (files && files.length && window.FileReader && window.File) {
+ if (textForDropEvent === null && files && files.length && window.FileReader && window.File) { // HACK:JESSE
var n = files.length, text = Array(n), read = 0;
var loadFile = function(file, i) {
if (cm.options.allowDropFileTypes &&
@@ -3863,9 +4024,9 @@
text[i] = content;
if (++read == n) {
pos = clipPos(cm.doc, pos);
- var change = {from: pos, to: pos,
+ var change = {from: pos, to: pos, // HACK: JESSE
text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())),
- origin: "paste"};
+ origin: "+paste"};
makeChange(cm.doc, change);
setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)));
}
@@ -3882,14 +4043,17 @@
return;
}
try {
- var text = e.dataTransfer.getData("Text");
+ var text = textForDropEvent ? textForDropEvent : e.dataTransfer.getData("Text"); // HACK
if (text) {
if (cm.state.draggingText && !(mac ? e.altKey : e.ctrlKey))
var selected = cm.listSelections();
setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
- if (selected) for (var i = 0; i < selected.length; ++i)
- replaceRange(cm.doc, "", selected[i].anchor, selected[i].head, "drag");
- cm.replaceSelection(text, "around", "paste");
+ if (!textForDropEvent) { // HACK
+ if (selected) // HACK
+ for (var i = 0; i < selected.length; ++i)
+ replaceRange(cm.doc, "", selected[i].anchor, selected[i].head, "drag");
+ }
+ cm.replaceSelection(text, "around", "+paste"); // HACK
cm.display.input.focus();
}
}
@@ -4508,6 +4672,11 @@
if (doc.cm) makeChangeSingleDocInEditor(doc.cm, change, spans);
else updateDoc(doc, change, spans);
setSelectionNoUndo(doc, selAfter, sel_dontScroll);
+
+ // HACK: JESSE
+ if (doc.cm && hasHandler(doc.cm, "justChanged")) {
+ signal(doc.cm, "justChanged", doc.cm, change);
+ }
}
// Handle the interaction of a change to a document with the editor
@@ -4602,15 +4771,16 @@
// Scroll a given position into view (immediately), verifying that
// it actually became visible (as line heights are accurately
// measured, the position of something may 'drift' during drawing).
- function scrollPosIntoView(cm, pos, end, margin) {
- if (margin == null) margin = 0;
+ function scrollPosIntoView(cm, pos, end, topMargin, bottomMargin) { // HACK
+ if (topMargin == null) topMargin = 0;
+ if (bottomMargin == null) bottomMargin = 0; // HACK
for (var limit = 0; limit < 5; limit++) {
var changed = false, coords = cursorCoords(cm, pos);
var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
- Math.min(coords.top, endCoords.top) - margin,
+ Math.min(coords.top, endCoords.top) - topMargin, // HACK
Math.max(coords.left, endCoords.left),
- Math.max(coords.bottom, endCoords.bottom) + margin);
+ Math.max(coords.bottom, endCoords.bottom) + bottomMargin); // HACK
var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
if (scrollPos.scrollTop != null) {
setScrollTop(cm, scrollPos.scrollTop);
@@ -4696,9 +4866,9 @@
cm.curOp.scrollToPos = null;
var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to);
var sPos = calculateScrollPos(cm, Math.min(from.left, to.left),
- Math.min(from.top, to.top) - range.margin,
+ Math.min(from.top, to.top) - range.topMargin, // HACK
Math.max(from.right, to.right),
- Math.max(from.bottom, to.bottom) + range.margin);
+ Math.max(from.bottom, to.bottom) + range.bottomMargin); // HACK
cm.scrollTo(sPos.scrollLeft, sPos.scrollTop);
}
}
@@ -5072,6 +5242,7 @@
defaultTextHeight: function() { return textHeight(this.display); },
defaultCharWidth: function() { return charWidth(this.display); },
+ defaultSpaceWidth: function() { return spaceWidth(this.display); }, // HACK: JESSE
setGutterMarker: methodOp(function(line, gutterID, value) {
return changeLine(this.doc, line, "gutter", function(line) {
@@ -5262,26 +5433,27 @@
clientHeight: displayHeight(this), clientWidth: displayWidth(this)};
},
- scrollIntoView: methodOp(function(range, margin) {
+ scrollIntoView: methodOp(function(range, topMargin, bottomMargin) { // HACK: JESSE TOP BOTTOM MARGINS
if (range == null) {
range = {from: this.doc.sel.primary().head, to: null};
- if (margin == null) margin = this.options.cursorScrollMargin;
+ if (topMargin == null) topMargin = this.options.cursorScrollMargin; // HACK
} else if (typeof range == "number") {
range = {from: Pos(range, 0), to: null};
} else if (range.from == null) {
range = {from: range, to: null};
}
if (!range.to) range.to = range.from;
- range.margin = margin || 0;
+ range.topMargin = topMargin || 0; // HACK
+ range.bottomMargin = bottomMargin === undefined ? range.topMargin : bottomMargin; // HACK
if (range.from.line != null) {
resolveScrollToPos(this);
this.curOp.scrollToPos = range;
} else {
var sPos = calculateScrollPos(this, Math.min(range.from.left, range.to.left),
- Math.min(range.from.top, range.to.top) - range.margin,
+ Math.min(range.from.top, range.to.top) - range.topMargin, // HACK
Math.max(range.from.right, range.to.right),
- Math.max(range.from.bottom, range.to.bottom) + range.margin);
+ Math.max(range.from.bottom, range.to.bottom) + range.bottomMargin); // HACK
this.scrollTo(sPos.scrollLeft, sPos.scrollTop);
}
}),
@@ -5318,6 +5490,16 @@
signal(this, "refresh", this);
}),
+ // HACK: JESSE
+ regLineChange: function(line, type) {
+ regLineChange(this, line, type)
+ },
+
+ lineHandleIsHidden: function(lineHandle) {
+ return lineIsHidden(this, lineHandle);
+ },
+ // END HACK
+
swapDoc: methodOp(function(doc) {
var old = this.doc;
old.cm = null;
@@ -6674,6 +6856,7 @@
function widgetHeight(widget) {
if (widget.height != null) return widget.height;
+ if (widget.overlay) return widget.height = 0; // HACK: JESSE
var cm = widget.doc.cm;
if (!cm) return 0;
if (!contains(document.body, widget.node)) {
@@ -6837,10 +7020,18 @@
// A styles array always starts with a number identifying the
// mode/overlays that it is based on (for easy invalidation).
var st = [cm.state.modeGen], lineClasses = {};
- // Compute the base array of styles
- runMode(cm, line.text, cm.doc.mode, state, function(end, style) {
- st.push(end, style);
- }, lineClasses, forceToEnd);
+
+ // HACK: JESSE
+ var externalMode = cm.getOption('externalMode'); // HACK
+ if (externalMode) { // HACK
+ var externalStyles = externalMode(cm, line); // HACK
+ st = st.concat(externalStyles); // HACK
+ } else { // HACK
+ // Compute the base array of styles
+ runMode(cm, line.text, cm.doc.mode, state, function(end, style) {
+ st.push(end, style);
+ }, lineClasses, forceToEnd);
+ } // HACK
// Run overlays, adjust style array.
for (var o = 0; o < cm.state.overlays.length; ++o) {
@@ -6961,7 +7152,7 @@
if (webkit && /\bcm-tab\b/.test(builder.content.lastChild.className))
builder.content.className = "cm-tab-wrap-hack";
- signal(cm, "renderLine", cm, lineView.line, builder.pre);
+ signal(cm, "renderLine", cm, lineView.line, builder.pre, builder, lineView.measure); // HACK: JESSE (Send builder and lineView.measure too)
if (builder.pre.className)
builder.textClass = joinClasses(builder.pre.className, builder.textClass || "");
@@ -7082,6 +7273,56 @@
// and marked text into account.
function insertLineContent(line, builder, styles) {
var spans = line.markedSpans, allText = line.text, at = 0;
+ /*
+ BREAKS codemirror span names such as CodeMirror-selectedtext since CM will be prepended to
+ anything that runs thorugh this code.
+
+ var AttributedString = builder.cm.options.AttributedString;
+ if (AttributedString) {
+ var attributedString = new AttributedString(line.text);
+ var start = 0;
+ var end = 0;
+ var runStyles;
+ var runs = [];
+ for (var i = 1; i < styles.length; i+=2) {
+ end = styles[i];
+ runStyles = styles[i + 1];
+ if (runStyles) {
+ runStyles = runStyles.split(' ');
+ for (var j = 0; j < runStyles.length; j++) {
+ attributedString.addAttributeInRange(runStyles[j], '', start, end - start);
+ }
+ }
+ start = end;
+ }
+
+ if (spans) {
+ for (var j = 0; j < spans.length; ++j) {
+ var sp = spans[j];
+ var marker = sp.marker;
+ var from = sp.from;
+ var to = sp.to;
+
+ if (from === null) from = 0;
+ if (to === null) to = allText.length;
+
+ var markerClassName = marker.className;
+ if (markerClassName) {
+ var markerClassNameLead = markerClassName.substr(0, 3);
+ if (markerClassNameLead === 'cm-') {
+ // trim off 'cm-''
+ attributedString.addAttributeInRange(markerClassName.substr(3), '', from, to - from);
+ } else {
+ attributedString.addAttributeInRange(markerClassName, '', from, to - from);
+ }
+ }
+ }
+ }
+
+ styles = [styles[0]];
+ attributedString.toCodeMirrorStyleArray(styles, false, true);
+ }*/
+
if (!spans) {
for (var i = 1; i < styles.length; i+=2)
builder.addToken(builder, allText.slice(at, at = styles[i]), interpretTokenStyle(styles[i+1], builder.cm.options));
@@ -7622,9 +7863,9 @@
var spans = line.markedSpans;
if (spans) for (var i = 0; i < spans.length; i++) {
var span = spans[i];
- if (!(lineNo == from.line && from.ch > span.to ||
- span.from == null && lineNo != from.line||
- lineNo == to.line && span.from > to.ch) &&
+ if (!(span.to != null && lineNo == from.line && from.ch > span.to ||
+ span.from == null && lineNo != from.line ||
+ span.from != null && lineNo == to.line && span.from > to.ch) &&
(!filter || filter(span.marker)))
found.push(span.marker.parent || span.marker);
}
@@ -7632,6 +7873,46 @@
});
return found;
},
+ // HACK: JESSE
+ findMarksInRange: function(from, to) {
+ if (!to) to = from;
+ from = clipPos(this, from);
+ to = clipPos(this, to);
+ var markers = [], lineNum = from.line;
+
+ this.iter(from.line, to.line + 1, function(line) {
+ var spans = line.markedSpans;
+ if (spans) {
+ for (var i = 0; i < spans.length; ++i) {
+ var span = spans[i];
+ var fromOverlap = false;
+ var toOverlap = false;
+
+ if (to.line === lineNum) {
+ fromOverlap = span.from == null || span.from <= to.ch;
+ } else {
+ fromOverlap = true;
+ }
+
+ if (from.line === lineNum) {
+ toOverlap = span.to == null || span.to >= from.ch;
+ } else {
+ toOverlap = true;
+ }
+
+ if (fromOverlap && toOverlap) {
+ var marker = span.marker.parent || span.marker;
+ if (markers.indexOf(marker) === -1) {
+ markers.push(marker);
+ }
+ }
+ }
+ }
+ lineNum++;
+ });
+ return markers;
+ },
+ // END HACK
getAllMarks: function() {
var markers = [];
this.iter(function(line) {