Handle folding in script and template/style separately

This commit is contained in:
leafOfTree
2020-04-13 14:53:02 +08:00
parent e237cabce1
commit 6a958cedcc
2 changed files with 28 additions and 13 deletions

View File

@@ -69,24 +69,35 @@ function! GetVueFold(lnum)
endif endif
" Fold by indent " Fold by indent
if a:lnum > 1
let prev_indent = s:IndentLevel(a:lnum - 1)
else
let prev_indent = 0
endif
let this_indent = s:IndentLevel(a:lnum) let this_indent = s:IndentLevel(a:lnum)
let next_indent = s:IndentLevel(s:NextNonBlankLine(a:lnum)) let next_indent = s:IndentLevel(s:NextNonBlankLine(a:lnum))
if a:lnum > 1 if GetVueTag(a:lnum) == 'script'
let prev_indent = s:IndentLevel(a:lnum - 1) " Handle closing '}'
if this_line =~ '\v^\s*},?\s*$'
if this_indent < prev_indent return '<'.prev_indent
return prev_indent
endif endif
endif
if this_indent >= next_indent " --this
" ----next
if this_indent < next_indent
return '>'.next_indent
endif
" ----this
" --next
if this_indent >= next_indent
return this_indent
endif
else
" Template or style
return this_indent return this_indent
endif endif
if this_indent < next_indent
return '>'.next_indent
endif
endfunction endfunction
function! s:IndentLevel(lnum) function! s:IndentLevel(lnum)

View File

@@ -269,8 +269,12 @@ function! s:PrevNonBlacnkNonComment(lnum)
return prevlnum return prevlnum
endfunction endfunction
function! GetVueTag() function! GetVueTag(...)
let lnum = getcurpos()[1] if a:0 > 0
let lnum = a:1
else
let lnum = getcurpos()[1]
endif
let cursyns = s:SynsEOL(lnum) let cursyns = s:SynsEOL(lnum)
let syn = get(cursyns, 0, '') let syn = get(cursyns, 0, '')