mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
WIP: Start on LineWrapper.displayPositionFromBufferPosition
It takes a row, column from the buffer and converts it to coordinates that account for line wrapping.
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'
|
||||
|
||||
fdescribe "when soft-wrap is enabled", ->
|
||||
describe "when soft-wrap is enabled", ->
|
||||
beforeEach ->
|
||||
editor.attachToDom()
|
||||
editor.width(editor.charWidth * 50)
|
||||
|
||||
@@ -47,5 +47,17 @@ fdescribe "LineWrapper", ->
|
||||
expect(segments[2].lastIndex).toBe 65
|
||||
expect(_.pluck(segments[2], 'value').join('')).toBe 'right.push(current);'
|
||||
|
||||
describe "when the buffer changes", ->
|
||||
|
||||
describe ".displayPositionFromBufferPosition(point)", ->
|
||||
it "returns the position of the indicated row and column on screen, accounting for wrapped lines", ->
|
||||
# no wrap
|
||||
expect(wrapper.displayPositionFromBufferPosition(row: 0, column: 5)).toEqual(row: 0, column: 5)
|
||||
|
||||
# wrap once
|
||||
expect(wrapper.displayPositionFromBufferPosition(row: 3, column: 5)).toEqual(row: 3, column: 5)
|
||||
expect(wrapper.displayPositionFromBufferPosition(row: 3, column: 50)).toEqual(row: 3, column: 50)
|
||||
expect(wrapper.displayPositionFromBufferPosition(row: 3, column: 51)).toEqual(row: 4, column: 0)
|
||||
|
||||
# following a wrap
|
||||
expect(wrapper.displayPositionFromBufferPosition(row: 4, column: 5)).toEqual(row: 5, column: 5)
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ class LineWrapper
|
||||
|
||||
currentSegment = []
|
||||
currentSegment.lastIndex = 0
|
||||
currentSegment.textLength = 0
|
||||
segments = [currentSegment]
|
||||
nextBreak = breakIndices.shift()
|
||||
for token in @highlighter.tokensForRow(row)
|
||||
@@ -50,3 +51,17 @@ class LineWrapper
|
||||
currentSegment.textLength += token.value.length
|
||||
|
||||
segments
|
||||
|
||||
displayPositionFromBufferPosition: (bufferPosition) ->
|
||||
row = 0
|
||||
for segments in @lines[0...bufferPosition.row]
|
||||
row += segments.length
|
||||
|
||||
column = bufferPosition.column
|
||||
for segment in @lines[bufferPosition.row]
|
||||
break if segment.lastIndex > bufferPosition.column
|
||||
column -= segment.textLength
|
||||
row++
|
||||
|
||||
{ row, column }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user