diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 4a7ebf194..1d8320f4f 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -1234,3 +1234,9 @@ describe "EditSession", -> editSession.foldAll() expect(editSession.getCursorBufferPosition()).toEqual([5,5]) + + describe ".clipBufferPosition(bufferPosition)", -> + it "clips the given position to a valid position", -> + expect(editSession.clipBufferPosition([-1, -1])).toEqual [0,0] + expect(editSession.clipBufferPosition([Infinity, Infinity])).toEqual [12,2] + expect(editSession.clipBufferPosition([8, 57])).toEqual [8, 56] diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index e836ce524..871e580ee 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -87,7 +87,13 @@ class EditSession @renderer.clipScreenPosition(screenPosition, options) clipBufferPosition: (bufferPosition, options) -> - @renderer.clipBufferPosition(bufferPosition, options) + { row, column } = Point.fromObject(bufferPosition) + row = 0 if row < 0 + column = 0 if column < 0 + row = Math.min(@buffer.getLastRow(), row) + column = Math.min(@buffer.lineLengthForRow(row), column) + + new Point(row, column) getEofBufferPosition: -> @buffer.getEofPosition() diff --git a/src/app/line-map.coffee b/src/app/line-map.coffee index cd5498453..a06c1254b 100644 --- a/src/app/line-map.coffee +++ b/src/app/line-map.coffee @@ -81,9 +81,6 @@ class LineMap clipScreenPosition: (screenPosition, options) -> @clipPosition('screenDelta', screenPosition, options) - clipBufferPosition: (bufferPosition, options) -> - @clipPosition('bufferDelta', bufferPosition, options) - clipPosition: (deltaType, position, options={}) -> options.clipToBounds = true @translatePosition(deltaType, deltaType, position, options) diff --git a/src/app/renderer.coffee b/src/app/renderer.coffee index 0d505f860..70299c523 100644 --- a/src/app/renderer.coffee +++ b/src/app/renderer.coffee @@ -165,9 +165,6 @@ class Renderer clipScreenPosition: (position, options) -> @lineMap.clipScreenPosition(position, options) - clipBufferPosition: (position, options) -> - @lineMap.clipBufferPosition(position, options) - handleBufferChange: (e) -> allFolds = [] # Folds can modify @activeFolds, so first make sure we have a stable array of folds allFolds.push(folds...) for row, folds of @activeFolds