(line, builder, styles)
| 7107 | // Outputs a number of spans to make up a line, taking highlighting |
| 7108 | // and marked text into account. |
| 7109 | function insertLineContent(line, builder, styles) { |
| 7110 | var spans = line.markedSpans, allText = line.text, at = 0; |
| 7111 | if (!spans) { |
| 7112 | for (var i = 1; i < styles.length; i+=2) |
| 7113 | builder.addToken(builder, allText.slice(at, at = styles[i]), interpretTokenStyle(styles[i+1], builder.cm.options)); |
| 7114 | return; |
| 7115 | } |
| 7116 | |
| 7117 | var len = allText.length, pos = 0, i = 1, text = "", style, css; |
| 7118 | var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed; |
| 7119 | for (;;) { |
| 7120 | if (nextChange == pos) { // Update current marker set |
| 7121 | spanStyle = spanEndStyle = spanStartStyle = title = css = ""; |
| 7122 | collapsed = null; nextChange = Infinity; |
| 7123 | var foundBookmarks = [], endStyles |
| 7124 | for (var j = 0; j < spans.length; ++j) { |
| 7125 | var sp = spans[j], m = sp.marker; |
| 7126 | if (m.type == "bookmark" && sp.from == pos && m.widgetNode) { |
| 7127 | foundBookmarks.push(m); |
| 7128 | } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) { |
| 7129 | if (sp.to != null && sp.to != pos && nextChange > sp.to) { |
| 7130 | nextChange = sp.to; |
| 7131 | spanEndStyle = ""; |
| 7132 | } |
| 7133 | if (m.className) spanStyle += " " + m.className; |
| 7134 | if (m.css) css = (css ? css + ";" : "") + m.css; |
| 7135 | if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle; |
| 7136 | if (m.endStyle && sp.to == nextChange) (endStyles || (endStyles = [])).push(m.endStyle, sp.to) |
| 7137 | if (m.title && !title) title = m.title; |
| 7138 | if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0)) |
| 7139 | collapsed = sp; |
| 7140 | } else if (sp.from > pos && nextChange > sp.from) { |
| 7141 | nextChange = sp.from; |
| 7142 | } |
| 7143 | } |
| 7144 | if (endStyles) for (var j = 0; j < endStyles.length; j += 2) |
| 7145 | if (endStyles[j + 1] == nextChange) spanEndStyle += " " + endStyles[j] |
| 7146 | |
| 7147 | if (!collapsed || collapsed.from == pos) for (var j = 0; j < foundBookmarks.length; ++j) |
| 7148 | buildCollapsedSpan(builder, 0, foundBookmarks[j]); |
| 7149 | if (collapsed && (collapsed.from || 0) == pos) { |
| 7150 | buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos, |
| 7151 | collapsed.marker, collapsed.from == null); |
| 7152 | if (collapsed.to == null) return; |
| 7153 | if (collapsed.to == pos) collapsed = false; |
| 7154 | } |
| 7155 | } |
| 7156 | if (pos >= len) break; |
| 7157 | |
| 7158 | var upto = Math.min(len, nextChange); |
| 7159 | while (true) { |
| 7160 | if (text) { |
| 7161 | var end = pos + text.length; |
| 7162 | if (!collapsed) { |
| 7163 | var tokenText = end > upto ? text.slice(0, upto - pos) : text; |
| 7164 | builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle, |
| 7165 | spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css); |
| 7166 | } |
no test coverage detected