From 8c9bf502f2a5c1514e8acbf710fbf1c6e337dedf Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Tue, 31 Jan 2012 08:12:05 +0100 Subject: [PATCH] Fixed a bug that could happen when a whole snippet was deleted. --- plugin/UltiSnips/_diff.py | 11 +++++++---- test.py | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plugin/UltiSnips/_diff.py b/plugin/UltiSnips/_diff.py index 73ba685..fdc1076 100644 --- a/plugin/UltiSnips/_diff.py +++ b/plugin/UltiSnips/_diff.py @@ -16,8 +16,11 @@ def is_complete_edit(initial_line, a, b, cmds): if char != '\n': buf[line] = buf[line][:col] + buf[line][col+len(char):] else: - buf[line] = buf[line] + buf[line+1] - del buf[line+1] + if len(buf) > 1: + buf[line] = buf[line] + buf[line+1] + del buf[line+1] + else: + del buf[line] elif ctype == "I": buf[line] = buf[line][:col] + char + buf[line][col:] buf = '\n'.join(buf).split('\n') @@ -34,11 +37,11 @@ def guess_edit(initial_line, lt, ct, vs): ppos = vs.ppos if len(lt) and (not ct or (len(ct) == 1 and not ct[0])): # All text deleted? es = [] + if not ct: ct = [''] for i in lt: es.append(("D", initial_line, 0, i)) es.append(("D", initial_line, 0, "\n")) - if ct: - es.pop() # Remove final \n because it is not really removed + es.pop() # Remove final \n because it is not really removed if is_complete_edit(initial_line, lt, ct, es): return True, es if ppos.mode == 'v': # Maybe selectmode? sv = list(map(int, _vim.eval("""getpos("'<")"""))); sv = Position(sv[1]-1,sv[2]-1) diff --git a/test.py b/test.py index 1a3564e..b4fde7a 100755 --- a/test.py +++ b/test.py @@ -2520,6 +2520,10 @@ class JumpForward_DefSnippet(_VimTest): snippets = ("test", "${1}\n`!p snip.rv = '\\n'.join(t[1].split())`\n\n${0:pass}") keys = "test" + EX + "a b c" + JF + "shallnot" + JF + "end" wanted = "a b c\na\nb\nc\n\nshallnotend" +class DeleteSnippetInsertion(_VimTest): + snippets = ("test", "${1:hello} $1") + keys = "test" + EX + ESC + "Vkx" + "i\nworld\n" + wanted = "world" # End: Undo of Snippet insertion #}}} # Tab Completion of Words {{{#