Add more precise undo levels (expanding, jumping)

Breaking undo achieved through re-setting &undolevel:

    Setting the value of 'undolevels' also breaks undo. Even when the new
    value is equal to the old value.

    [:h :undoj]
This commit is contained in:
Stanislav Seletskiy 2015-04-25 23:34:06 +06:00
parent aeb2e24204
commit 099d3bcfbc
2 changed files with 40 additions and 8 deletions

View File

@ -111,6 +111,7 @@ class SnippetManager(object):
def jump_forwards(self): def jump_forwards(self):
"""Jumps to the next tabstop.""" """Jumps to the next tabstop."""
_vim.command('let g:ulti_jump_forwards_res = 1') _vim.command('let g:ulti_jump_forwards_res = 1')
_vim.command('let &undolevels = &undolevels')
if not self._jump(): if not self._jump():
_vim.command('let g:ulti_jump_forwards_res = 0') _vim.command('let g:ulti_jump_forwards_res = 0')
return self._handle_failure(self.forward_trigger) return self._handle_failure(self.forward_trigger)
@ -119,6 +120,7 @@ class SnippetManager(object):
def jump_backwards(self): def jump_backwards(self):
"""Jumps to the previous tabstop.""" """Jumps to the previous tabstop."""
_vim.command('let g:ulti_jump_backwards_res = 1') _vim.command('let g:ulti_jump_backwards_res = 1')
_vim.command('let &undolevels = &undolevels')
if not self._jump(True): if not self._jump(True):
_vim.command('let g:ulti_jump_backwards_res = 0') _vim.command('let g:ulti_jump_backwards_res = 0')
return self._handle_failure(self.backward_trigger) return self._handle_failure(self.backward_trigger)
@ -575,13 +577,15 @@ class SnippetManager(object):
if not snippets: if not snippets:
# No snippet found # No snippet found
return False return False
elif len(snippets) == 1: _vim.command('let &undolevels = &undolevels')
if len(snippets) == 1:
snippet = snippets[0] snippet = snippets[0]
else: else:
snippet = _ask_snippets(snippets) snippet = _ask_snippets(snippets)
if not snippet: if not snippet:
return True return True
self._do_snippet(snippet, before) self._do_snippet(snippet, before)
_vim.command('let &undolevels = &undolevels')
return True return True
@property @property

View File

@ -6,8 +6,8 @@ from test.constant import *
class Undo_RemoveMultilineSnippet(_VimTest): class Undo_RemoveMultilineSnippet(_VimTest):
snippets = ('test', 'Hello\naaa ${1} bbb\nWorld') snippets = ('test', 'Hello\naaa ${1} bbb\nWorld')
keys = 'test' + EX + ESC + 'u' + 'inothing' keys = 'test' + EX + ESC + 'u'
wanted = 'nothing' wanted = 'test'
class Undo_RemoveEditInTabstop(_VimTest): class Undo_RemoveEditInTabstop(_VimTest):
@ -19,15 +19,43 @@ class Undo_RemoveEditInTabstop(_VimTest):
class Undo_RemoveWholeSnippet(_VimTest): class Undo_RemoveWholeSnippet(_VimTest):
snippets = ('test', 'Hello\n${1:Hello}World') snippets = ('test', 'Hello\n${1:Hello}World')
keys = 'first line\n\n\n\n\n\nthird line' + \ keys = 'first line\n\n\n\n\n\nthird line' + \
ESC + '3k0itest' + EX + ESC + 'uiupsy' ESC + '3k0itest' + EX + ESC + 'u6j'
wanted = 'first line\n\n\nupsy\n\n\nthird line' wanted = 'first line\n\n\ntest\n\n\nthird line'
class Undo_RemoveOneSnippetByTime(_VimTest):
snippets = ('i', 'if:\n\t$1')
keys = 'i' + EX + 'i' + EX + ESC + 'u'
wanted = 'if:\n\ti'
class Undo_RemoveOneSnippetByTime2(_VimTest):
snippets = ('i', 'if:\n\t$1')
keys = 'i' + EX + 'i' + EX + ESC + 'uu'
wanted = 'if:\n\t'
class Undo_ChangesInPlaceholder(_VimTest):
snippets = ('i', 'if $1:\n\t$2')
keys = 'i' + EX + 'asd' + JF + ESC + 'u'
wanted = 'if :\n\t'
class Undo_CompletelyUndoSnippet(_VimTest):
snippets = ('i', 'if $1:\n\t$2')
# undo 'feh'
# undo 'asd'
# undo snippet expansion
# undo entering of 'i'
keys = 'i' + EX + 'asd' + JF + 'feh' + ESC + 'uuuu'
wanted = ''
class JumpForward_DefSnippet(_VimTest): class JumpForward_DefSnippet(_VimTest):
snippets = ( snippets = (
'test', 'test',
"${1}\n`!p snip.rv = '\\n'.join(t[1].split())`\n\n${0:pass}") "${1}\n`!p snip.rv = '\\n'.join(t[1].split())`\n\n${0:pass}")
keys = 'test' + EX + 'a b c' + JF + 'shallnot' keys = 'test' + EX+ 'a b c' + JF + 'shallnot'
wanted = 'a b c\na\nb\nc\n\nshallnot' wanted = 'a b c\na\nb\nc\n\nshallnot'
@ -39,8 +67,8 @@ class DeleteSnippetInsertion0(_VimTest):
class DeleteSnippetInsertion1(_VimTest): class DeleteSnippetInsertion1(_VimTest):
snippets = ('test', r"$1${1/(.*)/(?0::.)/}") snippets = ('test', r"$1${1/(.*)/(?0::.)/}")
keys = 'test' + EX + ESC + 'u' + 'i' + JF + '\t' keys = 'test' + EX + ESC + 'u'
wanted = '\t' wanted = 'test'
# End: Undo of Snippet insertion #}}} # End: Undo of Snippet insertion #}}}
# Normal mode editing {{{# # Normal mode editing {{{#