Skip to content

Commit

Permalink
Range: The end of the range should point at the last line of the range
Browse files Browse the repository at this point in the history
To preserve compatibility with Vim, the end of the range should point
at the last line of the range, not at the first line below.

The inconsistency can be demostrated by running (both in Vim and Neovim):

:python import vim; print vim.current.range.start, vim.current.range.end

either with visual range selected or without it.
  • Loading branch information
tbabej committed Mar 18, 2016
1 parent 2b1147e commit b192bae
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions neovim/api/buffer.py
Expand Up @@ -166,10 +166,10 @@ class Range(object):
def __init__(self, buffer, start, end):
self._buffer = buffer
self.start = start - 1
self.end = end
self.end = end - 1

def __len__(self):
return self.end - self.start
return self.end - self.start + 1

def __getitem__(self, idx):
if not isinstance(idx, slice):
Expand All @@ -179,7 +179,7 @@ def __getitem__(self, idx):
if start is None:
start = self.start
if end is None:
end = self.end
end = self.end + 1
return self._buffer[start:end]

def __setitem__(self, idx, lines):
Expand All @@ -191,26 +191,26 @@ def __setitem__(self, idx, lines):
if start is None:
start = self.start
if end is None:
end = self.end
end = self.end + 1
self._buffer[start:end] = lines

def __iter__(self):
for i in range(self.start, self.end):
for i in range(self.start, self.end + 1):
yield self._buffer[i]

def append(self, lines, i=None):
i = self._normalize_index(i)
if i is None:
i = self.end
i = self.end + 1
self._buffer.append(lines, i)

def _normalize_index(self, index):
if index is None:
return None
if index < 0:
index = self.end - 1
index = self.end
else:
index += self.start
if index >= self.end:
index = self.end - 1
if index > self.end:
index = self.end
return index

0 comments on commit b192bae

Please sign in to comment.