Fix indent for blocks in template

This commit is contained in:
leafOfTree
2021-03-31 18:37:28 +08:00
parent 01e460244f
commit b617e1e110

View File

@@ -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 let ind = 0
endif endif
endif else
" When 'pug' syntax in <template>, set current line
if prevline =~ s:block_tag && prevline !~ s:template_tag if a:syntax == 'pug'
let ind = 0 if curline =~ s:block_tag
let ind = 0
endif
endif
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