Fixed a bug that could happen when a whole snippet was deleted.

This commit is contained in:
Holger Rapp 2012-01-31 08:12:05 +01:00
parent 634fdeb282
commit 8c9bf502f2
2 changed files with 11 additions and 4 deletions

View File

@ -16,8 +16,11 @@ def is_complete_edit(initial_line, a, b, cmds):
if char != '\n': if char != '\n':
buf[line] = buf[line][:col] + buf[line][col+len(char):] buf[line] = buf[line][:col] + buf[line][col+len(char):]
else: else:
buf[line] = buf[line] + buf[line+1] if len(buf) > 1:
del buf[line+1] buf[line] = buf[line] + buf[line+1]
del buf[line+1]
else:
del buf[line]
elif ctype == "I": elif ctype == "I":
buf[line] = buf[line][:col] + char + buf[line][col:] buf[line] = buf[line][:col] + char + buf[line][col:]
buf = '\n'.join(buf).split('\n') buf = '\n'.join(buf).split('\n')
@ -34,11 +37,11 @@ def guess_edit(initial_line, lt, ct, vs):
ppos = vs.ppos ppos = vs.ppos
if len(lt) and (not ct or (len(ct) == 1 and not ct[0])): # All text deleted? if len(lt) and (not ct or (len(ct) == 1 and not ct[0])): # All text deleted?
es = [] es = []
if not ct: ct = ['']
for i in lt: for i in lt:
es.append(("D", initial_line, 0, i)) es.append(("D", initial_line, 0, i))
es.append(("D", initial_line, 0, "\n")) 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 is_complete_edit(initial_line, lt, ct, es): return True, es
if ppos.mode == 'v': # Maybe selectmode? if ppos.mode == 'v': # Maybe selectmode?
sv = list(map(int, _vim.eval("""getpos("'<")"""))); sv = Position(sv[1]-1,sv[2]-1) sv = list(map(int, _vim.eval("""getpos("'<")"""))); sv = Position(sv[1]-1,sv[2]-1)

View File

@ -2520,6 +2520,10 @@ class JumpForward_DefSnippet(_VimTest):
snippets = ("test", "${1}\n`!p snip.rv = '\\n'.join(t[1].split())`\n\n${0:pass}") 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" keys = "test" + EX + "a b c" + JF + "shallnot" + JF + "end"
wanted = "a b c\na\nb\nc\n\nshallnotend" 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 #}}} # End: Undo of Snippet insertion #}}}
# Tab Completion of Words {{{# # Tab Completion of Words {{{#