VimBuffer.cursor.line is no 0 based

This commit is contained in:
Holger Rapp 2012-01-22 19:02:31 +01:00
parent 30286f5446
commit a4f8e12c24
3 changed files with 16 additions and 17 deletions

View File

@ -676,9 +676,8 @@ class SnippetManager(object):
def _check_if_still_inside_snippet(self): def _check_if_still_inside_snippet(self):
# Did we leave the snippet with this movement? # Did we leave the snippet with this movement?
line, col = _vim.buf.cursor
if self._cs and ( if self._cs and (
not self._cs.start <= Position(line - 1, col) <= self._cs.end not self._cs.start <= _vim.buf.cursor <= self._cs.end
): ):
self._current_snippet_is_done() self._current_snippet_is_done()
self._reinit() self._reinit()
@ -789,9 +788,7 @@ class SnippetManager(object):
""" Expands the given snippet, and handles everything """ Expands the given snippet, and handles everything
that needs to be done with it. that needs to be done with it.
""" """
lineno, col = _vim.buf.cursor
# Adjust before, maybe the trigger is not the complete word # Adjust before, maybe the trigger is not the complete word
text_before = before text_before = before
if snippet.matched: if snippet.matched:
text_before = before[:-len(snippet.matched)] text_before = before[:-len(snippet.matched)]
@ -799,8 +796,8 @@ class SnippetManager(object):
self._unset_offending_vim_options(snippet) self._unset_offending_vim_options(snippet)
if self._cs: if self._cs:
start = Position(lineno-1, len(text_before)) start = Position(_vim.buf.cursor.line, len(text_before))
end = Position(lineno-1, len(before)) end = Position(_vim.buf.cursor.line, len(before))
si = snippet.launch(text_before, self._visual_content, si = snippet.launch(text_before, self._visual_content,
self._cs.find_parent_for_new_to(start), start, end) self._cs.find_parent_for_new_to(start), start, end)
@ -808,8 +805,8 @@ class SnippetManager(object):
self._csnippets.append(si) self._csnippets.append(si)
else: else:
start = Position(lineno-1, len(text_before)) start = Position(_vim.buf.cursor.line, len(text_before))
end = Position(lineno-1, len(before)) end = Position(_vim.buf.cursor.line, len(before))
self._csnippets.append(snippet.launch(text_before, self._visual_content, None, start, end)) self._csnippets.append(snippet.launch(text_before, self._visual_content, None, start, end))
self._visual_content.reset() self._visual_content.reset()

View File

@ -42,14 +42,17 @@ class VimBuffer(object):
return before, after return before, after
def cursor(): def cursor():
"""The current windows cursor""" """
The current windows cursor. Note that this is 0 based in col and 0
based in line which is different from Vim's cursor.
"""
def fget(self): def fget(self):
return vim_cursor() line, col = vim_cursor()
def fset(self, value): return Position(line - 1, col)
set_vim_cursor(*value) def fset(self, pos):
set_vim_cursor(pos.line + 1, pos.col)
return locals() return locals()
cursor = property(**cursor()) cursor = property(**cursor())
buf = VimBuffer() buf = VimBuffer()
@ -195,7 +198,7 @@ def text_to_vim(start, end, text):
# Open any folds this might have created # Open any folds this might have created
debug("start: %r" % (start)) debug("start: %r" % (start))
buf.cursor = start.line + 1, start.col buf.cursor = start
vim.command("normal zv") vim.command("normal zv")
new_end = _calc_end(lines, start) new_end = _calc_end(lines, start)

View File

@ -116,12 +116,11 @@ class _VimCursor(NoneditableTextObject):
"""Helper class to keep track of the Vim Cursor""" """Helper class to keep track of the Vim Cursor"""
def __init__(self, parent): def __init__(self, parent):
line, col = _vim.buf.cursor
NoneditableTextObject.__init__( NoneditableTextObject.__init__(
self, parent, Position(line-1, col), Position(line-1, col) self, parent, _vim.buf.cursor, _vim.buf.cursor
) )
def to_vim(self): def to_vim(self):
assert(self._start == self._end) assert(self._start == self._end)
_vim.buf.cursor = self._start.line + 1, self._start.col _vim.buf.cursor = self._start