From 66ba0686d9cbfa8e0ec8491b6401d4b862aa5620 Mon Sep 17 00:00:00 2001 From: Michael Henry Date: Tue, 25 Aug 2009 19:18:06 -0400 Subject: [PATCH] Snippet mode is now exited after final tabstop zero is encountered. --- plugin/UltiSnips/__init__.py | 19 +++++++++++-------- test.py | 7 +++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index dcf37ad..d9dad6f 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -479,22 +479,25 @@ class SnippetManager(object): self._check_if_still_inside_snippet() def _jump(self, backwards = False): + jumped = False if self._cs: self._expect_move_wo_change = True self._ctab = self._cs.select_next_tab(backwards) if self._ctab: self._vstate.select_span(self._ctab.abs_span) self._span_selected = self._ctab.abs_span + jumped = True + if self._ctab.no == 0: + self._ctab = None + self._csnippets.pop() + self._vstate.update() else: + # This really shouldn't happen, because a snippet should + # have been popped when its final tabstop was used. + # Cleanup by removing current snippet and recursing. self._csnippets.pop() - if self._cs: - self._jump(backwards) - return True - - self._vstate.update() - return True - return False - + jumped = self._jump(backwards) + return jumped def _handle_failure(self, trigger): """ diff --git a/test.py b/test.py index 7bd8202..2ae5d03 100755 --- a/test.py +++ b/test.py @@ -163,6 +163,11 @@ class DoNotExpandAfterSpace_ExceptCorrectResult(_SimpleExpands): keys = "hallo " + EX wanted = "hallo " +class ExitSnippetModeAfterTabstopZero(_VimTest): + snippets = ("test", "SimpleText") + keys = "test" + EX + EX + wanted = "SimpleText" + EX + class ExpandInTheMiddleOfLine_ExceptCorrectResult(_SimpleExpands): keys = "Wie hallo gehts" + ESC + "bhi" + EX wanted = "Wie Hallo Welt! gehts" @@ -261,12 +266,10 @@ class TabStopUsingBackspaceToDeleteDefaultValueTypeSomethingThen_ECR(_VimTest): snippets = ("test", "snip ${1/.+/(?0:matched)/} ${1:default}") keys = "test" + EX + BS + "hallo" wanted = "snip matched hallo" - class TabStopWithOneChar_ExceptCorrectResult(_VimTest): snippets = ("hallo", "nothing ${1:i} hups") keys = "hallo" + EX + "ship" wanted = "nothing ship hups" - class TabStopTestJumping_ExceptCorrectResult(_VimTest): snippets = ("hallo", "hallo ${2:End} mitte ${1:Beginning}") keys = "hallo" + EX + JF + "Test" + JF + "Hi"