MCPcopy Create free account
hub / github.com/TruthHun/BookStack / maybeUpdateLineNumberWidth

Function maybeUpdateLineNumberWidth

static/mergely/lib/codemirror.js:606–622  ·  view source on GitHub ↗
(cm)

Source from the content-addressed store, hash-verified

604 // size for the current document size. Returns true when an update
605 // is needed.
606 function maybeUpdateLineNumberWidth(cm) {
607 if (!cm.options.lineNumbers) return false;
608 var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
609 if (last.length != display.lineNumChars) {
610 var test = display.measure.appendChild(elt("div", [elt("div", last)],
611 "CodeMirror-linenumber CodeMirror-gutter-elt"));
612 var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
613 display.lineGutter.style.width = "";
614 display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
615 display.lineNumWidth = display.lineNumInnerWidth + padding;
616 display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
617 display.lineGutter.style.width = display.lineNumWidth + "px";
618 updateGutterSpace(cm);
619 return true;
620 }
621 return false;
622 }
623
624 function lineNumberFor(options, i) {
625 return String(options.lineNumberFormatter(i + options.firstLineNumber));

Callers 2

CodeMirrorFunction · 0.70
updateDisplayIfNeededFunction · 0.70

Calls 3

lineNumberForFunction · 0.70
eltFunction · 0.70
updateGutterSpaceFunction · 0.70

Tested by

no test coverage detected