MCPcopy Index your code
hub / github.com/ronreiter/interactive-tutorials / insertLineContent

Function insertLineContent

static/js/codemirror/codemirror.js:4066–4122  ·  view source on GitHub ↗
(line, builder, styles)

Source from the content-addressed store, hash-verified

4064 // Outputs a number of spans to make up a line, taking highlighting
4065 // and marked text into account.
4066 function insertLineContent(line, builder, styles) {
4067 var spans = line.markedSpans;
4068 if (!spans) {
4069 for (var i = 1; i < styles.length; i+=2)
4070 builder.addToken(builder, styles[i], styleToClass(styles[i+1]));
4071 return;
4072 }
4073
4074 var allText = line.text, len = allText.length;
4075 var pos = 0, i = 1, text = "", style;
4076 var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, collapsed;
4077 for (;;) {
4078 if (nextChange == pos) { // Update current marker set
4079 spanStyle = spanEndStyle = spanStartStyle = "";
4080 collapsed = null; nextChange = Infinity;
4081 var foundBookmark = null;
4082 for (var j = 0; j < spans.length; ++j) {
4083 var sp = spans[j], m = sp.marker;
4084 if (sp.from <= pos && (sp.to == null || sp.to > pos)) {
4085 if (sp.to != null && nextChange > sp.to) { nextChange = sp.to; spanEndStyle = ""; }
4086 if (m.className) spanStyle += " " + m.className;
4087 if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle;
4088 if (m.endStyle && sp.to == nextChange) spanEndStyle += " " + m.endStyle;
4089 if (m.collapsed && (!collapsed || collapsed.marker.width < m.width))
4090 collapsed = sp;
4091 } else if (sp.from > pos && nextChange > sp.from) {
4092 nextChange = sp.from;
4093 }
4094 if (m.type == "bookmark" && sp.from == pos && m.replacedWith)
4095 foundBookmark = m.replacedWith;
4096 }
4097 if (collapsed && (collapsed.from || 0) == pos) {
4098 buildCollapsedSpan(builder, (collapsed.to == null ? len : collapsed.to) - pos,
4099 collapsed.from != null && collapsed.marker.replacedWith);
4100 if (collapsed.to == null) return collapsed.marker.find();
4101 }
4102 if (foundBookmark && !collapsed) buildCollapsedSpan(builder, 0, foundBookmark);
4103 }
4104 if (pos >= len) break;
4105
4106 var upto = Math.min(len, nextChange);
4107 while (true) {
4108 if (text) {
4109 var end = pos + text.length;
4110 if (!collapsed) {
4111 var tokenText = end > upto ? text.slice(0, upto - pos) : text;
4112 builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
4113 spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "");
4114 }
4115 if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
4116 pos = end;
4117 spanStartStyle = "";
4118 }
4119 text = styles[i++]; style = styleToClass(styles[i++]);
4120 }
4121 }
4122 }
4123

Callers 1

lineContentFunction · 0.85

Calls 3

styleToClassFunction · 0.85
buildCollapsedSpanFunction · 0.85
findMethod · 0.45

Tested by

no test coverage detected