Skip to content

Commit 68a97bb

Browse files
committed
Fix add property in some weird cases
1 parent bf5afad commit 68a97bb

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

plugin/php-refactoring-toolbox.vim

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
" Maintainer: Pierrick Charron <pierrick@adoy.net>
55
" URL: https://github.com/adoy/vim-php-refactoring-toolbox
66
" License: MIT
7-
" Version: 1.0.1
7+
" Version: 1.0.2
88
"
99

1010
" Config {{{
@@ -353,21 +353,30 @@ endfunction
353353
" }}}
354354

355355
function! s:PhpInsertProperty(name, visibility) " {{{
356-
if search(s:php_regex_member_line, 'beW') > 0
357-
let l:insertLine = line('.')+1
358-
elseif search(s:php_regex_const_line, 'beW') > 0
359-
let l:insertLine = line('.')+1
360-
elseif search(s:php_regex_class_line, 'beW') > 0
361-
call search('{', 'W')
362-
let l:insertLine = line('.')
363-
else
364-
let l:insertLine = line('.')
365-
endif
366-
call append(l:insertLine, '/**')
367-
call append(l:insertLine+1, '* @var mixed')
368-
call append(l:insertLine+2, '*/')
369-
call append(l:insertLine+3, a:visibility . " $" . a:name . ';')
370-
call append(l:insertLine+4, "")
356+
let l:regex = '\%(' . join([s:php_regex_member_line, s:php_regex_const_line, s:php_regex_class_line], '\)\|\(') .'\)'
357+
if search(l:regex, 'beW') > 0
358+
let l:line = getbufline("%", line('.'))[0]
359+
if match(l:line, s:php_regex_class_line) > -1
360+
call search('{', 'W')
361+
call append(line('.'), "")
362+
let l:insertLine = line('.')
363+
else
364+
call append(line('.'), "")
365+
let l:insertLine = line('.') + 1
366+
endif
367+
else
368+
call append(line('.'), "")
369+
let l:insertLine = line('.')
370+
endif
371+
call s:PhpInsertPropertyExtended(a:name, a:visibility, l:insertLine)
372+
endfunction
373+
" }}}
374+
375+
function! s:PhpInsertPropertyExtended(name, visibility, insertLine) " {{{
376+
call append(a:insertLine, '/**')
377+
call append(a:insertLine+1, '* @var mixed')
378+
call append(a:insertLine+2, '*/')
379+
call append(a:insertLine+3, a:visibility . " $" . a:name . ';')
371380
normal j=5=
372381
endfunction
373382
" }}}

0 commit comments

Comments
 (0)