mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Use LineWrapper to calculate pixelPositionFromPoint
This commit is contained in:
@@ -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])
|
||||
|
||||
@@ -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) }
|
||||
|
||||
Reference in New Issue
Block a user