Handle $0 in a default text like any other tabstop.
Also change timing for testing again. Fixes #356.
This commit is contained in:
parent
5c211b0e79
commit
67fbdb2ad8
@ -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:
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user