Skip to content

Commit

Permalink
Use vim.buf.cursor abstraction everywhere (#1127)
Browse files Browse the repository at this point in the history
Instead of accessing vim.current.window.cursor in some places.
  • Loading branch information
SirVer authored Nov 5, 2019
1 parent 44a73c1 commit a909dee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pythonx/UltiSnips/snippet/definition/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions pythonx/UltiSnips/snippet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pythonx/UltiSnips/vim_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()")

Expand Down

0 comments on commit a909dee

Please sign in to comment.