MCPcopy Create free account
hub / github.com/breck7/scroll / buildToken

Function buildToken

external/.scrollLibs.js:2910–2994  ·  view source on GitHub ↗
(builder, text, style, startStyle, endStyle, css, attributes)

Source from the content-addressed store, hash-verified

2908 // Build up the DOM representation for a single token, and add it to
2909 // the line map. Takes care to render special characters separately.
2910 function buildToken(builder, text, style, startStyle, endStyle, css, attributes) {
2911 if (!text) {
2912 return
2913 }
2914 var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text
2915 var special = builder.cm.state.specialChars,
2916 mustWrap = false
2917 var content
2918 if (!special.test(text)) {
2919 builder.col += text.length
2920 content = document.createTextNode(displayText)
2921 builder.map.push(builder.pos, builder.pos + text.length, content)
2922 if (ie && ie_version < 9) {
2923 mustWrap = true
2924 }
2925 builder.pos += text.length
2926 } else {
2927 content = document.createDocumentFragment()
2928 var pos = 0
2929 while (true) {
2930 special.lastIndex = pos
2931 var m = special.exec(text)
2932 var skipped = m ? m.index - pos : text.length - pos
2933 if (skipped) {
2934 var txt = document.createTextNode(displayText.slice(pos, pos + skipped))
2935 if (ie && ie_version < 9) {
2936 content.appendChild(elt("span", [txt]))
2937 } else {
2938 content.appendChild(txt)
2939 }
2940 builder.map.push(builder.pos, builder.pos + skipped, txt)
2941 builder.col += skipped
2942 builder.pos += skipped
2943 }
2944 if (!m) {
2945 break
2946 }
2947 pos += skipped + 1
2948 var txt$1 = void 0
2949 if (m[0] == "\t") {
2950 var tabSize = builder.cm.options.tabSize,
2951 tabWidth = tabSize - (builder.col % tabSize)
2952 txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"))
2953 txt$1.setAttribute("role", "presentation")
2954 txt$1.setAttribute("cm-text", "\t")
2955 builder.col += tabWidth
2956 } else if (m[0] == "\r" || m[0] == "\n") {
2957 txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"))
2958 txt$1.setAttribute("cm-text", m[0])
2959 builder.col += 1
2960 } else {
2961 txt$1 = builder.cm.options.specialCharPlaceholder(m[0])
2962 txt$1.setAttribute("cm-text", m[0])
2963 if (ie && ie_version < 9) {
2964 content.appendChild(elt("span", [txt$1]))
2965 } else {
2966 content.appendChild(txt$1)
2967 }

Callers

nothing calls this directly

Calls 4

splitSpacesFunction · 0.85
eltFunction · 0.85
spaceStrFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected