Fix template in pug indent error

This commit is contained in:
leafOfTree
2021-03-30 13:20:42 +08:00
parent 665d8a18b3
commit fc75f3c474
2 changed files with 11 additions and 6 deletions

View File

@@ -4,6 +4,8 @@
if exists('b:did_indent') | finish |endif
let s:test = exists('g:vim_vue_plugin_test')
function! s:Init()
""" Configs
let s:config = vue#GetConfig('config', {})
@@ -76,13 +78,14 @@ function! s:GetBlockIndent(syntax)
return ind
endfunction
function! s:GetIndentByContext()
function! s:GetIndentByContext(syntax)
let ind = -1
let prevline = getline(s:PrevNonBlankNonComment(v:lnum))
let curline = getline(v:lnum)
" 0 for blocks except template as it can be nested
if curline =~ s:block_tag && curline !~ s:template_tag
if curline =~ s:block_tag &&
\ (curline !~ s:template_tag || a:syntax == 'pug')
let ind = 0
endif
endif
@@ -188,9 +191,9 @@ function! s:AdjustHTMLIndent(ind)
endfunction
function! GetVueIndent()
let ind = s:GetIndentByContext()
let syntax = vue#GetBlockSyntax(v:lnum)
let ind = s:GetIndentByContext(syntax)
if ind == -1
let syntax = vue#GetBlockSyntax(v:lnum)
let ind = s:GetBlockIndent(syntax)
let ind = s:AdjustBlockIndent(syntax, ind)
call vue#LogWithLnum('syntax '.syntax.', ind '.ind)
@@ -210,7 +213,7 @@ function! VimVuePluginIndentMain(...)
call s:SetVueIndent()
endfunction
if exists('*timer_start')
if exists('*timer_start') && !s:test
call timer_start(50, 'VimVuePluginIndentMain')
else
call VimVuePluginIndentMain()

View File

@@ -9,6 +9,8 @@ endif
" <sfile> is replaced with the file name of the sourced file
let s:patch_path = expand('<sfile>:p:h').'/patch'
let s:test = exists('g:vim_vue_plugin_test')
function! s:Init()
""" Configs
let s:config = vue#GetConfig('config', {})
@@ -165,7 +167,7 @@ function! VimVuePluginSyntaxMain(...)
call s:HighlightVueTag()
endfunction
if exists('*timer_start')
if exists('*timer_start') && !s:test
call timer_start(1, 'VimVuePluginSyntaxMain')
else
call VimVuePluginSyntaxMain()