Skip to content

Commit 9af1741

Browse files
committed
Final point of #19
1 parent 1ea8853 commit 9af1741

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

autoload/autopairs.vim

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,12 @@ func! autopairs#AutoPairsDelete()
467467
end
468468

469469
let [before, after, ig] = s:getline()
470+
470471
for [open, close, opt] in b:AutoPairsList
471472
let rest_of_line = opt['multiline'] ? after : ig
472473
let b = matchstr(before, '\V'.open.'\v\s?$')
473474
let a = matchstr(rest_of_line, '^\v\s*\V'.close)
475+
474476
if b != '' && a != ''
475477
if b[-1:-1] == ' '
476478
if a[0] == ' '
@@ -483,12 +485,30 @@ func! autopairs#AutoPairsDelete()
483485
end
484486
endfor
485487

486-
return "\<BS>"
487488
" delete the pair foo[]| <BS> to foo
488489
for [open, close, opt] in b:AutoPairsList
489490
let m = s:matchend(before, '\V'.open.'\v\s*'.'\V'.close.'\v$')
491+
490492
if len(m) > 0
491493
return s:backspace(m[2])
494+
else
495+
let m = matchstr(before, '^\v\s*\V' . close)
496+
if m != ''
497+
let b = ""
498+
let offset = 1
499+
" a = m
500+
while getline(line('.') - offset) =~ "^\s*$"
501+
let b .= getline(line('.') - offset) . ' '
502+
let offset += 1
503+
if (line('.') - offset == 0)
504+
return "\<BS>"
505+
endif
506+
endwhile
507+
let a = matchstr(getline(line('.') - offset), '\V' . open . '\v\s*$') . ' '
508+
if a != '' || b != ''
509+
return s:backspace(a) . s:backspace(b) . s:backspace(m)
510+
endif
511+
endif
492512
end
493513
endfor
494514
return "\<BS>"
@@ -656,7 +676,7 @@ func! autopairs#AutoPairsReturn()
656676
end
657677

658678
let b:autopairs_return_pos = 0
659-
let before = getline(line('.')-1)
679+
let before = getline(line('.') - 1)
660680
let [ig, ig, afterline] = s:getline()
661681

662682
for [open, close, opt] in b:AutoPairsList

0 commit comments

Comments
 (0)