Refactored retaining of unnamed register to be done in VimState.
This commit is contained in:
parent
888ce5dac5
commit
7c9d0c0c71
@ -256,7 +256,7 @@ function! UltiSnips_LeavingBuffer()
|
|||||||
endf
|
endf
|
||||||
|
|
||||||
function! UltiSnips_LeavingInsertMode()
|
function! UltiSnips_LeavingInsertMode()
|
||||||
exec g:_uspy "UltiSnips_Manager.restore_unnamed_register()"
|
exec g:_uspy "UltiSnips_Manager.leaving_insert_mode()"
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
@ -168,10 +168,6 @@ class SnippetManager(object):
|
|||||||
while len(self._csnippets):
|
while len(self._csnippets):
|
||||||
self._current_snippet_is_done()
|
self._current_snippet_is_done()
|
||||||
|
|
||||||
# needed to retain the unnamed register at all times
|
|
||||||
self._unnamed_reg_cached = False
|
|
||||||
self._last_placeholder = None
|
|
||||||
|
|
||||||
self._reinit()
|
self._reinit()
|
||||||
|
|
||||||
@err_to_scratch_buffer
|
@err_to_scratch_buffer
|
||||||
@ -439,25 +435,14 @@ class SnippetManager(object):
|
|||||||
self._current_snippet_is_done()
|
self._current_snippet_is_done()
|
||||||
jumped = self._jump(backwards)
|
jumped = self._jump(backwards)
|
||||||
if jumped:
|
if jumped:
|
||||||
self._cache_unnamed_register()
|
|
||||||
self._vstate.remember_position()
|
self._vstate.remember_position()
|
||||||
|
self._vstate.remember_unnamed_register(self._ctab.current_text)
|
||||||
self._ignore_movements = True
|
self._ignore_movements = True
|
||||||
return jumped
|
return jumped
|
||||||
|
|
||||||
def _cache_unnamed_register(self):
|
def leaving_insert_mode(self):
|
||||||
"""Save the unnamed register."""
|
"""Called whenever we leave the insert mode."""
|
||||||
self._unnamed_reg_cached = True
|
self._vstate.restore_unnamed_register()
|
||||||
unnamed_reg = _vim.eval('@"')
|
|
||||||
if self._last_placeholder != unnamed_reg:
|
|
||||||
self._unnamed_reg_cache = unnamed_reg
|
|
||||||
self._last_placeholder = self._ctab.current_text
|
|
||||||
|
|
||||||
def restore_unnamed_register(self):
|
|
||||||
"""Restores the unnamed register from the cache."""
|
|
||||||
if self._unnamed_reg_cached:
|
|
||||||
escaped_cache = self._unnamed_reg_cache.replace("'", "''")
|
|
||||||
_vim.command("let @\"='%s'" % escaped_cache)
|
|
||||||
self._unnamed_reg_cached = False
|
|
||||||
|
|
||||||
def _handle_failure(self, trigger):
|
def _handle_failure(self, trigger):
|
||||||
"""Mainly make sure that we play well with SuperTab."""
|
"""Mainly make sure that we play well with SuperTab."""
|
||||||
|
@ -31,6 +31,29 @@ class VimState(object):
|
|||||||
self._poss = deque(maxlen=5)
|
self._poss = deque(maxlen=5)
|
||||||
self._lvb = None
|
self._lvb = None
|
||||||
|
|
||||||
|
self._text_to_expect = None
|
||||||
|
self._unnamed_reg_cache = None
|
||||||
|
self._unnamed_reg_cached = False
|
||||||
|
|
||||||
|
def remember_unnamed_register(self, text_to_expect):
|
||||||
|
"""Save the unnamed register. 'text_to_expect' is text that we expect
|
||||||
|
to be currently contained in the register - this could be text from the
|
||||||
|
tabstop that was selected and might have been overwritten. We will not
|
||||||
|
cash that then."""
|
||||||
|
self._unnamed_reg_cached = True
|
||||||
|
unnamed_reg = _vim.eval('@"')
|
||||||
|
if unnamed_reg != self._text_to_expect:
|
||||||
|
self._unnamed_reg_cache = unnamed_reg
|
||||||
|
self._text_to_expect = text_to_expect
|
||||||
|
|
||||||
|
def restore_unnamed_register(self):
|
||||||
|
"""Restores the unnamed register and forgets what we cached."""
|
||||||
|
if not self._unnamed_reg_cached:
|
||||||
|
return
|
||||||
|
escaped_cache = self._unnamed_reg_cache.replace("'", "''")
|
||||||
|
_vim.command("let @\"='%s'" % escaped_cache)
|
||||||
|
self._unnamed_reg_cached = False
|
||||||
|
|
||||||
def remember_position(self):
|
def remember_position(self):
|
||||||
"""Remember the current position as a previous pose."""
|
"""Remember the current position as a previous pose."""
|
||||||
self._poss.append(VimPosition())
|
self._poss.append(VimPosition())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user