diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index 26c52dbb5..ab3b1a99d 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -2894,6 +2894,20 @@ describe "EditorView", -> for rowNumber in [1..5] expect(editorView.lineElementForScreenRow(rowNumber).text()).toBe buffer.lineForRow(rowNumber) + it "correctly calculates the position left for non-monospaced invisibles", -> + editorView.setShowInvisibles(true) + editorView.setInvisibles tab: '♘' + editor.setText('\tx') + + editorView.setFontFamily('serif') + editorView.setFontSize(10) + editorView.attachToDom() + editorView.setWidthInChars(5) + + expect(editorView.pixelPositionForScreenPosition([0, 0]).left).toEqual 0 + expect(editorView.pixelPositionForScreenPosition([0, 1]).left).toEqual 10 + expect(editorView.pixelPositionForScreenPosition([0, 2]).left).toEqual 13 + describe "when the window is resized", -> it "updates the active edit session with the current soft wrap column", -> editorView.attachToDom() diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 2a28b6d83..2be2aca2a 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -1338,14 +1338,17 @@ class EditorView extends View return 0 if screenColumn == 0 tokenizedLine = @editor.displayBuffer.lineForRow(screenRow) + textContent = lineElement.textContent left = 0 index = 0 for token in tokenizedLine.tokens - for char in token.value + for bufferChar in token.value return left if index >= screenColumn - val = @getCharacterWidthCache(token.scopes, char) + # Invisibles might cause renderedChar to be different than bufferChar + renderedChar = textContent[index] + val = @getCharacterWidthCache(token.scopes, renderedChar) if val? left += val else