(cm, lineView)
| 61 | // The returned object contains the DOM node, this map, and |
| 62 | // information about line-wide styles that were set by the mode. |
| 63 | export function buildLineContent(cm, lineView) { |
| 64 | // The padding-right forces the element to have a 'border', which |
| 65 | // is needed on Webkit to be able to get line-level bounding |
| 66 | // rectangles for it (in measureChar). |
| 67 | let content = eltP("span", null, null, webkit ? "padding-right: .1px" : null) |
| 68 | let builder = {pre: eltP("pre", [content], "CodeMirror-line"), content: content, |
| 69 | col: 0, pos: 0, cm: cm, |
| 70 | trailingSpace: false, |
| 71 | splitSpaces: cm.getOption("lineWrapping")} |
| 72 | lineView.measure = {} |
| 73 | |
| 74 | // Iterate over the logical lines that make up this visual line. |
| 75 | for (let i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) { |
| 76 | let line = i ? lineView.rest[i - 1] : lineView.line, order |
| 77 | builder.pos = 0 |
| 78 | builder.addToken = buildToken |
| 79 | // Optionally wire in some hacks into the token-rendering |
| 80 | // algorithm, to deal with browser quirks. |
| 81 | if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction))) |
| 82 | builder.addToken = buildTokenBadBidi(builder.addToken, order) |
| 83 | builder.map = [] |
| 84 | let allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line) |
| 85 | insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate)) |
| 86 | if (line.styleClasses) { |
| 87 | if (line.styleClasses.bgClass) |
| 88 | builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "") |
| 89 | if (line.styleClasses.textClass) |
| 90 | builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "") |
| 91 | } |
| 92 | |
| 93 | // Ensure at least a single node is present, for measuring. |
| 94 | if (builder.map.length == 0) |
| 95 | builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))) |
| 96 | |
| 97 | // Store the map and a cache object for the current logical line |
| 98 | if (i == 0) { |
| 99 | lineView.measure.map = builder.map |
| 100 | lineView.measure.cache = {} |
| 101 | } else { |
| 102 | ;(lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map) |
| 103 | ;(lineView.measure.caches || (lineView.measure.caches = [])).push({}) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // See issue #2901 |
| 108 | if (webkit) { |
| 109 | let last = builder.content.lastChild |
| 110 | if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab"))) |
| 111 | builder.content.className = "cm-tab-wrap-hack" |
| 112 | } |
| 113 | |
| 114 | signal(cm, "renderLine", cm, lineView.line, builder.pre) |
| 115 | if (builder.pre.className) |
| 116 | builder.textClass = joinClasses(builder.pre.className, builder.textClass || "") |
| 117 | |
| 118 | return builder |
| 119 | } |
| 120 |
no test coverage detected