codemirror-rails 3.15 → 3.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/codemirror/rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/codemirror.js +59 -29
  4. data/vendor/assets/javascripts/codemirror/addons/comment/continuecomment.js +44 -0
  5. data/vendor/assets/javascripts/codemirror/addons/display/fullscreen.js +30 -0
  6. data/vendor/assets/javascripts/codemirror/addons/edit/continuecomment.js +1 -1
  7. data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +3 -3
  8. data/vendor/assets/javascripts/codemirror/addons/fold/comment-fold.js +40 -0
  9. data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +7 -10
  10. data/vendor/assets/javascripts/codemirror/addons/scroll/scrollpastend.js +34 -0
  11. data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +4 -1
  12. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +5 -0
  13. data/vendor/assets/javascripts/codemirror/modes/css.js +21 -19
  14. data/vendor/assets/javascripts/codemirror/modes/erlang.js +122 -102
  15. data/vendor/assets/javascripts/codemirror/modes/javascript.js +3 -2
  16. data/vendor/assets/javascripts/codemirror/modes/python.js +12 -4
  17. data/vendor/assets/javascripts/codemirror/modes/rst.js +20 -21
  18. data/vendor/assets/javascripts/codemirror/modes/velocity.js +54 -12
  19. data/vendor/assets/javascripts/codemirror/modes/xml.js +1 -1
  20. data/vendor/assets/javascripts/codemirror/modes/xquery.js +5 -1
  21. data/vendor/assets/javascripts/codemirror/modes/yaml.js +8 -8
  22. data/vendor/assets/stylesheets/codemirror.css +1 -0
  23. data/vendor/assets/stylesheets/codemirror/addons/display/fullscreen.css +6 -0
  24. data/vendor/assets/stylesheets/codemirror/themes/3024-day.css +1 -0
  25. data/vendor/assets/stylesheets/codemirror/themes/3024-night.css +1 -0
  26. data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +1 -1
  27. data/vendor/assets/stylesheets/codemirror/themes/base16-dark.css +1 -0
  28. data/vendor/assets/stylesheets/codemirror/themes/base16-light.css +1 -0
  29. data/vendor/assets/stylesheets/codemirror/themes/blackboard.css +3 -0
  30. data/vendor/assets/stylesheets/codemirror/themes/cobalt.css +3 -0
  31. data/vendor/assets/stylesheets/codemirror/themes/eclipse.css +2 -4
  32. data/vendor/assets/stylesheets/codemirror/themes/elegant.css +3 -0
  33. data/vendor/assets/stylesheets/codemirror/themes/erlang-dark.css +11 -2
  34. data/vendor/assets/stylesheets/codemirror/themes/lesser-dark.css +3 -0
  35. data/vendor/assets/stylesheets/codemirror/themes/midnight.css +2 -2
  36. data/vendor/assets/stylesheets/codemirror/themes/monokai.css +1 -0
  37. data/vendor/assets/stylesheets/codemirror/themes/neat.css +3 -0
  38. data/vendor/assets/stylesheets/codemirror/themes/night.css +3 -0
  39. data/vendor/assets/stylesheets/codemirror/themes/paraiso-dark.css +34 -0
  40. data/vendor/assets/stylesheets/codemirror/themes/paraiso-light.css +34 -0
  41. data/vendor/assets/stylesheets/codemirror/themes/rubyblue.css +2 -0
  42. data/vendor/assets/stylesheets/codemirror/themes/solarized.css +2 -7
  43. data/vendor/assets/stylesheets/codemirror/themes/the-matrix.css +26 -0
  44. data/vendor/assets/stylesheets/codemirror/themes/tomorrow-night-eighties.css +1 -0
  45. data/vendor/assets/stylesheets/codemirror/themes/twilight.css +2 -0
  46. data/vendor/assets/stylesheets/codemirror/themes/vibrant-ink.css +3 -0
  47. data/vendor/assets/stylesheets/codemirror/themes/xq-dark.css +4 -1
  48. data/vendor/assets/stylesheets/codemirror/themes/xq-light.css +1 -1
  49. metadata +10 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b87d64cb7ae54051ff568e14699010de59f830b4
4
- data.tar.gz: c1b9dfa59056dc0e7fa7a2dc097478013c95e6d1
3
+ metadata.gz: 1a097dd836952a9d7016ff82994bb2cf95bf08c5
4
+ data.tar.gz: b9217b3006c879ae8e9df6feee1abffdd92ab939
5
5
  SHA512:
6
- metadata.gz: 7ca0fdfede9a60eb79b632a66bf0afb91627cf98d610a45d822a0fca46e44bcf9af84fb5ba61d3316af5cb0f8e83ed713877e2c22e06f109cfa9615d04ed740d
7
- data.tar.gz: a489edc67eec3593cfc023f7e039b5d41b76ad7f7d7b1d54495ae348c87f704b7abb15073cf37870140595f5fbe7d35212fe30d18c592fbbf9d89c21ee9c9433
6
+ metadata.gz: 29a02c78ca161d4b336e380ebfcd633a125f213efb655bf7c49a1bd48755458d572f7dd45094382930004a120d0a612478d9c7ba01cdae9e8732f3e7511d010b
7
+ data.tar.gz: 8e45db94d110041b68a8c9649b88edd7f1ed11cb045a80b5f9bc2e8de6f6a39690bc994a906bae7f65831959d7f84a28f8495f58082095277790127e4d5c03b8
@@ -1,6 +1,6 @@
1
1
  module Codemirror
2
2
  module Rails
3
- VERSION = '3.15'
4
- CODEMIRROR_VERSION = '3.15'
3
+ VERSION = '3.16'
4
+ CODEMIRROR_VERSION = '3.16'
5
5
  end
6
6
  end
@@ -1,4 +1,4 @@
1
- // CodeMirror version 3.15
1
+ // CodeMirror version 3.16
2
2
  //
3
3
  // CodeMirror is the only global var we claim
4
4
  window.CodeMirror = (function() {
@@ -26,7 +26,7 @@ window.CodeMirror = (function() {
26
26
  // This is woefully incomplete. Suggestions for alternative methods welcome.
27
27
  var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent);
28
28
  var mac = ios || /Mac/.test(navigator.platform);
29
- var windows = /windows/i.test(navigator.platform);
29
+ var windows = /win/i.test(navigator.platform);
30
30
 
31
31
  var opera_version = opera && navigator.userAgent.match(/Version\/(\d*\.\d*)/);
32
32
  if (opera_version) opera_version = Number(opera_version[1]);
@@ -334,13 +334,19 @@ window.CodeMirror = (function() {
334
334
  d.scrollbarV.style.bottom = needsH ? scrollbarWidth(d.measure) + "px" : "0";
335
335
  d.scrollbarV.firstChild.style.height =
336
336
  (scrollHeight - d.scroller.clientHeight + d.scrollbarV.clientHeight) + "px";
337
- } else d.scrollbarV.style.display = "";
337
+ } else {
338
+ d.scrollbarV.style.display = "";
339
+ d.scrollbarV.firstChild.style.height = "0";
340
+ }
338
341
  if (needsH) {
339
342
  d.scrollbarH.style.display = "block";
340
343
  d.scrollbarH.style.right = needsV ? scrollbarWidth(d.measure) + "px" : "0";
341
344
  d.scrollbarH.firstChild.style.width =
342
345
  (d.scroller.scrollWidth - d.scroller.clientWidth + d.scrollbarH.clientWidth) + "px";
343
- } else d.scrollbarH.style.display = "";
346
+ } else {
347
+ d.scrollbarH.style.display = "";
348
+ d.scrollbarH.firstChild.style.width = "0";
349
+ }
344
350
  if (needsH && needsV) {
345
351
  d.scrollbarFiller.style.display = "block";
346
352
  d.scrollbarFiller.style.height = d.scrollbarFiller.style.width = scrollbarWidth(d.measure) + "px";
@@ -457,7 +463,7 @@ window.CodeMirror = (function() {
457
463
  var positionsChangedFrom = Infinity;
458
464
  if (cm.options.lineNumbers)
459
465
  for (var i = 0; i < changes.length; ++i)
460
- if (changes[i].diff) { positionsChangedFrom = changes[i].from; break; }
466
+ if (changes[i].diff && changes[i].from < positionsChangedFrom) { positionsChangedFrom = changes[i].from; }
461
467
 
462
468
  var end = doc.first + doc.size;
463
469
  var from = Math.max(visible.from - cm.options.viewportMargin, doc.first);
@@ -614,7 +620,7 @@ window.CodeMirror = (function() {
614
620
  if (nextIntact && nextIntact.to == lineN) nextIntact = intact.shift();
615
621
  if (lineIsHidden(cm.doc, line)) {
616
622
  if (line.height != 0) updateLineHeight(line, 0);
617
- if (line.widgets && cur.previousSibling) for (var i = 0; i < line.widgets.length; ++i) {
623
+ if (line.widgets && cur && cur.previousSibling) for (var i = 0; i < line.widgets.length; ++i) {
618
624
  var w = line.widgets[i];
619
625
  if (w.showIfHidden) {
620
626
  var prev = cur.previousSibling;
@@ -873,9 +879,10 @@ window.CodeMirror = (function() {
873
879
  clearInterval(display.blinker);
874
880
  var on = true;
875
881
  display.cursor.style.visibility = display.otherCursor.style.visibility = "";
876
- display.blinker = setInterval(function() {
877
- display.cursor.style.visibility = display.otherCursor.style.visibility = (on = !on) ? "" : "hidden";
878
- }, cm.options.cursorBlinkRate);
882
+ if (cm.options.cursorBlinkRate > 0)
883
+ display.blinker = setInterval(function() {
884
+ display.cursor.style.visibility = display.otherCursor.style.visibility = (on = !on) ? "" : "hidden";
885
+ }, cm.options.cursorBlinkRate);
879
886
  }
880
887
 
881
888
  // HIGHLIGHT WORKER
@@ -926,8 +933,8 @@ window.CodeMirror = (function() {
926
933
  // smallest indentation, which tends to need the least context to
927
934
  // parse correctly.
928
935
  function findStartLine(cm, n, precise) {
929
- var minindent, minline, doc = cm.doc;
930
- for (var search = n, lim = n - 100; search > lim; --search) {
936
+ var minindent, minline, doc = cm.doc, maxScan = cm.doc.mode.innerMode ? 1000 : 100;
937
+ for (var search = n, lim = n - maxScan; search > lim; --search) {
931
938
  if (search <= doc.first) return doc.first;
932
939
  var line = getLine(doc, search - 1);
933
940
  if (line.stateAfter && (!precise || search <= doc.frontier)) return search;
@@ -942,7 +949,7 @@ window.CodeMirror = (function() {
942
949
 
943
950
  function getStateBefore(cm, n, precise) {
944
951
  var doc = cm.doc, display = cm.display;
945
- if (!doc.mode.startState) return true;
952
+ if (!doc.mode.startState) return true;
946
953
  var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter;
947
954
  if (!state) state = startState(doc.mode);
948
955
  else state = copyState(doc.mode, state);
@@ -1092,6 +1099,7 @@ window.CodeMirror = (function() {
1092
1099
  if (cur.measureRight) rect.right = getRect(cur.measureRight).left;
1093
1100
  if (cur.leftSide) rect.leftSide = measureRect(getRect(cur.leftSide));
1094
1101
  }
1102
+ removeChildren(cm.display.measure);
1095
1103
  for (var i = 0, cur; i < data.length; ++i) if (cur = data[i]) {
1096
1104
  finishRect(cur);
1097
1105
  if (cur.leftSide) finishRect(cur.leftSide);
@@ -1444,6 +1452,10 @@ window.CodeMirror = (function() {
1444
1452
  function readInput(cm) {
1445
1453
  var input = cm.display.input, prevInput = cm.display.prevInput, doc = cm.doc, sel = doc.sel;
1446
1454
  if (!cm.state.focused || hasSelection(input) || isReadOnly(cm) || cm.state.disableInput) return false;
1455
+ if (cm.state.pasteIncoming && cm.state.fakedLastChar) {
1456
+ input.value = input.value.substring(0, input.value.length - 1);
1457
+ cm.state.fakedLastChar = false;
1458
+ }
1447
1459
  var text = input.value;
1448
1460
  if (text == prevInput && posEq(sel.from, sel.to)) return false;
1449
1461
  if (ie && !ie_lt9 && cm.display.inputHasSelection === text) {
@@ -1590,12 +1602,22 @@ window.CodeMirror = (function() {
1590
1602
  on(d.scroller, "dragover", drag_);
1591
1603
  on(d.scroller, "drop", operation(cm, onDrop));
1592
1604
  }
1593
- on(d.scroller, "paste", function(e){
1605
+ on(d.scroller, "paste", function(e) {
1594
1606
  if (eventInWidget(d, e)) return;
1595
1607
  focusInput(cm);
1596
1608
  fastPoll(cm);
1597
1609
  });
1598
1610
  on(d.input, "paste", function() {
1611
+ // Workaround for webkit bug https://bugs.webkit.org/show_bug.cgi?id=90206
1612
+ // Add a char to the end of textarea before paste occur so that
1613
+ // selection doesn't span to the end of textarea.
1614
+ if (webkit && !cm.state.fakedLastChar && !(new Date - cm.state.lastMiddleDown < 200)) {
1615
+ var start = d.input.selectionStart, end = d.input.selectionEnd;
1616
+ d.input.value += "$";
1617
+ d.input.selectionStart = start;
1618
+ d.input.selectionEnd = end;
1619
+ cm.state.fakedLastChar = true;
1620
+ }
1599
1621
  cm.state.pasteIncoming = true;
1600
1622
  fastPoll(cm);
1601
1623
  });
@@ -1659,6 +1681,7 @@ window.CodeMirror = (function() {
1659
1681
  if (captureMiddleClick) onContextMenu.call(cm, cm, e);
1660
1682
  return;
1661
1683
  case 2:
1684
+ if (webkit) cm.state.lastMiddleDown = +new Date;
1662
1685
  if (start) extendSelection(cm.doc, start);
1663
1686
  setTimeout(bind(focusInput, cm), 20);
1664
1687
  e_preventDefault(e);
@@ -2062,8 +2085,8 @@ window.CodeMirror = (function() {
2062
2085
  function onKeyDown(e) {
2063
2086
  var cm = this;
2064
2087
  if (!cm.state.focused) onFocus(cm);
2065
- if (ie && e.keyCode == 27) { e.returnValue = false; }
2066
2088
  if (signalDOMEvent(cm, e) || cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
2089
+ if (ie && e.keyCode == 27) e.returnValue = false;
2067
2090
  var code = e.keyCode;
2068
2091
  // IE does strange things with escape.
2069
2092
  cm.doc.sel.shift = code == 16 || e.shiftKey;
@@ -2100,7 +2123,10 @@ window.CodeMirror = (function() {
2100
2123
  cm.state.focused = true;
2101
2124
  if (cm.display.wrapper.className.search(/\bCodeMirror-focused\b/) == -1)
2102
2125
  cm.display.wrapper.className += " CodeMirror-focused";
2103
- resetInput(cm, true);
2126
+ if (!cm.curOp) {
2127
+ resetInput(cm, true);
2128
+ if (webkit) setTimeout(bind(resetInput, cm, true), 0); // Issue #1730
2129
+ }
2104
2130
  }
2105
2131
  slowPoll(cm);
2106
2132
  restartBlink(cm);
@@ -3731,9 +3757,10 @@ window.CodeMirror = (function() {
3731
3757
  TextMarker.prototype.changed = function() {
3732
3758
  var pos = this.find(), cm = this.doc.cm;
3733
3759
  if (!pos || !cm) return;
3734
- var line = getLine(this.doc, pos.from.line);
3760
+ if (this.type != "bookmark") pos = pos.from;
3761
+ var line = getLine(this.doc, pos.line);
3735
3762
  clearCachedMeasurement(cm, line);
3736
- if (pos.from.line >= cm.display.showingFrom && pos.from.line < cm.display.showingTo) {
3763
+ if (pos.line >= cm.display.showingFrom && pos.line < cm.display.showingTo) {
3737
3764
  for (var node = cm.display.lineDiv.firstChild; node; node = node.nextSibling) if (node.lineObj == line) {
3738
3765
  if (node.offsetHeight != line.height) updateLineHeight(line, node.offsetHeight);
3739
3766
  break;
@@ -4396,11 +4423,13 @@ window.CodeMirror = (function() {
4396
4423
  if (size) {
4397
4424
  builder.measure[builder.pos] = widget;
4398
4425
  } else {
4399
- var elt = builder.measure[builder.pos] = zeroWidthElement(builder.cm.display.measure);
4400
- if (marker.type != "bookmark" || marker.insertLeft)
4401
- builder.pre.insertBefore(elt, widget);
4426
+ var elt = zeroWidthElement(builder.cm.display.measure);
4427
+ if (marker.type == "bookmark" && !marker.insertLeft)
4428
+ builder.measure[builder.pos] = builder.pre.appendChild(elt);
4429
+ else if (builder.measure[builder.pos])
4430
+ return;
4402
4431
  else
4403
- builder.pre.appendChild(elt);
4432
+ builder.measure[builder.pos] = builder.pre.insertBefore(elt, widget);
4404
4433
  }
4405
4434
  builder.measuredSomething = true;
4406
4435
  }
@@ -4424,7 +4453,7 @@ window.CodeMirror = (function() {
4424
4453
  if (nextChange == pos) { // Update current marker set
4425
4454
  spanStyle = spanEndStyle = spanStartStyle = title = "";
4426
4455
  collapsed = null; nextChange = Infinity;
4427
- var foundBookmark = null;
4456
+ var foundBookmarks = [];
4428
4457
  for (var j = 0; j < spans.length; ++j) {
4429
4458
  var sp = spans[j], m = sp.marker;
4430
4459
  if (sp.from <= pos && (sp.to == null || sp.to > pos)) {
@@ -4438,14 +4467,15 @@ window.CodeMirror = (function() {
4438
4467
  } else if (sp.from > pos && nextChange > sp.from) {
4439
4468
  nextChange = sp.from;
4440
4469
  }
4441
- if (m.type == "bookmark" && sp.from == pos && m.replacedWith) foundBookmark = m;
4470
+ if (m.type == "bookmark" && sp.from == pos && m.replacedWith) foundBookmarks.push(m);
4442
4471
  }
4443
4472
  if (collapsed && (collapsed.from || 0) == pos) {
4444
4473
  buildCollapsedSpan(builder, (collapsed.to == null ? len : collapsed.to) - pos,
4445
4474
  collapsed.marker, collapsed.from == null);
4446
4475
  if (collapsed.to == null) return collapsed.marker.find();
4447
4476
  }
4448
- if (foundBookmark && !collapsed) buildCollapsedSpan(builder, 0, foundBookmark);
4477
+ if (!collapsed && foundBookmarks.length) for (var j = 0; j < foundBookmarks.length; ++j)
4478
+ buildCollapsedSpan(builder, 0, foundBookmarks[j]);
4449
4479
  }
4450
4480
  if (pos >= len) break;
4451
4481
 
@@ -4741,11 +4771,11 @@ window.CodeMirror = (function() {
4741
4771
  if (extend) extendSelection(this, pos);
4742
4772
  else setSelection(this, pos, pos);
4743
4773
  }),
4744
- setSelection: docOperation(function(anchor, head) {
4745
- setSelection(this, clipPos(this, anchor), clipPos(this, head || anchor));
4774
+ setSelection: docOperation(function(anchor, head, bias) {
4775
+ setSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), bias);
4746
4776
  }),
4747
- extendSelection: docOperation(function(from, to) {
4748
- extendSelection(this, clipPos(this, from), to && clipPos(this, to));
4777
+ extendSelection: docOperation(function(from, to, bias) {
4778
+ extendSelection(this, clipPos(this, from), to && clipPos(this, to), bias);
4749
4779
  }),
4750
4780
 
4751
4781
  getSelection: function(lineSep) {return this.getRange(this.sel.from, this.sel.to, lineSep);},
@@ -5793,7 +5823,7 @@ window.CodeMirror = (function() {
5793
5823
 
5794
5824
  // THE END
5795
5825
 
5796
- CodeMirror.version = "3.15.0";
5826
+ CodeMirror.version = "3.16.0";
5797
5827
 
5798
5828
  return CodeMirror;
5799
5829
  })();
@@ -0,0 +1,44 @@
1
+ (function() {
2
+ var modes = ["clike", "css", "javascript"];
3
+ for (var i = 0; i < modes.length; ++i)
4
+ CodeMirror.extendMode(modes[i], {blockCommentStart: "/*",
5
+ blockCommentEnd: "*/",
6
+ blockCommentContinue: " * "});
7
+
8
+ function continueComment(cm) {
9
+ var pos = cm.getCursor(), token = cm.getTokenAt(pos);
10
+ var mode = CodeMirror.innerMode(cm.getMode(), token.state).mode;
11
+ var space;
12
+
13
+ if (token.type == "comment" && mode.blockCommentStart && mode.blockCommentContinue) {
14
+ var end = token.string.indexOf(mode.blockCommentEnd);
15
+ var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found;
16
+ if (end != -1 && end == token.string.length - mode.blockCommentEnd.length) {
17
+ // Comment ended, don't continue it
18
+ } else if (token.string.indexOf(mode.blockCommentStart) == 0) {
19
+ space = full.slice(0, token.start);
20
+ if (!/^\s*$/.test(space)) {
21
+ space = "";
22
+ for (var i = 0; i < token.start; ++i) space += " ";
23
+ }
24
+ } else if ((found = full.indexOf(mode.blockCommentContinue)) != -1 &&
25
+ found + mode.blockCommentContinue.length > token.start &&
26
+ /^\s*$/.test(full.slice(0, found))) {
27
+ space = full.slice(0, found);
28
+ }
29
+ }
30
+
31
+ if (space != null)
32
+ cm.replaceSelection("\n" + space + mode.blockCommentContinue, "end");
33
+ else
34
+ return CodeMirror.Pass;
35
+ }
36
+
37
+ CodeMirror.defineOption("continueComments", null, function(cm, val, prev) {
38
+ if (prev && prev != CodeMirror.Init)
39
+ cm.removeKeyMap("continueComment");
40
+ var map = {name: "continueComment"};
41
+ map[typeof val == "string" ? val : "Enter"] = continueComment;
42
+ cm.addKeyMap(map);
43
+ });
44
+ })();
@@ -0,0 +1,30 @@
1
+ (function() {
2
+ "use strict";
3
+
4
+ CodeMirror.defineOption("fullScreen", false, function(cm, val, old) {
5
+ if (old == CodeMirror.Init) old = false;
6
+ if (!old == !val) return;
7
+ if (val) setFullscreen(cm);
8
+ else setNormal(cm);
9
+ });
10
+
11
+ function setFullscreen(cm) {
12
+ var wrap = cm.getWrapperElement();
13
+ cm.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset,
14
+ width: wrap.style.width, height: wrap.style.height};
15
+ wrap.style.width = wrap.style.height = "";
16
+ wrap.className += " CodeMirror-fullscreen";
17
+ document.documentElement.style.overflow = "hidden";
18
+ cm.refresh();
19
+ }
20
+
21
+ function setNormal(cm) {
22
+ var wrap = cm.getWrapperElement();
23
+ wrap.className = wrap.className.replace(/\s*CodeMirror-fullscreen\b/, "");
24
+ document.documentElement.style.overflow = "";
25
+ var info = cm.state.fullScreenRestore;
26
+ wrap.style.width = info.width; wrap.style.height = info.height;
27
+ window.scrollTo(info.scrollLeft, info.scrollTop);
28
+ cm.refresh();
29
+ }
30
+ })();
@@ -10,7 +10,7 @@
10
10
  var mode = CodeMirror.innerMode(cm.getMode(), token.state).mode;
11
11
  var space;
12
12
 
13
- if (token.type == "comment" && mode.blockCommentStart) {
13
+ if (token.type == "comment" && mode.blockCommentStart && mode.blockCommentContinue) {
14
14
  var end = token.string.indexOf(mode.blockCommentEnd);
15
15
  var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found;
16
16
  if (end != -1 && end == token.string.length - mode.blockCommentEnd.length) {
@@ -4,7 +4,7 @@ CodeMirror.registerHelper("fold", "brace", function(cm, start) {
4
4
 
5
5
  function findOpening(openCh) {
6
6
  for (var at = start.ch, pass = 0;;) {
7
- var found = lineText.lastIndexOf(openCh, at - 1);
7
+ var found = at <= 0 ? -1 : lineText.lastIndexOf(openCh, at - 1);
8
8
  if (found == -1) {
9
9
  if (pass == 1) break;
10
10
  pass = 1;
@@ -12,7 +12,7 @@ CodeMirror.registerHelper("fold", "brace", function(cm, start) {
12
12
  continue;
13
13
  }
14
14
  if (pass == 1 && found < start.ch) break;
15
- tokenType = cm.getTokenAt(CodeMirror.Pos(line, found + 1)).type;
15
+ tokenType = cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1));
16
16
  if (!/^(comment|string)/.test(tokenType)) return found + 1;
17
17
  at = found - 1;
18
18
  }
@@ -34,7 +34,7 @@ CodeMirror.registerHelper("fold", "brace", function(cm, start) {
34
34
  if (nextClose < 0) nextClose = text.length;
35
35
  pos = Math.min(nextOpen, nextClose);
36
36
  if (pos == text.length) break;
37
- if (cm.getTokenAt(CodeMirror.Pos(i, pos + 1)).type == tokenType) {
37
+ if (cm.getTokenTypeAt(CodeMirror.Pos(i, pos + 1)) == tokenType) {
38
38
  if (pos == nextOpen) ++count;
39
39
  else if (!--count) { end = i; endCh = pos; break outer; }
40
40
  }
@@ -0,0 +1,40 @@
1
+ CodeMirror.registerHelper("fold", "comment", function(cm, start) {
2
+ var mode = cm.getModeAt(start), startToken = mode.blockCommentStart, endToken = mode.blockCommentEnd;
3
+ if (!startToken || !endToken) return;
4
+ var line = start.line, lineText = cm.getLine(line);
5
+
6
+ var startCh;
7
+ for (var at = start.ch, pass = 0;;) {
8
+ var found = at <= 0 ? -1 : lineText.lastIndexOf(startToken, at - 1);
9
+ if (found == -1) {
10
+ if (pass == 1) return;
11
+ pass = 1;
12
+ at = lineText.length;
13
+ continue;
14
+ }
15
+ if (pass == 1 && found < start.ch) return;
16
+ if (/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1)))) {
17
+ startCh = found + startToken.length;
18
+ break;
19
+ }
20
+ at = found - 1;
21
+ }
22
+
23
+ var depth = 1, lastLine = cm.lastLine(), end, endCh;
24
+ outer: for (var i = line; i <= lastLine; ++i) {
25
+ var text = cm.getLine(i), pos = i == line ? startCh : 0;
26
+ for (;;) {
27
+ var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);
28
+ if (nextOpen < 0) nextOpen = text.length;
29
+ if (nextClose < 0) nextClose = text.length;
30
+ pos = Math.min(nextOpen, nextClose);
31
+ if (pos == text.length) break;
32
+ if (pos == nextOpen) ++depth;
33
+ else if (!--depth) { end = i; endCh = pos; break outer; }
34
+ ++pos;
35
+ }
36
+ }
37
+ if (end == null || line == end && endCh == startCh) return;
38
+ return {from: CodeMirror.Pos(line, startCh),
39
+ to: CodeMirror.Pos(end, endCh)};
40
+ });
@@ -67,15 +67,11 @@
67
67
  finished = true;
68
68
  completion.close();
69
69
  completion.cm.off("cursorActivity", activity);
70
- CodeMirror.signal(data, "close");
71
- }
72
- function isDone() {
73
- if (finished) return true;
74
- if (!completion.widget) { done(); return true; }
70
+ if (data) CodeMirror.signal(data, "close");
75
71
  }
76
72
 
77
73
  function update() {
78
- if (isDone()) return;
74
+ if (finished) return;
79
75
  CodeMirror.signal(data, "update");
80
76
  if (completion.options.async)
81
77
  completion.getHints(completion.cm, finishUpdate, completion.options);
@@ -84,9 +80,8 @@
84
80
  }
85
81
  function finishUpdate(data_) {
86
82
  data = data_;
87
- if (isDone()) return;
83
+ if (finished) return;
88
84
  if (!data || !data.list.length) return done();
89
- completion.widget.close();
90
85
  completion.widget = new Widget(completion, data);
91
86
  }
92
87
 
@@ -95,10 +90,12 @@
95
90
  var pos = completion.cm.getCursor(), line = completion.cm.getLine(pos.line);
96
91
  if (pos.line != startPos.line || line.length - pos.ch != startLen - startPos.ch ||
97
92
  pos.ch < startPos.ch || completion.cm.somethingSelected() ||
98
- (pos.ch && closeOn.test(line.charAt(pos.ch - 1))))
93
+ (pos.ch && closeOn.test(line.charAt(pos.ch - 1)))) {
99
94
  completion.close();
100
- else
95
+ } else {
101
96
  debounce = setTimeout(update, 170);
97
+ if (completion.widget) completion.widget.close();
98
+ }
102
99
  }
103
100
  this.cm.on("cursorActivity", activity);
104
101
  this.onClose = done;