-
-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathgutters.js
34 lines (31 loc) · 1.23 KB
/
gutters.js
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
import { elt, removeChildren } from "../util/dom"
import { indexOf } from "../util/misc"
import { updateGutterSpace } from "./update_display"
// Rebuild the gutter elements, ensure the margin to the left of the
// code matches their width.
export function updateGutters(cm) {
let gutters = cm.display.gutters, specs = cm.options.gutters
removeChildren(gutters)
let i = 0
for (; i < specs.length; ++i) {
let gutterClass = specs[i]
let gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass))
if (gutterClass == "CodeMirror-linenumbers") {
cm.display.lineGutter = gElt
gElt.style.width = (cm.display.lineNumWidth || 1) + "px"
}
}
gutters.style.display = i ? "" : "none"
updateGutterSpace(cm)
}
// Make sure the gutters options contains the element
// "CodeMirror-linenumbers" when the lineNumbers option is true.
export function setGuttersForLineNumbers(options) {
let found = indexOf(options.gutters, "CodeMirror-linenumbers")
if (found == -1 && options.lineNumbers) {
options.gutters = options.gutters.concat(["CodeMirror-linenumbers"])
} else if (found > -1 && !options.lineNumbers) {
options.gutters = options.gutters.slice(0)
options.gutters.splice(found, 1)
}
}