From a909dee82b6eaaa3ae001e27c3e95c58d487d242 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Tue, 5 Nov 2019 08:41:03 +0100 Subject: [PATCH] Use vim.buf.cursor abstraction everywhere (#1127) Instead of accessing vim.current.window.cursor in some places. --- pythonx/UltiSnips/snippet/definition/base.py | 5 ++++- pythonx/UltiSnips/snippet_manager.py | 6 +++--- pythonx/UltiSnips/vim_helper.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pythonx/UltiSnips/snippet/definition/base.py b/pythonx/UltiSnips/snippet/definition/base.py index 734282d6..2f870602 100644 --- a/pythonx/UltiSnips/snippet/definition/base.py +++ b/pythonx/UltiSnips/snippet/definition/base.py @@ -13,6 +13,7 @@ from UltiSnips.indent_util import IndentUtil from UltiSnips.text import escape from UltiSnips.text_objects import SnippetInstance +from UltiSnips.position import Position from UltiSnips.text_objects.python_code import SnippetUtilForAction __WHITESPACE_SPLIT = re.compile(r"\s") @@ -200,7 +201,9 @@ def _execute_action(self, action, context, additional_locals={}): snip = self._eval_code(action, locals) if snip.cursor.is_set(): - vim.current.window.cursor = snip.cursor.to_vim_cursor() + vim_helper.buf.cursor = Position( + snip.cursor._cursor[0], snip.cursor._cursor[1] + ) else: new_mark_pos = vim_helper.get_mark_pos(mark_to_use) diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py index c4c1fa18..9e443e87 100644 --- a/pythonx/UltiSnips/snippet_manager.py +++ b/pythonx/UltiSnips/snippet_manager.py @@ -89,7 +89,7 @@ def __init__(self, expand_trigger, forward_trigger, backward_trigger): self._snip_expanded_in_action = False self._inside_action = False - self._last_change = ("", 0) + self._last_change = ("", Position(-1, -1)) self._added_snippets_source = AddedSnippetsSource() self.register_snippet_source("ultisnips_files", UltiSnipsFileSource()) @@ -905,11 +905,11 @@ def _track_change(self): if ( before and before[-1] == self._last_change[0] - or self._last_change[1] != vim.current.window.cursor[0] + or self._last_change[1] != vim_helper.buf.cursor ): self._try_expand(autotrigger_only=True) finally: - self._last_change = (inserted_char, vim.current.window.cursor[0]) + self._last_change = (inserted_char, vim_helper.buf.cursor) if self._should_reset_visual and self._visual_content.mode == "": self._visual_content.reset() diff --git a/pythonx/UltiSnips/vim_helper.py b/pythonx/UltiSnips/vim_helper.py index e7a9fc00..8204d18d 100755 --- a/pythonx/UltiSnips/vim_helper.py +++ b/pythonx/UltiSnips/vim_helper.py @@ -197,7 +197,7 @@ def select(start, end): selection = eval("&selection") col = col2byte(start.line + 1, start.col) - vim.current.window.cursor = start.line + 1, col + buf.cursor = start mode = eval("mode()")