Try hard to retain the unnamed register. Patch by Gernot Höflechner - LFDM.
This commit is contained in:
commit
4adc048c16
@ -1397,6 +1397,7 @@ Contributors listed in chronological order:
|
||||
Romain Giot - rgiot
|
||||
Sergey Alexandrov - taketwo
|
||||
Brian Mock - saikobee
|
||||
Gernot Höflechner - LFDM
|
||||
|
||||
|
||||
8.2 Snippets *UltiSnips-contrisnippets*
|
||||
|
@ -227,6 +227,11 @@ endf
|
||||
function! UltiSnips_LeavingBuffer()
|
||||
exec g:_uspy "UltiSnips_Manager.leaving_buffer()"
|
||||
endf
|
||||
|
||||
function! UltiSnips_LeavingInsertMode()
|
||||
exec g:_uspy "UltiSnips_Manager.restore_unnamed_register()"
|
||||
endfunction
|
||||
|
||||
" }}}
|
||||
" COMPLETE FUNCTIONS {{{
|
||||
function! UltiSnipsFiletypeComplete(arglead, cmdline, cursorpos)
|
||||
@ -262,6 +267,7 @@ exec g:_uspy "UltiSnips_Manager.backward_trigger = vim.eval('g:UltiSnipsJumpBack
|
||||
au CursorMovedI * call UltiSnips_CursorMoved()
|
||||
au CursorMoved * call UltiSnips_CursorMoved()
|
||||
au BufLeave * call UltiSnips_LeavingBuffer()
|
||||
au InsertLeave * call UltiSnips_LeavingInsertMode()
|
||||
|
||||
call UltiSnips_MapKeys()
|
||||
|
||||
|
@ -553,8 +553,13 @@ class SnippetManager(object):
|
||||
self._supertab_keys = None
|
||||
self._csnippets = []
|
||||
|
||||
# needed to retain the unnamed register at all times
|
||||
self._unnamed_reg_cached = False
|
||||
self._last_placeholder = None
|
||||
|
||||
self.reset()
|
||||
|
||||
|
||||
@err_to_scratch_buffer
|
||||
def reset(self, test_error=False):
|
||||
self._vstate = VimState()
|
||||
@ -832,10 +837,24 @@ class SnippetManager(object):
|
||||
self._current_snippet_is_done()
|
||||
jumped = self._jump(backwards)
|
||||
if jumped:
|
||||
self._cache_unnamed_register()
|
||||
self._vstate.remember_position()
|
||||
self._ignore_movements = True
|
||||
return jumped
|
||||
|
||||
def _cache_unnamed_register(self):
|
||||
self._unnamed_reg_cached = True
|
||||
unnamed_reg = _vim.eval('@"')
|
||||
if self._last_placeholder != unnamed_reg:
|
||||
self._unnamed_reg_cache = unnamed_reg
|
||||
self._last_placeholder = self._ctab._initial_text
|
||||
|
||||
def restore_unnamed_register(self):
|
||||
if self._unnamed_reg_cached:
|
||||
escaped_cache = self._unnamed_reg_cache.replace("'", "''")
|
||||
_vim.command("let @\"='%s'" % escaped_cache)
|
||||
self._unnamed_register_cached = False
|
||||
|
||||
def _handle_failure(self, trigger):
|
||||
"""
|
||||
Mainly make sure that we play well with SuperTab
|
||||
|
7
test.py
7
test.py
@ -3041,6 +3041,13 @@ class Bug1251994(_VimTest):
|
||||
wanted = " world hello;blub"
|
||||
# End: 1251994 #}}}
|
||||
|
||||
# Test for Github Pull Request #134 {{{#
|
||||
class RetainsTheUnnamedRegister(_VimTest):
|
||||
snippets = ("test", "${1:hello} ${2:world} ${0}")
|
||||
keys = "yank" + ESC + "by4lea test" + EX + "HELLO" + JF + JF + ESC + "p"
|
||||
wanted = "yank HELLO world yank"
|
||||
# End: Github Pull Request # 134 #}}}
|
||||
|
||||
class VerifyVimDict1(_VimTest):
|
||||
"""check:
|
||||
correct type (4 means vim dictionary)
|
||||
|
Loading…
Reference in New Issue
Block a user