Back LineWrapper.bufferPositionForScreenPosition with LineMap

Also rename From -> For
This commit is contained in:
Nathan Sobo
2012-02-21 09:46:30 -07:00
parent ba506fcd45
commit c13b90b6b6
3 changed files with 9 additions and 13 deletions

View File

@@ -122,18 +122,18 @@ describe "LineWrapper", ->
it "translates a position at the end of a wrapped screen line to the begining of the next screen line", ->
expect(wrapper.screenPositionForBufferPosition([3, 51], true)).toEqual([4, 0])
describe ".bufferPositionFromScreenPosition(point)", ->
describe ".bufferPositionForScreenPosition(point)", ->
it "translates the given screen position to a buffer position, account for wrapped lines", ->
# before any wrapped lines
expect(wrapper.bufferPositionFromScreenPosition([0, 5])).toEqual([0, 5])
expect(wrapper.bufferPositionForScreenPosition([0, 5])).toEqual([0, 5])
# on a wrapped line
expect(wrapper.bufferPositionFromScreenPosition([3, 5])).toEqual([3, 5])
expect(wrapper.bufferPositionFromScreenPosition([4, 0])).toEqual([3, 51])
expect(wrapper.bufferPositionFromScreenPosition([4, 5])).toEqual([3, 56])
expect(wrapper.bufferPositionForScreenPosition([3, 5])).toEqual([3, 5])
expect(wrapper.bufferPositionForScreenPosition([4, 0])).toEqual([3, 51])
expect(wrapper.bufferPositionForScreenPosition([4, 5])).toEqual([3, 56])
# following a wrapped line
expect(wrapper.bufferPositionFromScreenPosition([5, 5])).toEqual([4, 5])
expect(wrapper.bufferPositionForScreenPosition([5, 5])).toEqual([4, 5])
describe ".wrapScreenLine(screenLine)", ->
makeTokens = (tokenValues...) ->

View File

@@ -214,7 +214,7 @@ class Editor extends View
pointFromPixelPosition: ({top, left}) ->
screenPosition = new Point(Math.floor(top / @lineHeight), Math.floor(left / @charWidth))
@lineWrapper.bufferPositionFromScreenPosition screenPosition
@lineWrapper.bufferPositionForScreenPosition screenPosition
pointFromMouseEvent: (e) ->
{ pageX, pageY } = e

View File

@@ -108,12 +108,8 @@ class LineWrapper
screenPositionForBufferPosition: (bufferPosition, eagerWrap=true) ->
@lineMap.screenPositionForBufferPosition(bufferPosition, eagerWrap)
bufferPositionFromScreenPosition: (screenPosition) ->
screenPosition = Point.fromObject(screenPosition)
{ index, offset } = @index.indexForSpan(screenPosition.row)
row = index
column = @index.at(row).screenLines[offset].startColumn + screenPosition.column
new Point(row, column)
bufferPositionForScreenPosition: (screenPosition) ->
@lineMap.bufferPositionForScreenPosition(screenPosition)
screenLineForRow: (screenRow) ->
@screenLinesForRows(screenRow, screenRow)[0]