From d62ef599cd5f543d65e3e62163692696d3a2a687 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 18 Mar 2016 15:57:49 -0600 Subject: [PATCH] Replace tokens with tagCodes in DisplayLayer.prototype.getScreenLines --- src/lines-tile-component.coffee | 26 +++++++++++++------------- src/text-editor-presenter.coffee | 12 +++++++++++- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/lines-tile-component.coffee b/src/lines-tile-component.coffee index 03af7333b..a815c5be5 100644 --- a/src/lines-tile-component.coffee +++ b/src/lines-tile-component.coffee @@ -253,26 +253,26 @@ class LinesTileComponent @currentLineTextNodes.push(textNode) setLineInnerNodes: (id, lineNode) -> - {tokens} = @newTileState.lines[id] + {lineText, tagCodes} = @newTileState.lines[id] + lineLength = 0 + startIndex = 0 openScopeNode = lineNode - for token in tokens when token.text.length > 0 - {closeTags, openTags, text} = token - - for scope in closeTags + for tagCode in tagCodes when tagCode isnt 0 + if @presenter.isCloseTagCode(tagCode) openScopeNode = openScopeNode.parentElement - - for scope in openTags + else if @presenter.isOpenTagCode(tagCode) + scope = @presenter.tagForCode(tagCode) newScopeNode = @domElementPool.buildElement("span", scope.replace(/\.+/g, ' ')) openScopeNode.appendChild(newScopeNode) openScopeNode = newScopeNode + else + textNode = @domElementPool.buildText(lineText.substr(startIndex, tagCode).replace(/\s/g, NBSPCharacter)) + startIndex += tagCode + openScopeNode.appendChild(textNode) + @currentLineTextNodes.push(textNode) - lineLength += text.length - textNode = @domElementPool.buildText(text.replace(/\s/g, NBSPCharacter)) - openScopeNode.appendChild(textNode) - @currentLineTextNodes.push(textNode) - - if lineLength is 0 + if startIndex is 0 textNode = @domElementPool.buildText(NBSPCharacter) lineNode.appendChild(textNode) @currentLineTextNodes.push(textNode) diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 9ff1e5970..3d69606aa 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -436,7 +436,8 @@ class TextEditorPresenter else tileState.lines[line.id] = screenRow: screenRow - tokens: line.tokens + lineText: line.lineText + tagCodes: line.tagCodes decorationClasses: @lineDecorationClassesForRow(screenRow) precedingBlockDecorations: precedingBlockDecorations followingBlockDecorations: followingBlockDecorations @@ -1548,3 +1549,12 @@ class TextEditorPresenter isRowVisible: (row) -> @startRow <= row < @endRow + + isOpenTagCode: (tagCode) -> + @displayLayer.isOpenTagCode(tagCode) + + isCloseTagCode: (tagCode) -> + @displayLayer.isCloseTagCode(tagCode) + + tagForCode: (tagCode) -> + @displayLayer.tagForCode(tagCode)