mirror of
https://github.com/tpope/vim-surround.git
synced 2025-11-10 12:23:50 -05:00
Fix edgecase where ds would move the inner text
This commit is contained in:
@@ -424,8 +424,9 @@ function! s:dosurround(...) " {{{1
|
||||
exe 'norm '.strcount.'[/d'.strcount.']/'
|
||||
else
|
||||
exe 'norm d'.strcount.'i'.char
|
||||
" One character backwards
|
||||
call search('.','bW')
|
||||
endif
|
||||
"exe "norm vi".char."d"
|
||||
let keeper = getreg('"')
|
||||
let okeeper = keeper " for reindent below
|
||||
if keeper == ""
|
||||
@@ -436,8 +437,6 @@ function! s:dosurround(...) " {{{1
|
||||
let oldline = getline('.')
|
||||
let oldlnum = line('.')
|
||||
if char ==# "p"
|
||||
"let append = matchstr(keeper,'\n*\%$')
|
||||
"let keeper = substitute(keeper,'\n*\%$','','')
|
||||
call setreg('"','','V')
|
||||
elseif char ==# "s" || char ==# "w" || char ==# "W"
|
||||
" Do nothing
|
||||
@@ -450,32 +449,23 @@ function! s:dosurround(...) " {{{1
|
||||
call setreg('"','/**/',"c")
|
||||
let keeper = substitute(substitute(keeper,'^/\*\s\=','',''),'\s\=\*$','','')
|
||||
else
|
||||
exe "norm! da".char
|
||||
exe "norm da".char
|
||||
endif
|
||||
let removed = getreg('"')
|
||||
let rem2 = substitute(removed,'\n.*','','')
|
||||
let oldhead = strpart(oldline,0,strlen(oldline)-strlen(rem2))
|
||||
let oldtail = strpart(oldline, strlen(oldline)-strlen(rem2))
|
||||
let regtype = getregtype('"')
|
||||
if char == 'p'
|
||||
let regtype = "V"
|
||||
endif
|
||||
if char =~# '[\[({<T]' || spc
|
||||
let keeper = substitute(keeper,'^\s\+','','')
|
||||
let keeper = substitute(keeper,'\s\+$','','')
|
||||
endif
|
||||
if col("']") == col("$") && col('.') + 1 == col('$')
|
||||
"let keeper = substitute(keeper,'^\n\s*','','')
|
||||
"let keeper = substitute(keeper,'\n\s*$','','')
|
||||
if oldhead =~# '^\s*$' && a:0 < 2
|
||||
"let keeper = substitute(keeper,oldhead.'\%$','','')
|
||||
let keeper = substitute(keeper,'\%^\n'.oldhead.'\(\s*.\{-\}\)\n\s*\%$','\1','')
|
||||
endif
|
||||
let pcmd = "p"
|
||||
else
|
||||
if oldhead == "" && a:0 < 2
|
||||
"let keeper = substitute(keeper,'\%^\n\(.*\)\n\%$','\1','')
|
||||
endif
|
||||
let pcmd = "P"
|
||||
endif
|
||||
if line('.') < oldlnum && regtype ==# "V"
|
||||
@@ -488,7 +478,6 @@ function! s:dosurround(...) " {{{1
|
||||
silent exe 'norm! ""'.pcmd.'`['
|
||||
if removed =~ '\n' || okeeper =~ '\n' || getreg('"') =~ '\n'
|
||||
call s:reindent()
|
||||
else
|
||||
endif
|
||||
if getline('.') =~ '^\s\+$' && keeper =~ '^\s*\n'
|
||||
silent norm! cc
|
||||
|
||||
Reference in New Issue
Block a user