MCPcopy
hub / github.com/csev/py4e / buildLineElement

Function buildLineElement

tools/pythonauto/static/codemirror/codemirror.js:684–760  ·  view source on GitHub ↗
(cm, line, lineNo, dims, reuse)

Source from the content-addressed store, hash-verified

682 }
683
684 function buildLineElement(cm, line, lineNo, dims, reuse) {
685 var built = buildLineContent(cm, line), lineElement = built.pre;
686 var markers = line.gutterMarkers, display = cm.display, wrap;
687
688 var bgClass = built.bgClass ? built.bgClass + " " + (line.bgClass || "") : line.bgClass;
689 if (!cm.options.lineNumbers && !markers && !bgClass && !line.wrapClass && !line.widgets)
690 return lineElement;
691
692 // Lines with gutter elements, widgets or a background class need
693 // to be wrapped again, and have the extra elements added to the
694 // wrapper div
695
696 if (reuse) {
697 reuse.alignable = null;
698 var isOk = true, widgetsSeen = 0, insertBefore = null;
699 for (var n = reuse.firstChild, next; n; n = next) {
700 next = n.nextSibling;
701 if (!/\bCodeMirror-linewidget\b/.test(n.className)) {
702 reuse.removeChild(n);
703 } else {
704 for (var i = 0; i < line.widgets.length; ++i) {
705 var widget = line.widgets[i];
706 if (widget.node == n.firstChild) {
707 if (!widget.above && !insertBefore) insertBefore = n;
708 positionLineWidget(widget, n, reuse, dims);
709 ++widgetsSeen;
710 break;
711 }
712 }
713 if (i == line.widgets.length) { isOk = false; break; }
714 }
715 }
716 reuse.insertBefore(lineElement, insertBefore);
717 if (isOk && widgetsSeen == line.widgets.length) {
718 wrap = reuse;
719 reuse.className = line.wrapClass || "";
720 }
721 }
722 if (!wrap) {
723 wrap = elt("div", null, line.wrapClass, "position: relative");
724 wrap.appendChild(lineElement);
725 }
726 // Kludge to make sure the styled element lies behind the selection (by z-index)
727 if (bgClass)
728 wrap.insertBefore(elt("div", null, bgClass + " CodeMirror-linebackground"), wrap.firstChild);
729 if (cm.options.lineNumbers || markers) {
730 var gutterWrap = wrap.insertBefore(elt("div", null, "CodeMirror-gutter-wrapper", "position: absolute; left: " +
731 (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"),
732 lineElement);
733 if (cm.options.fixedGutter) (wrap.alignable || (wrap.alignable = [])).push(gutterWrap);
734 if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
735 wrap.lineNumber = gutterWrap.appendChild(
736 elt("div", lineNumberFor(cm.options, lineNo),
737 "CodeMirror-linenumber CodeMirror-gutter-elt",
738 "left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: "
739 + display.lineNumInnerWidth + "px"));
740 if (markers)
741 for (var k = 0; k < cm.options.gutters.length; ++k) {

Callers 1

patchDisplayFunction · 0.70

Calls 8

buildLineContentFunction · 0.70
positionLineWidgetFunction · 0.70
eltFunction · 0.70
lineNumberForFunction · 0.70
signalLaterFunction · 0.70
removeChildMethod · 0.45
insertBeforeMethod · 0.45
appendChildMethod · 0.45

Tested by

no test coverage detected