mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2026-08-12 19:06:55 +08:00
Fix incorrect fold for template
This commit is contained in:
+12
-8
@@ -54,39 +54,43 @@ function! GetVueFold(lnum)
|
|||||||
let prev_line = getline(a:lnum - 1)
|
let prev_line = getline(a:lnum - 1)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Empty lines
|
" Handle empty lines
|
||||||
if this_line =~ s:empty_line
|
if this_line =~ s:empty_line
|
||||||
return -1
|
return -1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Vue tag
|
" Handle start/end tags
|
||||||
if this_line =~ s:vue_tag_start
|
if this_line =~ s:vue_tag_start
|
||||||
return '>1'
|
return '>1'
|
||||||
elseif this_line =~ s:vue_tag_end
|
endif
|
||||||
return '<1'
|
if this_line =~ s:vue_tag_end
|
||||||
|
" If return '<1', fold will get incorrect with prev line
|
||||||
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Use (indentLevel + 1) as fold level
|
" Fold by indent
|
||||||
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 a:lnum > 1
|
||||||
let prev_indent = s:IndentLevel(a:lnum - 1)
|
let prev_indent = s:IndentLevel(a:lnum - 1)
|
||||||
|
|
||||||
if (this_line =~ s:block_end) && (this_indent < prev_indent)
|
if this_indent < prev_indent
|
||||||
return prev_indent
|
return prev_indent
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if this_indent >= next_indent
|
if this_indent >= next_indent
|
||||||
return this_indent
|
return this_indent
|
||||||
elseif this_indent < next_indent
|
endif
|
||||||
|
|
||||||
|
if this_indent < next_indent
|
||||||
return '>'.next_indent
|
return '>'.next_indent
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:IndentLevel(lnum)
|
function! s:IndentLevel(lnum)
|
||||||
" Add 1 to enable vue tags to fold
|
" Add 1 to indentLevel, so start/end tags' can fold properly
|
||||||
return indent(a:lnum) / &shiftwidth + 1
|
return indent(a:lnum) / &shiftwidth + 1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user