MCPcopy Create free account
hub / github.com/breck7/scroll / buildLineContent

Function buildLineContent

external/.scrollLibs.js:2839–2899  ·  view source on GitHub ↗
(cm, lineView)

Source from the content-addressed store, hash-verified

2837 // The returned object contains the DOM node, this map, and
2838 // information about line-wide styles that were set by the mode.
2839 function buildLineContent(cm, lineView) {
2840 // The padding-right forces the element to have a 'border', which
2841 // is needed on Webkit to be able to get line-level bounding
2842 // rectangles for it (in measureChar).
2843 var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null)
2844 var builder = { pre: eltP("pre", [content], "CodeMirror-line"), content: content, col: 0, pos: 0, cm: cm, trailingSpace: false, splitSpaces: cm.getOption("lineWrapping") }
2845 lineView.measure = {}
2846
2847 // Iterate over the logical lines that make up this visual line.
2848 for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
2849 var line = i ? lineView.rest[i - 1] : lineView.line,
2850 order = void 0
2851 builder.pos = 0
2852 builder.addToken = buildToken
2853 // Optionally wire in some hacks into the token-rendering
2854 // algorithm, to deal with browser quirks.
2855 if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction))) {
2856 builder.addToken = buildTokenBadBidi(builder.addToken, order)
2857 }
2858 builder.map = []
2859 var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line)
2860 insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate))
2861 if (line.styleClasses) {
2862 if (line.styleClasses.bgClass) {
2863 builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "")
2864 }
2865 if (line.styleClasses.textClass) {
2866 builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "")
2867 }
2868 }
2869
2870 // Ensure at least a single node is present, for measuring.
2871 if (builder.map.length == 0) {
2872 builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure)))
2873 }
2874
2875 // Store the map and a cache object for the current logical line
2876 if (i == 0) {
2877 lineView.measure.map = builder.map
2878 lineView.measure.cache = {}
2879 } else {
2880 ;(lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map)
2881 ;(lineView.measure.caches || (lineView.measure.caches = [])).push({})
2882 }
2883 }
2884
2885 // See issue #2901
2886 if (webkit) {
2887 var last = builder.content.lastChild
2888 if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab"))) {
2889 builder.content.className = "cm-tab-wrap-hack"
2890 }
2891 }
2892
2893 signal(cm, "renderLine", cm, lineView.line, builder.pre)
2894 if (builder.pre.className) {
2895 builder.textClass = joinClasses(builder.pre.className, builder.textClass || "")
2896 }

Callers 2

getLineContentFunction · 0.85

Calls 10

eltPFunction · 0.85
hasBadBidiRectsFunction · 0.85
buildTokenBadBidiFunction · 0.85
lineNoFunction · 0.85
insertLineContentFunction · 0.85
getLineStylesFunction · 0.85
joinClassesFunction · 0.85
zeroWidthElementFunction · 0.85
signalFunction · 0.85
getOrderFunction · 0.70

Tested by

no test coverage detected