mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-10 22:51:52 +08:00
Fix indent for blocks in template
This commit is contained in:
@@ -78,20 +78,23 @@ function! s:GetBlockIndent(syntax)
|
|||||||
return ind
|
return ind
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:GetIndentByContext(syntax)
|
function! s:GetIndentByContext(tag, syntax)
|
||||||
let ind = -1
|
let ind = -1
|
||||||
let prevline = getline(s:PrevNonBlankNonComment(v:lnum))
|
let prevline = getline(s:PrevNonBlankNonComment(v:lnum))
|
||||||
let curline = getline(v:lnum)
|
let curline = getline(v:lnum)
|
||||||
|
|
||||||
" 0 for blocks except template as it can be nested
|
" When not in <template>, set block tags indent to 0
|
||||||
if curline =~ s:block_tag &&
|
if a:tag != 'template'
|
||||||
\ (curline !~ s:template_tag || a:syntax == 'pug')
|
if curline =~ s:block_tag || prevline =~ s:block_tag
|
||||||
|
let ind = 0
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
" When 'pug' syntax in <template>, set current line
|
||||||
|
if a:syntax == 'pug'
|
||||||
|
if curline =~ s:block_tag
|
||||||
let ind = 0
|
let ind = 0
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if prevline =~ s:block_tag && prevline !~ s:template_tag
|
|
||||||
let ind = 0
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ind
|
return ind
|
||||||
@@ -191,8 +194,9 @@ function! s:AdjustHTMLIndent(ind)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! GetVueIndent()
|
function! GetVueIndent()
|
||||||
|
let tag = vue#GetBlockTag(v:lnum)
|
||||||
let syntax = vue#GetBlockSyntax(v:lnum)
|
let syntax = vue#GetBlockSyntax(v:lnum)
|
||||||
let ind = s:GetIndentByContext(syntax)
|
let ind = s:GetIndentByContext(tag, syntax)
|
||||||
if ind == -1
|
if ind == -1
|
||||||
let ind = s:GetBlockIndent(syntax)
|
let ind = s:GetBlockIndent(syntax)
|
||||||
let ind = s:AdjustBlockIndent(syntax, ind)
|
let ind = s:AdjustBlockIndent(syntax, ind)
|
||||||
@@ -201,7 +205,6 @@ function! GetVueIndent()
|
|||||||
call vue#LogWithLnum('context, ind '.ind)
|
call vue#LogWithLnum('context, ind '.ind)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let tag = vue#GetBlockTag(v:lnum)
|
|
||||||
let ind = s:CheckInitIndent(tag, ind)
|
let ind = s:CheckInitIndent(tag, ind)
|
||||||
return ind
|
return ind
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user