mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
TokenizedLine::screenColumnForBufferColumn calculates more accurately
screenColumnForBufferColumn used to break only if the current column was strictly greater than the target column. This commit changes it so it breaks when greater or equal, which is how bufferColumnForScreenColumn works. This also adds some unit tests for screenColumnForBufferColumn's interactions with hard tab characters.
This commit is contained in:
@@ -719,6 +719,14 @@ describe "DisplayBuffer", ->
|
||||
expect(displayBuffer.screenPositionForBufferPosition([100000, 0])).toEqual [12, 2]
|
||||
expect(displayBuffer.screenPositionForBufferPosition([100000, 100000])).toEqual [12, 2]
|
||||
|
||||
it "clips to the (left or right) edge of an atomic token without simply rounding up", ->
|
||||
tabLength = 4
|
||||
displayBuffer.setTabLength(tabLength)
|
||||
|
||||
buffer.insert([0, 0], '\t')
|
||||
expect(displayBuffer.screenPositionForBufferPosition([0, 0])).toEqual [0, 0]
|
||||
expect(displayBuffer.screenPositionForBufferPosition([0, 1])).toEqual [0, tabLength]
|
||||
|
||||
describe "position translation in the presence of hard tabs", ->
|
||||
it "correctly translates positions on either side of a tab", ->
|
||||
buffer.setText('\t')
|
||||
|
||||
@@ -67,7 +67,7 @@ class TokenizedLine
|
||||
screenColumn = 0
|
||||
currentBufferColumn = 0
|
||||
for token in @tokens
|
||||
break if currentBufferColumn > bufferColumn
|
||||
break if currentBufferColumn + token.bufferDelta > bufferColumn
|
||||
screenColumn += token.screenDelta
|
||||
currentBufferColumn += token.bufferDelta
|
||||
@clipScreenColumn(screenColumn + (bufferColumn - currentBufferColumn))
|
||||
|
||||
Reference in New Issue
Block a user