diff --git a/pythonx/UltiSnips/snippet/definition/_base.py b/pythonx/UltiSnips/snippet/definition/_base.py index b7f4bbe..e8ece6b 100644 --- a/pythonx/UltiSnips/snippet/definition/_base.py +++ b/pythonx/UltiSnips/snippet/definition/_base.py @@ -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 diff --git a/pythonx/UltiSnips/snippet/parsing/_base.py b/pythonx/UltiSnips/snippet/parsing/_base.py index 8c7f342..23be989 100644 --- a/pythonx/UltiSnips/snippet/parsing/_base.py +++ b/pythonx/UltiSnips/snippet/parsing/_base.py @@ -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() diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py index 75c900c..dbb20d1 100644 --- a/pythonx/UltiSnips/snippet_manager.py +++ b/pythonx/UltiSnips/snippet_manager.py @@ -640,10 +640,10 @@ class SnippetManager(object): before = _vim.buf.line_till_cursor 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: - 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 # 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]) diff --git a/pythonx/UltiSnips/text_objects/_base.py b/pythonx/UltiSnips/text_objects/_base.py index 6ee1745..df83954 100644 --- a/pythonx/UltiSnips/text_objects/_base.py +++ b/pythonx/UltiSnips/text_objects/_base.py @@ -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), diff --git a/pythonx/UltiSnips/text_objects/_snippet_instance.py b/pythonx/UltiSnips/text_objects/_snippet_instance.py index 60c1db1..d63f8ae 100644 --- a/pythonx/UltiSnips/text_objects/_snippet_instance.py +++ b/pythonx/UltiSnips/text_objects/_snippet_instance.py @@ -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)