mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Merge pull request #1799 from atom/cj-calculate-invisibles-correctly
Calculate invisibles correctly
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user