From c13b90b6b674597dcdcf6e2d09a8de8705227b05 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 21 Feb 2012 09:46:30 -0700 Subject: [PATCH] Back LineWrapper.bufferPositionForScreenPosition with LineMap Also rename From -> For --- spec/atom/line-wrapper-spec.coffee | 12 ++++++------ src/atom/editor.coffee | 2 +- src/atom/line-wrapper.coffee | 8 ++------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/spec/atom/line-wrapper-spec.coffee b/spec/atom/line-wrapper-spec.coffee index 76467b249..c456d4d8d 100644 --- a/spec/atom/line-wrapper-spec.coffee +++ b/spec/atom/line-wrapper-spec.coffee @@ -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...) -> diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 9896c796b..7a40b34bb 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -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 diff --git a/src/atom/line-wrapper.coffee b/src/atom/line-wrapper.coffee index 81615c2f6..79353eb70 100644 --- a/src/atom/line-wrapper.coffee +++ b/src/atom/line-wrapper.coffee @@ -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]