codemirror-rails 5.0 → 5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/codemirror/rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/codemirror.js +104 -64
  4. data/vendor/assets/javascripts/codemirror/addons/dialog/dialog.js +3 -1
  5. data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +144 -121
  6. data/vendor/assets/javascripts/codemirror/addons/fold/foldgutter.js +4 -2
  7. data/vendor/assets/javascripts/codemirror/addons/hint/css-hint.js +4 -0
  8. data/vendor/assets/javascripts/codemirror/addons/hint/sql-hint.js +13 -8
  9. data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +2 -0
  10. data/vendor/assets/javascripts/codemirror/addons/merge/merge.js +40 -0
  11. data/vendor/assets/javascripts/codemirror/addons/mode/multiplex_test.js +33 -0
  12. data/vendor/assets/javascripts/codemirror/addons/scroll/simplescrollbars.js +8 -2
  13. data/vendor/assets/javascripts/codemirror/addons/tern/tern.js +1 -1
  14. data/vendor/assets/javascripts/codemirror/keymaps/sublime.js +13 -0
  15. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +43 -54
  16. data/vendor/assets/javascripts/codemirror/modes/asciiarmor.js +73 -0
  17. data/vendor/assets/javascripts/codemirror/modes/clike.js +2 -1
  18. data/vendor/assets/javascripts/codemirror/modes/clojure.js +1 -0
  19. data/vendor/assets/javascripts/codemirror/modes/cmake.js +97 -0
  20. data/vendor/assets/javascripts/codemirror/modes/commonlisp.js +1 -0
  21. data/vendor/assets/javascripts/codemirror/modes/css.js +1 -0
  22. data/vendor/assets/javascripts/codemirror/modes/groovy.js +1 -0
  23. data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +18 -76
  24. data/vendor/assets/javascripts/codemirror/modes/javascript.js +5 -0
  25. data/vendor/assets/javascripts/codemirror/modes/kotlin.js +1 -0
  26. data/vendor/assets/javascripts/codemirror/modes/less_test.js +51 -0
  27. data/vendor/assets/javascripts/codemirror/modes/mllike.js +1 -1
  28. data/vendor/assets/javascripts/codemirror/modes/properties.js +1 -1
  29. data/vendor/assets/javascripts/codemirror/modes/python.js +1 -0
  30. data/vendor/assets/javascripts/codemirror/modes/sass.js +1 -1
  31. data/vendor/assets/javascripts/codemirror/modes/scheme.js +1 -0
  32. data/vendor/assets/javascripts/codemirror/modes/scss_test.js +110 -0
  33. data/vendor/assets/javascripts/codemirror/modes/smarty.js +100 -107
  34. data/vendor/assets/javascripts/codemirror/modes/stylus.js +651 -332
  35. data/vendor/assets/javascripts/codemirror/modes/test.js +67 -0
  36. data/vendor/assets/javascripts/codemirror/modes/troff.js +82 -0
  37. data/vendor/assets/javascripts/codemirror/modes/vb.js +6 -5
  38. data/vendor/assets/javascripts/codemirror/modes/verilog.js +53 -53
  39. data/vendor/assets/stylesheets/codemirror.css +11 -8
  40. data/vendor/assets/stylesheets/codemirror/themes/mdn-like.css +1 -1
  41. metadata +9 -3
  42. data/vendor/assets/javascripts/codemirror/modes/smartymixed.js +0 -197
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee58ad7606652b7d8522d0aa8e8bebba57fefa10
4
- data.tar.gz: 23919e1e33923f699a4198fe5244d1018db115c7
3
+ metadata.gz: fb8e0f584aeb96820145217fba9658635664ce33
4
+ data.tar.gz: 91c2ff5b741853b45e908e33b5c940e5f1d8bc3e
5
5
  SHA512:
6
- metadata.gz: e40c4eec1f07c990ab495b1a316f51c41645ad87ad159b62bc45061ade6dff34ea60cea1902adc1e5e38839f5179facccbb3041b8156549907fb5a72a00253f6
7
- data.tar.gz: 4e4b07ea9cd230ae38699c606f2810537e5ee9d0fe546c3a188749137c3124359ba112eb85245404f83e1cd4f8e999a4cf836e816fc7f69b34d3158c31c0a22b
6
+ metadata.gz: c779e40abb5943d41d80f957e9e311d2fe4e191a2ad56e007f6225771c9bc0189d5b22fca1885289fd0ab01af7224777230b4533e21a3df5c4c69323aaf01c2c
7
+ data.tar.gz: 154d437fc78cbfdd03e7bdde74a734a54b098edc1bce1ac4c4cd2c742a8c02135ded6af0731bd91fe2a2f819bc47a5231964e0a58ca3378f12b28c8c74450a3e
@@ -1,6 +1,6 @@
1
1
  module Codemirror
2
2
  module Rails
3
- VERSION = '5.0'
4
- CODEMIRROR_VERSION = '5.0'
3
+ VERSION = '5.1'
4
+ CODEMIRROR_VERSION = '5.1'
5
5
  end
6
6
  end
@@ -82,12 +82,15 @@
82
82
  keyMaps: [], // stores maps added by addKeyMap
83
83
  overlays: [], // highlighting overlays, as added by addOverlay
84
84
  modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
85
- overwrite: false, focused: false,
85
+ overwrite: false,
86
+ delayingBlurEvent: false,
87
+ focused: false,
86
88
  suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
87
89
  pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll
88
90
  draggingText: false,
89
91
  highlight: new Delayed(), // stores highlight worker timeout
90
- keySeq: null // Unfinished key sequence
92
+ keySeq: null, // Unfinished key sequence
93
+ specialChars: null
91
94
  };
92
95
 
93
96
  var cm = this;
@@ -591,7 +594,7 @@
591
594
  "CodeMirror-linenumber CodeMirror-gutter-elt"));
592
595
  var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
593
596
  display.lineGutter.style.width = "";
594
- display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding);
597
+ display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
595
598
  display.lineNumWidth = display.lineNumInnerWidth + padding;
596
599
  display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
597
600
  display.lineGutter.style.width = display.lineNumWidth + "px";
@@ -1381,8 +1384,14 @@
1381
1384
  return false;
1382
1385
  }
1383
1386
 
1384
- if (text.charCodeAt(0) == 0x200b && cm.doc.sel == cm.display.selForContextMenu && !prevInput)
1385
- prevInput = "\u200b";
1387
+ if (cm.doc.sel == cm.display.selForContextMenu) {
1388
+ if (text.charCodeAt(0) == 0x200b) {
1389
+ if (!prevInput) prevInput = "\u200b";
1390
+ } else if (prevInput == "\u200b") {
1391
+ text = text.slice(1);
1392
+ prevInput = "";
1393
+ }
1394
+ }
1386
1395
  // Find the part of the input that is actually new
1387
1396
  var same = 0, l = Math.min(prevInput.length, text.length);
1388
1397
  while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same;
@@ -1458,7 +1467,7 @@
1458
1467
  if (te.selectionStart != null) {
1459
1468
  if (!ie || (ie && ie_version < 9)) prepareSelectAllHack();
1460
1469
  var i = 0, poll = function() {
1461
- if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0)
1470
+ if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 && input.prevInput == "\u200b")
1462
1471
  operation(cm, commands.selectAll)(cm);
1463
1472
  else if (i++ < 10) display.detectingSelectAll = setTimeout(poll, 500);
1464
1473
  else display.input.reset();
@@ -1491,6 +1500,7 @@
1491
1500
  this.cm = cm;
1492
1501
  this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;
1493
1502
  this.polling = new Delayed();
1503
+ this.gracePeriod = false;
1494
1504
  }
1495
1505
 
1496
1506
  ContentEditableInput.prototype = copyObj({
@@ -1625,10 +1635,21 @@
1625
1635
  sel.removeAllRanges();
1626
1636
  sel.addRange(rng);
1627
1637
  if (old && sel.anchorNode == null) sel.addRange(old);
1638
+ else if (gecko) this.startGracePeriod();
1628
1639
  }
1629
1640
  this.rememberSelection();
1630
1641
  },
1631
1642
 
1643
+ startGracePeriod: function() {
1644
+ var input = this;
1645
+ clearTimeout(this.gracePeriod);
1646
+ this.gracePeriod = setTimeout(function() {
1647
+ input.gracePeriod = false;
1648
+ if (input.selectionChanged())
1649
+ input.cm.operation(function() { input.cm.curOp.selectionChanged = true; });
1650
+ }, 20);
1651
+ },
1652
+
1632
1653
  showMultipleSelections: function(info) {
1633
1654
  removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);
1634
1655
  removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);
@@ -1671,12 +1692,15 @@
1671
1692
  this.polling.set(this.cm.options.pollInterval, poll);
1672
1693
  },
1673
1694
 
1674
- pollSelection: function() {
1675
- if (this.composing) return;
1695
+ selectionChanged: function() {
1696
+ var sel = window.getSelection();
1697
+ return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
1698
+ sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset;
1699
+ },
1676
1700
 
1677
- var sel = window.getSelection(), cm = this.cm;
1678
- if (sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
1679
- sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset) {
1701
+ pollSelection: function() {
1702
+ if (!this.composing && !this.gracePeriod && this.selectionChanged()) {
1703
+ var sel = window.getSelection(), cm = this.cm;
1680
1704
  this.rememberSelection();
1681
1705
  var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
1682
1706
  var head = domToPos(cm, sel.focusNode, sel.focusOffset);
@@ -3475,6 +3499,7 @@
3475
3499
  break;
3476
3500
  case 3:
3477
3501
  if (captureRightClick) onContextMenu(cm, e);
3502
+ else delayBlurEvent(cm);
3478
3503
  break;
3479
3504
  }
3480
3505
  }
@@ -3517,10 +3542,11 @@
3517
3542
  e_preventDefault(e2);
3518
3543
  if (!modifier)
3519
3544
  extendSelection(cm.doc, start);
3520
- display.input.focus();
3521
- // Work around unexplainable focus problem in IE9 (#2127)
3522
- if (ie && ie_version == 9)
3545
+ // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
3546
+ if (webkit || ie && ie_version == 9)
3523
3547
  setTimeout(function() {document.body.focus(); display.input.focus();}, 20);
3548
+ else
3549
+ display.input.focus();
3524
3550
  }
3525
3551
  });
3526
3552
  // Let the drag handler handle this.
@@ -3546,6 +3572,7 @@
3546
3572
  ourRange = new Range(start, start);
3547
3573
  } else {
3548
3574
  ourRange = doc.sel.primary();
3575
+ ourIndex = doc.sel.primIndex;
3549
3576
  }
3550
3577
 
3551
3578
  if (e.altKey) {
@@ -3577,7 +3604,7 @@
3577
3604
  ourIndex = ranges.length;
3578
3605
  setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex),
3579
3606
  {scroll: false, origin: "*mouse"});
3580
- } else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single") {
3607
+ } else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single" && !e.shiftKey) {
3581
3608
  setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0));
3582
3609
  startSel = doc.sel;
3583
3610
  } else {
@@ -4050,7 +4077,19 @@
4050
4077
 
4051
4078
  // FOCUS/BLUR EVENTS
4052
4079
 
4080
+ function delayBlurEvent(cm) {
4081
+ cm.state.delayingBlurEvent = true;
4082
+ setTimeout(function() {
4083
+ if (cm.state.delayingBlurEvent) {
4084
+ cm.state.delayingBlurEvent = false;
4085
+ onBlur(cm);
4086
+ }
4087
+ }, 100);
4088
+ }
4089
+
4053
4090
  function onFocus(cm) {
4091
+ if (cm.state.delayingBlurEvent) cm.state.delayingBlurEvent = false;
4092
+
4054
4093
  if (cm.options.readOnly == "nocursor") return;
4055
4094
  if (!cm.state.focused) {
4056
4095
  signal(cm, "focus", cm);
@@ -4068,6 +4107,8 @@
4068
4107
  restartBlink(cm);
4069
4108
  }
4070
4109
  function onBlur(cm) {
4110
+ if (cm.state.delayingBlurEvent) return;
4111
+
4071
4112
  if (cm.state.focused) {
4072
4113
  signal(cm, "blur", cm);
4073
4114
  cm.state.focused = false;
@@ -4824,7 +4865,7 @@
4824
4865
 
4825
4866
  getHelpers: function(pos, type) {
4826
4867
  var found = [];
4827
- if (!helpers.hasOwnProperty(type)) return helpers;
4868
+ if (!helpers.hasOwnProperty(type)) return found;
4828
4869
  var help = helpers[type], mode = this.getModeAt(pos);
4829
4870
  if (typeof mode[type] == "string") {
4830
4871
  if (help[mode[type]]) found.push(help[mode[type]]);
@@ -4906,12 +4947,6 @@
4906
4947
  });
4907
4948
  }),
4908
4949
 
4909
- addLineWidget: methodOp(function(handle, node, options) {
4910
- return addLineWidget(this, handle, node, options);
4911
- }),
4912
-
4913
- removeLineWidget: function(widget) { widget.clear(); },
4914
-
4915
4950
  lineInfo: function(line) {
4916
4951
  if (typeof line == "number") {
4917
4952
  if (!isLine(this.doc, line)) return null;
@@ -5186,10 +5221,10 @@
5186
5221
  clearCaches(cm);
5187
5222
  regChange(cm);
5188
5223
  }, true);
5189
- option("specialChars", /[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, function(cm, val) {
5190
- cm.options.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
5191
- cm.refresh();
5192
- }, true);
5224
+ option("specialChars", /[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, function(cm, val, old) {
5225
+ cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
5226
+ if (old != CodeMirror.Init) cm.refresh();
5227
+ });
5193
5228
  option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function(cm) {cm.refresh();}, true);
5194
5229
  option("electricChars", true);
5195
5230
  option("inputStyle", mobile ? "contenteditable" : "textarea", function() {
@@ -6431,10 +6466,10 @@
6431
6466
 
6432
6467
  // Line widgets are block elements displayed above or below a line.
6433
6468
 
6434
- var LineWidget = CodeMirror.LineWidget = function(cm, node, options) {
6469
+ var LineWidget = CodeMirror.LineWidget = function(doc, node, options) {
6435
6470
  if (options) for (var opt in options) if (options.hasOwnProperty(opt))
6436
6471
  this[opt] = options[opt];
6437
- this.cm = cm;
6472
+ this.doc = doc;
6438
6473
  this.node = node;
6439
6474
  };
6440
6475
  eventMixin(LineWidget);
@@ -6445,52 +6480,55 @@
6445
6480
  }
6446
6481
 
6447
6482
  LineWidget.prototype.clear = function() {
6448
- var cm = this.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
6483
+ var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
6449
6484
  if (no == null || !ws) return;
6450
6485
  for (var i = 0; i < ws.length; ++i) if (ws[i] == this) ws.splice(i--, 1);
6451
6486
  if (!ws.length) line.widgets = null;
6452
6487
  var height = widgetHeight(this);
6453
- runInOp(cm, function() {
6488
+ updateLineHeight(line, Math.max(0, line.height - height));
6489
+ if (cm) runInOp(cm, function() {
6454
6490
  adjustScrollWhenAboveVisible(cm, line, -height);
6455
6491
  regLineChange(cm, no, "widget");
6456
- updateLineHeight(line, Math.max(0, line.height - height));
6457
6492
  });
6458
6493
  };
6459
6494
  LineWidget.prototype.changed = function() {
6460
- var oldH = this.height, cm = this.cm, line = this.line;
6495
+ var oldH = this.height, cm = this.doc.cm, line = this.line;
6461
6496
  this.height = null;
6462
6497
  var diff = widgetHeight(this) - oldH;
6463
6498
  if (!diff) return;
6464
- runInOp(cm, function() {
6499
+ updateLineHeight(line, line.height + diff);
6500
+ if (cm) runInOp(cm, function() {
6465
6501
  cm.curOp.forceUpdate = true;
6466
6502
  adjustScrollWhenAboveVisible(cm, line, diff);
6467
- updateLineHeight(line, line.height + diff);
6468
6503
  });
6469
6504
  };
6470
6505
 
6471
6506
  function widgetHeight(widget) {
6472
6507
  if (widget.height != null) return widget.height;
6508
+ var cm = widget.doc.cm;
6509
+ if (!cm) return 0;
6473
6510
  if (!contains(document.body, widget.node)) {
6474
6511
  var parentStyle = "position: relative;";
6475
6512
  if (widget.coverGutter)
6476
- parentStyle += "margin-left: -" + widget.cm.display.gutters.offsetWidth + "px;";
6513
+ parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;";
6477
6514
  if (widget.noHScroll)
6478
- parentStyle += "width: " + widget.cm.display.wrapper.clientWidth + "px;";
6479
- removeChildrenAndAdd(widget.cm.display.measure, elt("div", [widget.node], null, parentStyle));
6515
+ parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;";
6516
+ removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle));
6480
6517
  }
6481
6518
  return widget.height = widget.node.offsetHeight;
6482
6519
  }
6483
6520
 
6484
- function addLineWidget(cm, handle, node, options) {
6485
- var widget = new LineWidget(cm, node, options);
6486
- if (widget.noHScroll) cm.display.alignWidgets = true;
6487
- changeLine(cm.doc, handle, "widget", function(line) {
6521
+ function addLineWidget(doc, handle, node, options) {
6522
+ var widget = new LineWidget(doc, node, options);
6523
+ var cm = doc.cm;
6524
+ if (cm && widget.noHScroll) cm.display.alignWidgets = true;
6525
+ changeLine(doc, handle, "widget", function(line) {
6488
6526
  var widgets = line.widgets || (line.widgets = []);
6489
6527
  if (widget.insertAt == null) widgets.push(widget);
6490
6528
  else widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget);
6491
6529
  widget.line = line;
6492
- if (!lineIsHidden(cm.doc, line)) {
6493
- var aboveVisible = heightAtLine(line) < cm.doc.scrollTop;
6530
+ if (cm && !lineIsHidden(doc, line)) {
6531
+ var aboveVisible = heightAtLine(line) < doc.scrollTop;
6494
6532
  updateLineHeight(line, line.height + widgetHeight(widget));
6495
6533
  if (aboveVisible) addToScrollPos(cm, null, widget.height);
6496
6534
  cm.curOp.forceUpdate = true;
@@ -6710,7 +6748,9 @@
6710
6748
  // is needed on Webkit to be able to get line-level bounding
6711
6749
  // rectangles for it (in measureChar).
6712
6750
  var content = elt("span", null, null, webkit ? "padding-right: .1px" : null);
6713
- var builder = {pre: elt("pre", [content]), content: content, col: 0, pos: 0, cm: cm};
6751
+ var builder = {pre: elt("pre", [content]), content: content,
6752
+ col: 0, pos: 0, cm: cm,
6753
+ splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")};
6714
6754
  lineView.measure = {};
6715
6755
 
6716
6756
  // Iterate over the logical lines that make up this visual line.
@@ -6720,8 +6760,6 @@
6720
6760
  builder.addToken = buildToken;
6721
6761
  // Optionally wire in some hacks into the token-rendering
6722
6762
  // algorithm, to deal with browser quirks.
6723
- if ((ie || webkit) && cm.getOption("lineWrapping"))
6724
- builder.addToken = buildTokenSplitSpaces(builder.addToken);
6725
6763
  if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line)))
6726
6764
  builder.addToken = buildTokenBadBidi(builder.addToken, order);
6727
6765
  builder.map = [];
@@ -6770,10 +6808,11 @@
6770
6808
  // the line map. Takes care to render special characters separately.
6771
6809
  function buildToken(builder, text, style, startStyle, endStyle, title, css) {
6772
6810
  if (!text) return;
6773
- var special = builder.cm.options.specialChars, mustWrap = false;
6811
+ var displayText = builder.splitSpaces ? text.replace(/ {3,}/g, splitSpaces) : text;
6812
+ var special = builder.cm.state.specialChars, mustWrap = false;
6774
6813
  if (!special.test(text)) {
6775
6814
  builder.col += text.length;
6776
- var content = document.createTextNode(text);
6815
+ var content = document.createTextNode(displayText);
6777
6816
  builder.map.push(builder.pos, builder.pos + text.length, content);
6778
6817
  if (ie && ie_version < 9) mustWrap = true;
6779
6818
  builder.pos += text.length;
@@ -6784,7 +6823,7 @@
6784
6823
  var m = special.exec(text);
6785
6824
  var skipped = m ? m.index - pos : text.length - pos;
6786
6825
  if (skipped) {
6787
- var txt = document.createTextNode(text.slice(pos, pos + skipped));
6826
+ var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
6788
6827
  if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
6789
6828
  else content.appendChild(txt);
6790
6829
  builder.map.push(builder.pos, builder.pos + skipped, txt);
@@ -6821,22 +6860,17 @@
6821
6860
  builder.content.appendChild(content);
6822
6861
  }
6823
6862
 
6824
- function buildTokenSplitSpaces(inner) {
6825
- function split(old) {
6826
- var out = " ";
6827
- for (var i = 0; i < old.length - 2; ++i) out += i % 2 ? " " : "\u00a0";
6828
- out += " ";
6829
- return out;
6830
- }
6831
- return function(builder, text, style, startStyle, endStyle, title) {
6832
- inner(builder, text.replace(/ {3,}/g, split), style, startStyle, endStyle, title);
6833
- };
6863
+ function splitSpaces(old) {
6864
+ var out = " ";
6865
+ for (var i = 0; i < old.length - 2; ++i) out += i % 2 ? " " : "\u00a0";
6866
+ out += " ";
6867
+ return out;
6834
6868
  }
6835
6869
 
6836
6870
  // Work around nonsense dimensions being reported for stretches of
6837
6871
  // right-to-left text.
6838
6872
  function buildTokenBadBidi(inner, order) {
6839
- return function(builder, text, style, startStyle, endStyle, title) {
6873
+ return function(builder, text, style, startStyle, endStyle, title, css) {
6840
6874
  style = style ? style + " cm-force-border" : "cm-force-border";
6841
6875
  var start = builder.pos, end = start + text.length;
6842
6876
  for (;;) {
@@ -6845,8 +6879,8 @@
6845
6879
  var part = order[i];
6846
6880
  if (part.to > start && part.from <= start) break;
6847
6881
  }
6848
- if (part.to >= end) return inner(builder, text, style, startStyle, endStyle, title);
6849
- inner(builder, text.slice(0, part.to - start), style, startStyle, null, title);
6882
+ if (part.to >= end) return inner(builder, text, style, startStyle, endStyle, title, css);
6883
+ inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css);
6850
6884
  startStyle = null;
6851
6885
  text = text.slice(part.to - start);
6852
6886
  start = part.to;
@@ -7368,13 +7402,19 @@
7368
7402
  });
7369
7403
  }),
7370
7404
 
7405
+ addLineWidget: docMethodOp(function(handle, node, options) {
7406
+ return addLineWidget(this, handle, node, options);
7407
+ }),
7408
+ removeLineWidget: function(widget) { widget.clear(); },
7409
+
7371
7410
  markText: function(from, to, options) {
7372
7411
  return markText(this, clipPos(this, from), clipPos(this, to), options, "range");
7373
7412
  },
7374
7413
  setBookmark: function(pos, options) {
7375
7414
  var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
7376
7415
  insertLeft: options && options.insertLeft,
7377
- clearWhenEmpty: false, shared: options && options.shared};
7416
+ clearWhenEmpty: false, shared: options && options.shared,
7417
+ handleMouseEvents: options && options.handleMouseEvents};
7378
7418
  pos = clipPos(this, pos);
7379
7419
  return markText(this, pos, pos, realOpts, "bookmark");
7380
7420
  },
@@ -8639,7 +8679,7 @@
8639
8679
 
8640
8680
  // THE END
8641
8681
 
8642
- CodeMirror.version = "5.0.0";
8682
+ CodeMirror.version = "5.1.0";
8643
8683
 
8644
8684
  return CodeMirror;
8645
8685
  });
@@ -58,7 +58,9 @@
58
58
  if (inp) {
59
59
  if (options.value) {
60
60
  inp.value = options.value;
61
- inp.select();
61
+ if (options.selectValueOnOpen !== false) {
62
+ inp.select();
63
+ }
62
64
  }
63
65
 
64
66
  if (options.onInput)
@@ -9,29 +9,157 @@
9
9
  else // Plain browser env
10
10
  mod(CodeMirror);
11
11
  })(function(CodeMirror) {
12
- var DEFAULT_BRACKETS = "()[]{}''\"\"";
13
- var DEFAULT_TRIPLES = "'\"";
14
- var DEFAULT_EXPLODE_ON_ENTER = "[]{}";
15
- var SPACE_CHAR_REGEX = /\s/;
12
+ var defaults = {
13
+ pairs: "()[]{}''\"\"",
14
+ triples: "",
15
+ explode: "[]{}"
16
+ };
16
17
 
17
18
  var Pos = CodeMirror.Pos;
18
19
 
19
20
  CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
20
- if (old != CodeMirror.Init && old)
21
- cm.removeKeyMap("autoCloseBrackets");
22
- if (!val) return;
23
- var pairs = DEFAULT_BRACKETS, triples = DEFAULT_TRIPLES, explode = DEFAULT_EXPLODE_ON_ENTER;
24
- if (typeof val == "string") pairs = val;
25
- else if (typeof val == "object") {
26
- if (val.pairs != null) pairs = val.pairs;
27
- if (val.triples != null) triples = val.triples;
28
- if (val.explode != null) explode = val.explode;
21
+ if (old && old != CodeMirror.Init) {
22
+ cm.removeKeyMap(keyMap);
23
+ cm.state.closeBrackets = null;
24
+ }
25
+ if (val) {
26
+ cm.state.closeBrackets = val;
27
+ cm.addKeyMap(keyMap);
29
28
  }
30
- var map = buildKeymap(pairs, triples);
31
- if (explode) map.Enter = buildExplodeHandler(explode);
32
- cm.addKeyMap(map);
33
29
  });
34
30
 
31
+ function getOption(conf, name) {
32
+ if (name == "pairs" && typeof conf == "string") return conf;
33
+ if (typeof conf == "object" && conf[name] != null) return conf[name];
34
+ return defaults[name];
35
+ }
36
+
37
+ var bind = defaults.pairs + "`";
38
+ var keyMap = {Backspace: handleBackspace, Enter: handleEnter};
39
+ for (var i = 0; i < bind.length; i++)
40
+ keyMap["'" + bind.charAt(i) + "'"] = handler(bind.charAt(i));
41
+
42
+ function handler(ch) {
43
+ return function(cm) { return handleChar(cm, ch); };
44
+ }
45
+
46
+ function getConfig(cm) {
47
+ var deflt = cm.state.closeBrackets;
48
+ if (!deflt) return null;
49
+ var mode = cm.getModeAt(cm.getCursor());
50
+ return mode.closeBrackets || deflt;
51
+ }
52
+
53
+ function handleBackspace(cm) {
54
+ var conf = getConfig(cm);
55
+ if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
56
+
57
+ var pairs = getOption(conf, "pairs");
58
+ var ranges = cm.listSelections();
59
+ for (var i = 0; i < ranges.length; i++) {
60
+ if (!ranges[i].empty()) return CodeMirror.Pass;
61
+ var around = charsAround(cm, ranges[i].head);
62
+ if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
63
+ }
64
+ for (var i = ranges.length - 1; i >= 0; i--) {
65
+ var cur = ranges[i].head;
66
+ cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1));
67
+ }
68
+ }
69
+
70
+ function handleEnter(cm) {
71
+ var conf = getConfig(cm);
72
+ var explode = conf && getOption(conf, "explode");
73
+ if (!explode || cm.getOption("disableInput")) return CodeMirror.Pass;
74
+
75
+ var ranges = cm.listSelections();
76
+ for (var i = 0; i < ranges.length; i++) {
77
+ if (!ranges[i].empty()) return CodeMirror.Pass;
78
+ var around = charsAround(cm, ranges[i].head);
79
+ if (!around || explode.indexOf(around) % 2 != 0) return CodeMirror.Pass;
80
+ }
81
+ cm.operation(function() {
82
+ cm.replaceSelection("\n\n", null);
83
+ cm.execCommand("goCharLeft");
84
+ ranges = cm.listSelections();
85
+ for (var i = 0; i < ranges.length; i++) {
86
+ var line = ranges[i].head.line;
87
+ cm.indentLine(line, null, true);
88
+ cm.indentLine(line + 1, null, true);
89
+ }
90
+ });
91
+ }
92
+
93
+ function handleChar(cm, ch) {
94
+ var conf = getConfig(cm);
95
+ if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
96
+
97
+ var pairs = getOption(conf, "pairs");
98
+ var pos = pairs.indexOf(ch);
99
+ if (pos == -1) return CodeMirror.Pass;
100
+ var triples = getOption(conf, "triples");
101
+
102
+ var identical = pairs.charAt(pos + 1) == ch;
103
+ var ranges = cm.listSelections();
104
+ var opening = pos % 2 == 0;
105
+
106
+ var type, next;
107
+ for (var i = 0; i < ranges.length; i++) {
108
+ var range = ranges[i], cur = range.head, curType;
109
+ var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
110
+ if (opening && !range.empty()) {
111
+ curType = "surround";
112
+ } else if ((identical || !opening) && next == ch) {
113
+ if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == ch + ch + ch)
114
+ curType = "skipThree";
115
+ else
116
+ curType = "skip";
117
+ } else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 &&
118
+ cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch &&
119
+ (cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != ch)) {
120
+ curType = "addFour";
121
+ } else if (identical) {
122
+ if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, ch)) curType = "both";
123
+ else return CodeMirror.Pass;
124
+ } else if (opening && (cm.getLine(cur.line).length == cur.ch ||
125
+ isClosingBracket(next, pairs) ||
126
+ /\s/.test(next))) {
127
+ curType = "both";
128
+ } else {
129
+ return CodeMirror.Pass;
130
+ }
131
+ if (!type) type = curType;
132
+ else if (type != curType) return CodeMirror.Pass;
133
+ }
134
+
135
+ var left = pos % 2 ? pairs.charAt(pos - 1) : ch;
136
+ var right = pos % 2 ? ch : pairs.charAt(pos + 1);
137
+ cm.operation(function() {
138
+ if (type == "skip") {
139
+ cm.execCommand("goCharRight");
140
+ } else if (type == "skipThree") {
141
+ for (var i = 0; i < 3; i++)
142
+ cm.execCommand("goCharRight");
143
+ } else if (type == "surround") {
144
+ var sels = cm.getSelections();
145
+ for (var i = 0; i < sels.length; i++)
146
+ sels[i] = left + sels[i] + right;
147
+ cm.replaceSelections(sels, "around");
148
+ } else if (type == "both") {
149
+ cm.replaceSelection(left + right, null);
150
+ cm.execCommand("goCharLeft");
151
+ } else if (type == "addFour") {
152
+ cm.replaceSelection(left + left + left + left, "before");
153
+ cm.execCommand("goCharRight");
154
+ }
155
+ });
156
+ }
157
+
158
+ function isClosingBracket(ch, pairs) {
159
+ var pos = pairs.lastIndexOf(ch);
160
+ return pos > -1 && pos % 2 == 1;
161
+ }
162
+
35
163
  function charsAround(cm, pos) {
36
164
  var str = cm.getRange(Pos(pos.line, pos.ch - 1),
37
165
  Pos(pos.line, pos.ch + 1));
@@ -53,109 +181,4 @@
53
181
  stream.start = stream.pos;
54
182
  }
55
183
  }
56
-
57
- function buildKeymap(pairs, triples) {
58
- var map = {
59
- name : "autoCloseBrackets",
60
- Backspace: function(cm) {
61
- if (cm.getOption("disableInput")) return CodeMirror.Pass;
62
- var ranges = cm.listSelections();
63
- for (var i = 0; i < ranges.length; i++) {
64
- if (!ranges[i].empty()) return CodeMirror.Pass;
65
- var around = charsAround(cm, ranges[i].head);
66
- if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
67
- }
68
- for (var i = ranges.length - 1; i >= 0; i--) {
69
- var cur = ranges[i].head;
70
- cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1));
71
- }
72
- }
73
- };
74
- var closingBrackets = "";
75
- for (var i = 0; i < pairs.length; i += 2) (function(left, right) {
76
- closingBrackets += right;
77
- map["'" + left + "'"] = function(cm) {
78
- if (cm.getOption("disableInput")) return CodeMirror.Pass;
79
- var ranges = cm.listSelections(), type, next;
80
- for (var i = 0; i < ranges.length; i++) {
81
- var range = ranges[i], cur = range.head, curType;
82
- var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
83
- if (!range.empty()) {
84
- curType = "surround";
85
- } else if (left == right && next == right) {
86
- if (cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == left + left + left)
87
- curType = "skipThree";
88
- else
89
- curType = "skip";
90
- } else if (left == right && cur.ch > 1 && triples.indexOf(left) >= 0 &&
91
- cm.getRange(Pos(cur.line, cur.ch - 2), cur) == left + left &&
92
- (cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != left)) {
93
- curType = "addFour";
94
- } else if (left == '"' || left == "'") {
95
- if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, left)) curType = "both";
96
- else return CodeMirror.Pass;
97
- } else if (cm.getLine(cur.line).length == cur.ch || closingBrackets.indexOf(next) >= 0 || SPACE_CHAR_REGEX.test(next)) {
98
- curType = "both";
99
- } else {
100
- return CodeMirror.Pass;
101
- }
102
- if (!type) type = curType;
103
- else if (type != curType) return CodeMirror.Pass;
104
- }
105
-
106
- cm.operation(function() {
107
- if (type == "skip") {
108
- cm.execCommand("goCharRight");
109
- } else if (type == "skipThree") {
110
- for (var i = 0; i < 3; i++)
111
- cm.execCommand("goCharRight");
112
- } else if (type == "surround") {
113
- var sels = cm.getSelections();
114
- for (var i = 0; i < sels.length; i++)
115
- sels[i] = left + sels[i] + right;
116
- cm.replaceSelections(sels, "around");
117
- } else if (type == "both") {
118
- cm.replaceSelection(left + right, null);
119
- cm.execCommand("goCharLeft");
120
- } else if (type == "addFour") {
121
- cm.replaceSelection(left + left + left + left, "before");
122
- cm.execCommand("goCharRight");
123
- }
124
- });
125
- };
126
- if (left != right) map["'" + right + "'"] = function(cm) {
127
- var ranges = cm.listSelections();
128
- for (var i = 0; i < ranges.length; i++) {
129
- var range = ranges[i];
130
- if (!range.empty() ||
131
- cm.getRange(range.head, Pos(range.head.line, range.head.ch + 1)) != right)
132
- return CodeMirror.Pass;
133
- }
134
- cm.execCommand("goCharRight");
135
- };
136
- })(pairs.charAt(i), pairs.charAt(i + 1));
137
- return map;
138
- }
139
-
140
- function buildExplodeHandler(pairs) {
141
- return function(cm) {
142
- if (cm.getOption("disableInput")) return CodeMirror.Pass;
143
- var ranges = cm.listSelections();
144
- for (var i = 0; i < ranges.length; i++) {
145
- if (!ranges[i].empty()) return CodeMirror.Pass;
146
- var around = charsAround(cm, ranges[i].head);
147
- if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
148
- }
149
- cm.operation(function() {
150
- cm.replaceSelection("\n\n", null);
151
- cm.execCommand("goCharLeft");
152
- ranges = cm.listSelections();
153
- for (var i = 0; i < ranges.length; i++) {
154
- var line = ranges[i].head.line;
155
- cm.indentLine(line, null, true);
156
- cm.indentLine(line + 1, null, true);
157
- }
158
- });
159
- };
160
- }
161
184
  });