Ensure start row is always >= 0

Previously if a file was a single line
it couldn't be deleted using the delete
line command because the start row would
index one row back which would be -1 and
therefore not be able to report a length
for use in the delete range.
This commit is contained in:
Kevin Sawicki 2012-09-20 09:00:37 -07:00
parent f241bc5d2b
commit 7278bc62c6
2 changed files with 22 additions and 1 deletions

View File

@ -1508,3 +1508,21 @@ describe "EditSession", ->
expect(buffer.getLineCount()).toBe(13)
editSession.deleteLine()
expect(buffer.getLineCount()).toBe(4)
it "deletes the entire file from the bottom up", ->
count = buffer.getLineCount()
expect(count).toBeGreaterThan(0)
for line in [0...count]
editSession.getLastCursor().moveToBottom()
editSession.deleteLine()
expect(buffer.getLineCount()).toBe(1)
expect(buffer.getText()).toBe('')
it "deletes the entire file from the top down", ->
count = buffer.getLineCount()
expect(count).toBeGreaterThan(0)
for line in [0...count]
editSession.getLastCursor().moveToTop()
editSession.deleteLine()
expect(buffer.getLineCount()).toBe(1)
expect(buffer.getText()).toBe('')

View File

@ -168,7 +168,10 @@ class Buffer
startPoint = null
endPoint = null
if end == @getLastRow()
startPoint = [start - 1, @lineLengthForRow(start - 1)]
if start > 0
startPoint = [start - 1, @lineLengthForRow(start - 1)]
else
startPoint = [start, 0]
endPoint = [end, @lineLengthForRow(end)]
else
startPoint = [start, 0]