Code simplifications. (#972)

This commit is contained in:
Holger Rapp 2018-04-14 16:25:44 +02:00 committed by UltiBot
parent 943156d879
commit 165dd4b3cd
5 changed files with 15 additions and 22 deletions

View File

@ -438,6 +438,6 @@ class SnippetDefinition(object):
last_re=self._last_re, globals=self._globals, last_re=self._last_re, globals=self._globals,
context=self._context) context=self._context)
self.instantiate(snippet_instance, initial_text, indent) self.instantiate(snippet_instance, initial_text, indent)
snippet_instance.replace_initial_text()
snippet_instance.update_textobjects() snippet_instance.update_textobjects()
return snippet_instance return snippet_instance

View File

@ -65,4 +65,3 @@ def finalize(all_tokens, seen_ts, snippet_instance):
mark = all_tokens[-1][1].end # Last token is always EndOfText mark = all_tokens[-1][1].end # Last token is always EndOfText
m1 = Position(mark.line, mark.col) m1 = Position(mark.line, mark.col)
TabStop(snippet_instance, 0, mark, m1) TabStop(snippet_instance, 0, mark, m1)
snippet_instance.replace_initial_text()

View File

@ -640,10 +640,10 @@ class SnippetManager(object):
before = _vim.buf.line_till_cursor before = _vim.buf.line_till_cursor
with suspend_proxy_edits(): with suspend_proxy_edits():
start = Position(_vim.buf.cursor.line, len(text_before))
end = Position(_vim.buf.cursor.line, len(before))
parent = None
if self._cs: if self._cs:
start = Position(_vim.buf.cursor.line, len(text_before))
end = Position(_vim.buf.cursor.line, len(before))
# If cursor is set in pre-action, then action was modified # 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 # cursor line, in that case we do not need to do any edits, it
# can break snippet # can break snippet
@ -658,26 +658,17 @@ class SnippetManager(object):
('I', start.line, start.col, snippet.matched), ('I', start.line, start.col, snippet.matched),
] ]
self._csnippets[0].replay_user_edits(edit_actions) self._csnippets[0].replay_user_edits(edit_actions)
parent = self._cs.find_parent_for_new_to(start)
si = snippet.launch(text_before, self._visual_content, snippet_instance = snippet.launch(text_before,
self._cs.find_parent_for_new_to(start), self._visual_content, parent, start, end)
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)
self._visual_content.reset() self._visual_content.reset()
self._csnippets.append(si) self._csnippets.append(snippet_instance)
si.update_textobjects()
with use_proxy_buffer(self._csnippets, self._vstate): with use_proxy_buffer(self._csnippets, self._vstate):
with self._action_context(): with self._action_context():
snippet.do_post_expand( 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]) self._vstate.remember_buffer(self._csnippets[0])

View File

@ -115,7 +115,10 @@ class TextObject(object):
"""The end position.""" """The end position."""
return self._end 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 """Overwrite the text of this object in the Vim Buffer and update its
length information. length information.
@ -129,7 +132,7 @@ class TextObject(object):
return return
old_end = self._end old_end = self._end
self._end = _text_to_vim( self._end = _text_to_vim(
self._start, self._end, gtext or self._initial_text) self._start, self._end, gtext)
if self._parent: if self._parent:
self._parent._child_has_moved( self._parent._child_has_moved(
self._parent._children.index(self), min(old_end, self._end), self._parent._children.index(self), min(old_end, self._end),

View File

@ -42,7 +42,7 @@ class SnippetInstance(EditableTextObject):
"""Puts the initial text of all text elements into Vim.""" """Puts the initial text of all text elements into Vim."""
def _place_initial_text(obj): def _place_initial_text(obj):
"""recurses on the children to do the work.""" """recurses on the children to do the work."""
obj.overwrite() obj.overwrite_with_initial_text()
if isinstance(obj, EditableTextObject): if isinstance(obj, EditableTextObject):
for child in obj._children: for child in obj._children:
_place_initial_text(child) _place_initial_text(child)