 
       if tokenText.length > MaxTokenLength
         while startIndex < endIndex
-          text = @sliceText(tokenText, startIndex, startIndex + MaxTokenLength)
-          scopeNode.appendChild(@domElementPool.buildElement("span", null, text))
+          textNode = @domElementPool.buildText(
+            @sliceText(tokenText, startIndex, startIndex + MaxTokenLength)
+          )
+          textSpan = @domElementPool.buildElement("span")
+
+          textSpan.appendChild(textNode)
+          scopeNode.appendChild(textSpan)
           startIndex += MaxTokenLength
       else
-        scopeNode.insertAdjacentText("beforeend", @sliceText(tokenText, startIndex, endIndex))
+        scopeNode.appendChild(
+          @domElementPool.buildText(@sliceText(tokenText, startIndex, endIndex))
+        )
 
       scopeNode.appendChild(trailingWhitespaceNode) if trailingWhitespaceNode?
 

        indentGuide = @domElementPool.buildElement("span", "indent-guide")
        for j in [0...tabLength]
          if invisible = endOfLineInvisibles?[invisibleIndex++]
            indentGuide.appendChild(
              @domElementPool.buildElement("span", "invisible-character", invisible)
            )
          else
            indentGuide.insertAdjacentText("beforeend", " ")
        lineNode.appendChild(indentGuide)

      while invisibleIndex < endOfLineInvisibles?.length
        invisible = endOfLineInvisibles[invisibleIndex++]
        lineNode.appendChild(
          @domElementPool.buildElement("span", "invisible-character", invisible)
        )
    else
      unless @appendEndOfLineNodes(id, lineNode)
        lineNode.textContent = "\u00a0"

  setLineInnerNodes: (id, lineNode) ->
    lineState = @newTileState.lines[id]

      trailingWhitespaceNode = null

      if firstNonWhitespaceIndex?
        leadingWhitespaceNode = @domElementPool.buildElement("span", "leading-whitespace")
        leadingWhitespaceNode.classList.add("indent-guide") if hasIndentGuide
        leadingWhitespaceNode.classList.add("invisible-character") if hasInvisibleCharacters
        leadingWhitespaceNode.appendChild(
          @domElementPool.buildText(tokenText.substring(0, firstNonWhitespaceIndex))
        )

        startIndex = firstNonWhitespaceIndex

      if firstTrailingWhitespaceIndex?
        tokenIsOnlyWhitespace = firstTrailingWhitespaceIndex is 0

        trailingWhitespaceNode = @domElementPool.buildElement("span", "trailing-whitespace")
        trailingWhitespaceNode.classList.add("indent-guide") if hasIndentGuide and not firstNonWhitespaceIndex? and tokenIsOnlyWhitespace
        trailingWhitespaceNode.classList.add("invisible-character") if hasInvisibleCharacters
        trailingWhitespaceNode.appendChild(
          @domElementPool.buildText(tokenText.substring(firstTrailingWhitespaceIndex))
        )

        endIndex = firstTrailingWhitespaceIndex

