summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/addon/display
diff options
context:
space:
mode:
authorWu Cheng-Han2016-07-30 12:25:24 +0800
committerWu Cheng-Han2016-07-30 12:25:24 +0800
commit1490eafdd26a576dcc3832d1811802c0162dfe84 (patch)
treeabf105de4a0ec1659672643b7583330a421e79bb /public/vendor/codemirror/addon/display
parentb6ca8649af10d969d86f0e8ff31723321d43087a (diff)
Update CodeMirror to version 5.17.1
Diffstat (limited to 'public/vendor/codemirror/addon/display')
-rw-r--r--public/vendor/codemirror/addon/display/rulers.js38
1 files changed, 13 insertions, 25 deletions
diff --git a/public/vendor/codemirror/addon/display/rulers.js b/public/vendor/codemirror/addon/display/rulers.js
index 01f65667..73005447 100644
--- a/public/vendor/codemirror/addon/display/rulers.js
+++ b/public/vendor/codemirror/addon/display/rulers.js
@@ -11,30 +11,26 @@
})(function(CodeMirror) {
"use strict";
- CodeMirror.defineOption("rulers", false, function(cm, val, old) {
- if (old && old != CodeMirror.Init) {
- clearRulers(cm);
- cm.off("refresh", refreshRulers);
+ CodeMirror.defineOption("rulers", false, function(cm, val) {
+ if (cm.state.rulerDiv) {
+ cm.display.lineSpace.removeChild(cm.state.rulerDiv)
+ cm.state.rulerDiv = null
+ cm.off("refresh", drawRulers)
}
if (val && val.length) {
- setRulers(cm);
- cm.on("refresh", refreshRulers);
+ cm.state.rulerDiv = cm.display.lineSpace.insertBefore(document.createElement("div"), cm.display.cursorDiv)
+ cm.state.rulerDiv.className = "CodeMirror-rulers"
+ drawRulers(cm)
+ cm.on("refresh", drawRulers)
}
});
- function clearRulers(cm) {
- for (var i = cm.display.lineSpace.childNodes.length - 1; i >= 0; i--) {
- var node = cm.display.lineSpace.childNodes[i];
- if (/(^|\s)CodeMirror-ruler($|\s)/.test(node.className))
- node.parentNode.removeChild(node);
- }
- }
-
- function setRulers(cm) {
+ function drawRulers(cm) {
+ cm.state.rulerDiv.textContent = ""
var val = cm.getOption("rulers");
var cw = cm.defaultCharWidth();
var left = cm.charCoords(CodeMirror.Pos(cm.firstLine(), 0), "div").left;
- var minH = cm.display.scroller.offsetHeight + 30;
+ cm.state.rulerDiv.style.minHeight = (cm.display.scroller.offsetHeight + 30) + "px";
for (var i = 0; i < val.length; i++) {
var elt = document.createElement("div");
elt.className = "CodeMirror-ruler";
@@ -49,15 +45,7 @@
if (conf.width) elt.style.borderLeftWidth = conf.width;
}
elt.style.left = (left + col * cw) + "px";
- elt.style.top = "-50px";
- elt.style.bottom = "-20px";
- elt.style.minHeight = minH + "px";
- cm.display.lineSpace.insertBefore(elt, cm.display.cursorDiv);
+ cm.state.rulerDiv.appendChild(elt)
}
}
-
- function refreshRulers(cm) {
- clearRulers(cm);
- setRulers(cm);
- }
});