Code simplifications. (#972)
This commit is contained in:
parent
943156d879
commit
165dd4b3cd
@ -438,6 +438,6 @@ class SnippetDefinition(object):
|
||||
last_re=self._last_re, globals=self._globals,
|
||||
context=self._context)
|
||||
self.instantiate(snippet_instance, initial_text, indent)
|
||||
|
||||
snippet_instance.replace_initial_text()
|
||||
snippet_instance.update_textobjects()
|
||||
return snippet_instance
|
||||
|
@ -65,4 +65,3 @@ def finalize(all_tokens, seen_ts, snippet_instance):
|
||||
mark = all_tokens[-1][1].end # Last token is always EndOfText
|
||||
m1 = Position(mark.line, mark.col)
|
||||
TabStop(snippet_instance, 0, mark, m1)
|
||||
snippet_instance.replace_initial_text()
|
||||
|
@ -640,10 +640,10 @@ class SnippetManager(object):
|
||||
before = _vim.buf.line_till_cursor
|
||||
|
||||
with suspend_proxy_edits():
|
||||
if self._cs:
|
||||
start = Position(_vim.buf.cursor.line, len(text_before))
|
||||
end = Position(_vim.buf.cursor.line, len(before))
|
||||
|
||||
parent = None
|
||||
if self._cs:
|
||||
# If cursor is set in pre-action, then action was modified
|
||||
# cursor line, in that case we do not need to do any edits, it
|
||||
# can break snippet
|
||||
@ -658,26 +658,17 @@ class SnippetManager(object):
|
||||
('I', start.line, start.col, snippet.matched),
|
||||
]
|
||||
self._csnippets[0].replay_user_edits(edit_actions)
|
||||
|
||||
si = snippet.launch(text_before, self._visual_content,
|
||||
self._cs.find_parent_for_new_to(start),
|
||||
start, end
|
||||
)
|
||||
else:
|
||||
start = Position(_vim.buf.cursor.line, len(text_before))
|
||||
end = Position(_vim.buf.cursor.line, len(before))
|
||||
si = snippet.launch(text_before, self._visual_content,
|
||||
None, start, end)
|
||||
parent = self._cs.find_parent_for_new_to(start)
|
||||
snippet_instance = snippet.launch(text_before,
|
||||
self._visual_content, parent, start, end)
|
||||
|
||||
self._visual_content.reset()
|
||||
self._csnippets.append(si)
|
||||
|
||||
si.update_textobjects()
|
||||
self._csnippets.append(snippet_instance)
|
||||
|
||||
with use_proxy_buffer(self._csnippets, self._vstate):
|
||||
with self._action_context():
|
||||
snippet.do_post_expand(
|
||||
si._start, si._end, self._csnippets
|
||||
snippet_instance._start, snippet_instance._end, self._csnippets
|
||||
)
|
||||
|
||||
self._vstate.remember_buffer(self._csnippets[0])
|
||||
|
@ -115,7 +115,10 @@ class TextObject(object):
|
||||
"""The end position."""
|
||||
return self._end
|
||||
|
||||
def overwrite(self, gtext=None):
|
||||
def overwrite_with_initial_text(self):
|
||||
self.overwrite(self._initial_text)
|
||||
|
||||
def overwrite(self, gtext):
|
||||
"""Overwrite the text of this object in the Vim Buffer and update its
|
||||
length information.
|
||||
|
||||
@ -129,7 +132,7 @@ class TextObject(object):
|
||||
return
|
||||
old_end = self._end
|
||||
self._end = _text_to_vim(
|
||||
self._start, self._end, gtext or self._initial_text)
|
||||
self._start, self._end, gtext)
|
||||
if self._parent:
|
||||
self._parent._child_has_moved(
|
||||
self._parent._children.index(self), min(old_end, self._end),
|
||||
|
@ -42,7 +42,7 @@ class SnippetInstance(EditableTextObject):
|
||||
"""Puts the initial text of all text elements into Vim."""
|
||||
def _place_initial_text(obj):
|
||||
"""recurses on the children to do the work."""
|
||||
obj.overwrite()
|
||||
obj.overwrite_with_initial_text()
|
||||
if isinstance(obj, EditableTextObject):
|
||||
for child in obj._children:
|
||||
_place_initial_text(child)
|
||||
|
Loading…
Reference in New Issue
Block a user