Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 8c9bf502f2a5c1514e8acbf710fbf1c6e337dedf 1 parent 634fdeb
@SirVer SirVer authored
Showing with 11 additions and 4 deletions.
  1. +7 −4 plugin/UltiSnips/_diff.py
  2. +4 −0 test.py
View
11 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)
View
4 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 {{{#
Please sign in to comment.
Something went wrong with that request. Please try again.