mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Add allowEOL param to screenPositionFromBufferPosition
This commit is contained in:
@@ -174,19 +174,28 @@ fdescribe "LineWrapper", ->
|
||||
expect(line2.endColumn).toBe 14
|
||||
expect(line2.textLength).toBe 3
|
||||
|
||||
describe ".screenPositionFromBufferPosition(point)", ->
|
||||
describe ".screenPositionFromBufferPosition(point, allowEOL=false)", ->
|
||||
it "translates the given buffer position to a screen position, accounting for wrapped lines", ->
|
||||
# before any wrapped lines
|
||||
expect(wrapper.screenPositionFromBufferPosition([0, 5])).toEqual([0, 5])
|
||||
expect(wrapper.screenPositionFromBufferPosition([0, 29])).toEqual([0, 29])
|
||||
|
||||
# on a wrapped line
|
||||
expect(wrapper.screenPositionFromBufferPosition([3, 5])).toEqual([3, 5])
|
||||
expect(wrapper.screenPositionFromBufferPosition([3, 50])).toEqual([3, 50])
|
||||
expect(wrapper.screenPositionFromBufferPosition([3, 51])).toEqual([4, 0])
|
||||
expect(wrapper.screenPositionFromBufferPosition([3, 62])).toEqual([4, 11])
|
||||
|
||||
# following a wrapped line
|
||||
expect(wrapper.screenPositionFromBufferPosition([4, 5])).toEqual([5, 5])
|
||||
|
||||
describe "when allowEOL is true", ->
|
||||
it "preserves a position at the end of a wrapped screen line ", ->
|
||||
expect(wrapper.screenPositionFromBufferPosition([3, 51], true)).toEqual([3, 51])
|
||||
|
||||
describe "when allowEOL is false", ->
|
||||
it "translates a position at the end of a wrapped screen line to the begining of the next screen line", ->
|
||||
expect(wrapper.screenPositionFromBufferPosition([3, 51])).toEqual([4, 0])
|
||||
|
||||
describe ".bufferPositionFromScreenPosition(point)", ->
|
||||
it "translates the given screen position to a buffer position, account for wrapped lines", ->
|
||||
# before any wrapped lines
|
||||
|
||||
@@ -91,15 +91,22 @@ class LineWrapper
|
||||
end = @screenPositionFromBufferPosition(bufferRange.end)
|
||||
new Range(start,end)
|
||||
|
||||
screenPositionFromBufferPosition: (bufferPosition) ->
|
||||
screenPositionFromBufferPosition: (bufferPosition, allowEOL=false) ->
|
||||
bufferPosition = Point.fromObject(bufferPosition)
|
||||
row = 0
|
||||
for wrappedLine in @wrappedLines[0...bufferPosition.row]
|
||||
row += wrappedLine.screenLines.length
|
||||
|
||||
column = bufferPosition.column
|
||||
for screenLine in @wrappedLines[bufferPosition.row].screenLines
|
||||
break if screenLine.endColumn > bufferPosition.column
|
||||
|
||||
screenLines = @wrappedLines[bufferPosition.row].screenLines
|
||||
for screenLine, index in screenLines
|
||||
break if index == screenLines.length - 1
|
||||
if allowEOL
|
||||
break if screenLine.endColumn >= bufferPosition.column
|
||||
else
|
||||
break if screenLine.endColumn > bufferPosition.column
|
||||
|
||||
column -= screenLine.textLength
|
||||
row++
|
||||
|
||||
|
||||
Reference in New Issue
Block a user