Skip to content

Commit b192bae

Browse files
committed
Range: The end of the range should point at the last line of the range
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.
1 parent 2b1147e commit b192bae

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

neovim/api/buffer.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ class Range(object):
166166
def __init__(self, buffer, start, end):
167167
self._buffer = buffer
168168
self.start = start - 1
169-
self.end = end
169+
self.end = end - 1
170170

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

174174
def __getitem__(self, idx):
175175
if not isinstance(idx, slice):
@@ -179,7 +179,7 @@ def __getitem__(self, idx):
179179
if start is None:
180180
start = self.start
181181
if end is None:
182-
end = self.end
182+
end = self.end + 1
183183
return self._buffer[start:end]
184184

185185
def __setitem__(self, idx, lines):
@@ -191,26 +191,26 @@ def __setitem__(self, idx, lines):
191191
if start is None:
192192
start = self.start
193193
if end is None:
194-
end = self.end
194+
end = self.end + 1
195195
self._buffer[start:end] = lines
196196

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

201201
def append(self, lines, i=None):
202202
i = self._normalize_index(i)
203203
if i is None:
204-
i = self.end
204+
i = self.end + 1
205205
self._buffer.append(lines, i)
206206

207207
def _normalize_index(self, index):
208208
if index is None:
209209
return None
210210
if index < 0:
211-
index = self.end - 1
211+
index = self.end
212212
else:
213213
index += self.start
214-
if index >= self.end:
215-
index = self.end - 1
214+
if index > self.end:
215+
index = self.end
216216
return index

0 commit comments

Comments
 (0)