Merge pull request #1799 from atom/cj-calculate-invisibles-correctly

Calculate invisibles correctly
This commit is contained in:
Corey Johnson
2014-03-26 15:58:17 -07:00
2 changed files with 19 additions and 2 deletions

View File

@@ -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()

View File

@@ -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