diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index da629ae..e8450c7 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -156,18 +156,20 @@ class VimState(object): class SnippetManager(object): def __init__(self): + self._vstate = VimState() + self.reset() - self._vstate = VimState() - self._ctab = None - - self._expect_move_wo_change = False def reset(self): self._snippets = {} self._csnippets = [] + self._reinit() + + def _reinit(self): self._ctab = None self._span_selected = None + self._expect_move_wo_change = False def add_snippet(self, trigger, value, descr): @@ -179,8 +181,10 @@ class SnippetManager(object): def jump(self, backwards = False): if self._cs: + debug("jump: self._cs: %s" % (self._cs)) self._expect_move_wo_change = True self._ctab = self._cs.select_next_tab(backwards) + debug(" self._ctab: %s" % (self._ctab)) if self._ctab: self._vstate.select_span(self._ctab.abs_span) self._span_selected = self._ctab.abs_span @@ -300,17 +304,25 @@ class SnippetManager(object): else: vim.command(r'call feedkeys("\")') + def _check_if_still_inside_snippet(self): + # Cursor moved without input. + self._ctab = None + + # Did we leave the snippet with this movement? + if self._cs and not (self._vstate.pos in self._cs.abs_span): + debug("popping: self._cs: %s" % (self._cs)) + debug(" self._csni: %s" % (self._csnippets)) + self._csnippets.pop() + + self._reinit() + + self._check_if_still_inside_snippet() + def cursor_moved(self): self._vstate.update() if not self._vstate.buf_changed and not self._expect_move_wo_change: - # Cursor moved without input. - self._ctab = None - - # Did we leave the snippet with this movement? - if self._cs and not \ - (self._vstate.pos in self._cs.abs_span): - self.reset() + self._check_if_still_inside_snippet() if not self._ctab: return @@ -356,7 +368,8 @@ class SnippetManager(object): def entered_insert_mode(self): self._vstate.update() if self._cs and self._vstate.has_moved: - self.reset() + self._reinit() + self._csnippets = [] ################################### # Private/Protect Functions Below # diff --git a/test.py b/test.py index b9960d8..96339c2 100755 --- a/test.py +++ b/test.py @@ -42,7 +42,7 @@ class _VimTest(unittest.TestCase): text_after = " --- some text after --- " wanted = "" keys = "" - sleeptime = 0.01 + sleeptime = 0.03 def send(self,s): send(s, self.session) @@ -227,7 +227,7 @@ class TabStopUsingBackspaceToDeleteDefaultValue_ECR(_VimTest): keys = "test" + EX + BS wanted = "snip " class TabStopUsingBackspaceToDeleteDefaultValueInFirstTab_ECR(_VimTest): - sleeptime = 0.05 # Do this very slowly + sleeptime = 0.09 # Do this very slowly snippets = ("test", "snip ${1/.+/(?0:m1)/} ${2/.+/(?0:m2)/} " "${1:default} ${2:def}") keys = "test" + EX + BS + JF + "hi" @@ -374,7 +374,7 @@ class TabStop_Shell_TextInNextLine(_VimTest): keys = "test" + EX + "and more" wanted = "hi hallo\nWeiterand more" class TabStop_Shell_InDefValue_Leave(_VimTest): - sleeptime = 0.05 # Do this very slowly + sleeptime = 0.09 # Do this very slowly snippets = ("test", "Hallo ${1:now `echo fromecho`} end") keys = "test" + EX + JF + "and more" wanted = "Hallo now fromecho endand more" @@ -384,7 +384,7 @@ class TabStop_Shell_InDefValue_Overwrite(_VimTest): wanted = "Hallo overwrite endand more" class TabStop_Shell_ShebangPython(_VimTest): - sleeptime = 0.05 # Do this very slowly + sleeptime = 0.09 # Do this very slowly snippets = ("test", """Hallo ${1:now `#!/usr/bin/env python print "Hallo Welt" `} end""") @@ -420,10 +420,6 @@ class TabStop_VimScriptInterpolation_SimpleExample(_VimTest): # TODO: Multiline text pasting -print "Recursive Tabstops: TODO: this will still take some time" -# TODO: leaving all nested snippets at onec -# TODO: only leaving one nested snippet - ############################### # Recursive (Nested) Snippets # ############################### @@ -530,6 +526,36 @@ class RecTabStops_InNewlineInTabstopNotAtBeginOfLine_ECR(_VimTest): # keys = "m" + EX + "m" + EX # wanted = "M START\n M START\n" +print "Recursive Tabstops: TODO: this will still take some time" + +class RecTabStops_BarelyNotLeavingInner_ECR(_VimTest): + snippets = ( + ("m", "[ ${1:first} ${2:sec} ]"), + ) + keys = "m" + EX + "m" + EX + "a" + 3*ARR_L + JF + "hallo" + \ + JF + "world" + JF + "end" + wanted = "[ [ a hallo ] world ]end" +class RecTabStops_LeavingInner_ECR(_VimTest): + snippets = ( + ("m", "[ ${1:first} ${2:sec} ]"), + ) + keys = "m" + EX + "m" + EX + "a" + 4*ARR_L + JF + "hallo" + \ + JF + "world" + wanted = "[ [ a sec ] hallo ]world" +class RecTabStops_LeavingInnerInner_ECR(_VimTest): + snippets = ( + ("m", "[ ${1:first} ${2:sec} ]"), + ) + keys = "m" + EX + "m" + EX + "m" + EX + "a" + 4*ARR_L + JF + "hallo" + \ + JF + "world" + JF + "end" + wanted = "[ [ [ a sec ] hallo ] world ]end" +class RecTabStops_LeavingInnerInnerTwo_ECR(_VimTest): + snippets = ( + ("m", "[ ${1:first} ${2:sec} ]"), + ) + keys = "m" + EX + "m" + EX + "m" + EX + "a" + 6*ARR_L + JF + "hallo" + \ + JF + "end" + wanted = "[ [ [ a sec ] sec ] hallo ]end" class RecTabStops_IgnoreZeroTS_ECR(_VimTest):