MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / insertLineContent

Function insertLineContent

lib/web/CodeMirror/src/line/line_data.js:250–323  ·  view source on GitHub ↗
(line, builder, styles)

Source from the content-addressed store, hash-verified

248// Outputs a number of spans to make up a line, taking highlighting
249// and marked text into account.
250function insertLineContent(line, builder, styles) {
251 let spans = line.markedSpans, allText = line.text, at = 0
252 if (!spans) {
253 for (let i = 1; i < styles.length; i+=2)
254 builder.addToken(builder, allText.slice(at, at = styles[i]), interpretTokenStyle(styles[i+1], builder.cm.options))
255 return
256 }
257
258 let len = allText.length, pos = 0, i = 1, text = "", style, css
259 let nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, collapsed, attributes
260 for (;;) {
261 if (nextChange == pos) { // Update current marker set
262 spanStyle = spanEndStyle = spanStartStyle = css = ""
263 attributes = null
264 collapsed = null; nextChange = Infinity
265 let foundBookmarks = [], endStyles
266 for (let j = 0; j < spans.length; ++j) {
267 let sp = spans[j], m = sp.marker
268 if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
269 foundBookmarks.push(m)
270 } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
271 if (sp.to != null && sp.to != pos && nextChange > sp.to) {
272 nextChange = sp.to
273 spanEndStyle = ""
274 }
275 if (m.className) spanStyle += " " + m.className
276 if (m.css) css = (css ? css + ";" : "") + m.css
277 if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle
278 if (m.endStyle && sp.to == nextChange) (endStyles || (endStyles = [])).push(m.endStyle, sp.to)
279 // support for the old title property
280 // https://github.com/codemirror/CodeMirror/pull/5673
281 if (m.title) (attributes || (attributes = {})).title = m.title
282 if (m.attributes) {
283 for (let attr in m.attributes)
284 (attributes || (attributes = {}))[attr] = m.attributes[attr]
285 }
286 if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
287 collapsed = sp
288 } else if (sp.from > pos && nextChange > sp.from) {
289 nextChange = sp.from
290 }
291 }
292 if (endStyles) for (let j = 0; j < endStyles.length; j += 2)
293 if (endStyles[j + 1] == nextChange) spanEndStyle += " " + endStyles[j]
294
295 if (!collapsed || collapsed.from == pos) for (let j = 0; j < foundBookmarks.length; ++j)
296 buildCollapsedSpan(builder, 0, foundBookmarks[j])
297 if (collapsed && (collapsed.from || 0) == pos) {
298 buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
299 collapsed.marker, collapsed.from == null)
300 if (collapsed.to == null) return
301 if (collapsed.to == pos) collapsed = false
302 }
303 }
304 if (pos >= len) break
305
306 let upto = Math.min(len, nextChange)
307 while (true) {

Callers 1

buildLineContentFunction · 0.70

Calls 5

compareCollapsedMarkersFunction · 0.90
interpretTokenStyleFunction · 0.70
buildCollapsedSpanFunction · 0.70
pushMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected