From bb72c839dac97ea29b533a76c69b54477ea33f16 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 8 Feb 2012 09:49:51 -0700 Subject: [PATCH] Use LineWrapper to calculate pixelPositionFromPoint --- spec/atom/editor-spec.coffee | 4 ++-- src/atom/editor.coffee | 15 +++------------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 1982ae1e1..6ddeb567b 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -50,7 +50,7 @@ describe "Editor", -> buffer.insert([1,0], "/*") expect(editor.lines.find('.line:eq(2) span:eq(0)')).toMatchSelector '.comment' - describe "when soft-wrap is enabled", -> + fdescribe "when soft-wrap is enabled", -> beforeEach -> editor.attachToDom() editor.width(editor.charWidth * 50) @@ -60,7 +60,7 @@ describe "Editor", -> expect(editor.lines.find('pre:eq(3)').text()).toBe " var pivot = items.shift(), current, left = [], " expect(editor.lines.find('pre:eq(4)').text()).toBe "right = [];" - editor.cursor.setPosition([3, 52]) + editor.cursor.setPosition([3, 51]) expect(editor.cursor.position()).toEqual(editor.lines.find('pre:eq(4)').position()) editor.cursor.setPosition([4, 0]) diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 07cf5c310..f6f66fa79 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -191,18 +191,9 @@ class Editor extends View new Point(row, column) - pixelPositionFromPoint: ({row, column}) -> - segmentsAbove = 0 - segmentsAbove += @lineWrapper.segmentsForRow(i).length for i in [0...row] - - for segment in @lineWrapper.segmentsForRow(row) - if column > segment.lastIndex - segmentsAbove++ - column -= segment.textLength - else - break - - { top: segmentsAbove * @lineHeight, left: column * @charWidth } + pixelPositionFromPoint: (position) -> + { row, column } = @lineWrapper.displayPositionFromBufferPosition(position) + { top: row * @lineHeight, left: column * @charWidth } pointFromPixelPosition: ({top, left}) -> { row: Math.floor(top / @lineHeight), column: Math.floor(left / @charWidth) }