Clip buffer position in screenPositionForBufferPosition()

Closes #562
This commit is contained in:
Kevin Sawicki
2013-05-22 15:23:30 -07:00
parent 1dc49cfc70
commit d3cbd937fb
2 changed files with 8 additions and 1 deletions

View File

@@ -513,6 +513,13 @@ describe "DisplayBuffer", ->
expect(displayBuffer.clipScreenPosition([0, 1], skipAtomicTokens: true)).toEqual [0, tabLength]
expect(displayBuffer.clipScreenPosition([0, tabLength], skipAtomicTokens: true)).toEqual [0, tabLength]
describe ".screenPositionForBufferPosition(bufferPosition, options)", ->
it "clips the specified buffer position", ->
expect(displayBuffer.screenPositionForBufferPosition([0, 2])).toEqual [0, 2]
expect(displayBuffer.screenPositionForBufferPosition([0, 100000])).toEqual [0, 29]
expect(displayBuffer.screenPositionForBufferPosition([100000, 0])).toEqual [12, 2]
expect(displayBuffer.screenPositionForBufferPosition([100000, 100000])).toEqual [12, 2]
describe "position translation in the presence of hard tabs", ->
it "correctly translates positions on either side of a tab", ->
buffer.setText('\t')

View File

@@ -241,7 +241,7 @@ class DisplayBuffer
#
# Returns a {Point}.
screenPositionForBufferPosition: (bufferPosition, options) ->
{ row, column } = Point.fromObject(bufferPosition)
{ row, column } = @buffer.clipPosition(bufferPosition)
[startScreenRow, endScreenRow] = @rowMap.screenRowRangeForBufferRow(row)
for screenRow in [startScreenRow...endScreenRow]
screenLine = @screenLines[screenRow]