(line, builder, styles)
| 7079 | // Outputs a number of spans to make up a line, taking highlighting |
| 7080 | // and marked text into account. |
| 7081 | function insertLineContent(line, builder, styles) { |
| 7082 | var spans = line.markedSpans, allText = line.text, at = 0; |
| 7083 | if (!spans) { |
| 7084 | for (var i = 1; i < styles.length; i+=2) |
| 7085 | builder.addToken(builder, allText.slice(at, at = styles[i]), interpretTokenStyle(styles[i+1], builder.cm.options)); |
| 7086 | return; |
| 7087 | } |
| 7088 | |
| 7089 | var len = allText.length, pos = 0, i = 1, text = "", style, css; |
| 7090 | var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed; |
| 7091 | for (;;) { |
| 7092 | if (nextChange == pos) { // Update current marker set |
| 7093 | spanStyle = spanEndStyle = spanStartStyle = title = css = ""; |
| 7094 | collapsed = null; nextChange = Infinity; |
| 7095 | var foundBookmarks = [], endStyles |
| 7096 | for (var j = 0; j < spans.length; ++j) { |
| 7097 | var sp = spans[j], m = sp.marker; |
| 7098 | if (m.type == "bookmark" && sp.from == pos && m.widgetNode) { |
| 7099 | foundBookmarks.push(m); |
| 7100 | } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) { |
| 7101 | if (sp.to != null && sp.to != pos && nextChange > sp.to) { |
| 7102 | nextChange = sp.to; |
| 7103 | spanEndStyle = ""; |
| 7104 | } |
| 7105 | if (m.className) spanStyle += " " + m.className; |
| 7106 | if (m.css) css = (css ? css + ";" : "") + m.css; |
| 7107 | if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle; |
| 7108 | if (m.endStyle && sp.to == nextChange) (endStyles || (endStyles = [])).push(m.endStyle, sp.to) |
| 7109 | if (m.title && !title) title = m.title; |
| 7110 | if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0)) |
| 7111 | collapsed = sp; |
| 7112 | } else if (sp.from > pos && nextChange > sp.from) { |
| 7113 | nextChange = sp.from; |
| 7114 | } |
| 7115 | } |
| 7116 | if (endStyles) for (var j = 0; j < endStyles.length; j += 2) |
| 7117 | if (endStyles[j + 1] == nextChange) spanEndStyle += " " + endStyles[j] |
| 7118 | |
| 7119 | if (!collapsed || collapsed.from == pos) for (var j = 0; j < foundBookmarks.length; ++j) |
| 7120 | buildCollapsedSpan(builder, 0, foundBookmarks[j]); |
| 7121 | if (collapsed && (collapsed.from || 0) == pos) { |
| 7122 | buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos, |
| 7123 | collapsed.marker, collapsed.from == null); |
| 7124 | if (collapsed.to == null) return; |
| 7125 | if (collapsed.to == pos) collapsed = false; |
| 7126 | } |
| 7127 | } |
| 7128 | if (pos >= len) break; |
| 7129 | |
| 7130 | var upto = Math.min(len, nextChange); |
| 7131 | while (true) { |
| 7132 | if (text) { |
| 7133 | var end = pos + text.length; |
| 7134 | if (!collapsed) { |
| 7135 | var tokenText = end > upto ? text.slice(0, upto - pos) : text; |
| 7136 | builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle, |
| 7137 | spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css); |
| 7138 | } |
no test coverage detected