diff --git a/pythonx/UltiSnips/text_objects/_base.py b/pythonx/UltiSnips/text_objects/_base.py index 8c9913f..db18e59 100644 --- a/pythonx/UltiSnips/text_objects/_base.py +++ b/pythonx/UltiSnips/text_objects/_base.py @@ -48,18 +48,18 @@ class TextObject(object): """Represents any object in the text that has a span in any ways.""" - def __init__(self, parent, token, end=None, + def __init__(self, parent, token_or_start, end=None, initial_text='', tiebreaker=None): self._parent = parent if end is not None: # Took 4 arguments - self._start = token + self._start = token_or_start self._end = end self._initial_text = initial_text else: # Initialize from token - self._start = token.start - self._end = token.end - self._initial_text = token.initial_text + self._start = token_or_start.start + self._end = token_or_start.end + self._initial_text = token_or_start.initial_text self._tiebreaker = tiebreaker or Position( self._start.line, self._end.line) if parent is not None: diff --git a/pythonx/UltiSnips/text_objects/_mirror.py b/pythonx/UltiSnips/text_objects/_mirror.py index 499dac9..7f8c961 100644 --- a/pythonx/UltiSnips/text_objects/_mirror.py +++ b/pythonx/UltiSnips/text_objects/_mirror.py @@ -12,7 +12,6 @@ class Mirror(NoneditableTextObject): def __init__(self, parent, tabstop, token): NoneditableTextObject.__init__(self, parent, token) - self._ts = tabstop def _update(self, done): diff --git a/pythonx/UltiSnips/text_objects/_snippet_instance.py b/pythonx/UltiSnips/text_objects/_snippet_instance.py index 99b86ed..8b8e222 100644 --- a/pythonx/UltiSnips/text_objects/_snippet_instance.py +++ b/pythonx/UltiSnips/text_objects/_snippet_instance.py @@ -13,6 +13,7 @@ from UltiSnips import _vim from UltiSnips.position import Position from UltiSnips.text_objects._base import EditableTextObject, \ NoneditableTextObject +from UltiSnips.text_objects._tabstop import TabStop class SnippetInstance(EditableTextObject): @@ -104,7 +105,16 @@ class SnippetInstance(EditableTextObject): res = self._get_next_tab(self._cts) if res is None: self._cts = None - return self._tabstops.get(0, None) + + ts = self._get_tabstop(self, 0) + if ts: + return ts + + # TabStop 0 was deleted. It was probably killed through some + # edit action. Recreate it at the end of us. + start = Position(self.end.line, self.end.col) + end = Position(self.end.line, self.end.col) + return TabStop(self, 0, start, end) else: self._cts, ts = res return ts diff --git a/test/test_TabStop.py b/test/test_TabStop.py index 8254134..1f7e2c7 100644 --- a/test/test_TabStop.py +++ b/test/test_TabStop.py @@ -227,6 +227,16 @@ class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteSecond(_VimTest): wanted = """haupsblEnd""" +class TabStop_TSInDefaultText_ZeroLengthZerothTabstop(_VimTest): + snippets = ('test', """Test: ${1:snippet start\nNested tabstop: $0\nsnippet end}\nTrailing text""") + keys = 'test' + EX + JF + 'hello' + wanted = "Test: snippet start\nNested tabstop: hello\nsnippet end\nTrailing text" + +class TabStop_TSInDefaultText_ZeroLengthZerothTabstop_Override(_VimTest): + snippets = ('test', """Test: ${1:snippet start\nNested tabstop: $0\nsnippet end}\nTrailing text""") + keys = 'test' + EX + 'blub' + JF + 'hello' + wanted = "Test: blub\nTrailing texthello" + class TabStop_TSInDefaultText_ZeroLengthNested_OverwriteFirst(_VimTest): snippets = ('test', """h${1:a$2b}l""") keys = 'test' + EX + 'ups' + JF + 'End' @@ -370,4 +380,3 @@ class TabStop_AdjacentTabStopAddText_ExpectCorrectResult(_VimTest): snippets = ('test', '[ $1$2 ] $1') keys = 'test' + EX + 'Hello' + JF + 'World' + JF wanted = '[ HelloWorld ] Hello' - diff --git a/test/vim_test_case.py b/test/vim_test_case.py index ef3a7b9..ec888f4 100644 --- a/test/vim_test_case.py +++ b/test/vim_test_case.py @@ -26,7 +26,7 @@ class VimTestCase(unittest.TestCase, TempFileManager): expected_error = '' wanted = '' keys = '' - sleeptime = 0.02 + sleeptime = 0.00 output = '' plugins = [] # Skip this test for the given reason or None for not skipping it. @@ -52,7 +52,7 @@ class VimTestCase(unittest.TestCase, TempFileManager): for i in range(self.retries): if self.output != wanted: # Redo this, but slower - self.sleeptime += 0.05 + self.sleeptime += 0.15 self.tearDown() self.setUp() self.assertEqual(self.output, wanted)