Merge pull request #348 from cwahbong/select-cr-fix

Fix issue #341 (github).
This commit is contained in:
Holger Rapp 2014-08-02 13:54:31 +02:00
commit 57ed954ccd
2 changed files with 20 additions and 6 deletions

View File

@ -379,15 +379,23 @@ class SnippetManager(object):
def _jump(self, backwards=False):
"""Helper method that does the actual jump."""
jumped = False
# If next tab has length 1 and the distance between itself and
# self._ctab is 1 then there is 1 less CursorMove events. We
# cannot ignore next movement in such case.
ntab_short_and_near = False
if self._cs:
self._ctab = self._cs.select_next_tab(backwards)
if self._ctab:
ntab = self._cs.select_next_tab(backwards)
if ntab:
if self._cs.snippet.has_option("s"):
lineno = _vim.buf.cursor.line
_vim.buf[lineno] = _vim.buf[lineno].rstrip()
_vim.select(self._ctab.start, self._ctab.end)
_vim.select(ntab.start, ntab.end)
jumped = True
if self._ctab.number == 0:
if (self._ctab is not None
and ntab.start - self._ctab.end == Position(0, 1)
and ntab.end - ntab.start == Position(0, 1)):
ntab_short_and_near = True
if ntab.number == 0:
self._current_snippet_is_done()
else:
# This really shouldn't happen, because a snippet should
@ -395,10 +403,12 @@ class SnippetManager(object):
# Cleanup by removing current snippet and recursing.
self._current_snippet_is_done()
jumped = self._jump(backwards)
self._ctab = ntab
if jumped:
self._vstate.remember_position()
self._vstate.remember_unnamed_register(self._ctab.current_text)
self._ignore_movements = True
if not ntab_short_and_near:
self._ignore_movements = True
return jumped
def _leaving_insert_mode(self):
@ -506,7 +516,6 @@ class SnippetManager(object):
si.update_textobjects()
self._ignore_movements = True
self._vstate.remember_buffer(self._csnippets[0])
self._jump()

View File

@ -251,3 +251,8 @@ class TabStopNavigatingInInsertModeSimple_ExpectCorrectResult(_VimTest):
snippets = ("hallo", "Hallo ${1:WELT} ups")
keys = "hallo" + EX + "haselnut" + 2*ARR_L + "hips" + JF + "end"
wanted = "Hallo haselnhipsut upsend"
class TabStop_CROnlyOnSelectedNear(_VimTest):
snippets = ("test", "t$1t${2: }t{\n\t$0\n}")
keys = "test" + EX + JF + "\n" + JF + "t"
wanted = "tt\nt{\n\tt\n}"