use Atom 1.19 buffer API for finding the length of a buffer

This commit is contained in:
Sophie Haskins 2017-06-29 10:32:17 -04:00
parent 545f13294e
commit abb5cd207f

View file

@ -14,7 +14,11 @@ class Command
addr = row addr = row
else if str is '$' else if str is '$'
# Lines are 0-indexed in Atom, but 1-indexed in vim. # Lines are 0-indexed in Atom, but 1-indexed in vim.
addr = @editor.getBuffer().lines.length - 1 # The two ways of getting length let us support Atom 1.19's new buffer
# implementation (https://github.com/atom/atom/pull/14435) and still
# support 1.18 and below
buffer = @editor.getBuffer()
addr = (buffer.getLineCount?() ? buffer.lines.length) - 1
else if str[0] in ["+", "-"] else if str[0] in ["+", "-"]
addr = row + @parseOffset(str) addr = row + @parseOffset(str)
else if not isNaN(str) else if not isNaN(str)
@ -73,7 +77,9 @@ class Command
return return
# Step 4: Address parsing # Step 4: Address parsing
lastLine = @editor.getBuffer().lines.length - 1 # see comment in parseAddr about line length
buffer = @editor.getBuffer()
lastLine = (buffer.getLineCount?() ? buffer.lines.length) - 1
if cl[0] is '%' if cl[0] is '%'
range = [0, lastLine] range = [0, lastLine]
cl = cl[1..] cl = cl[1..]