From 6a958cedcc2b230c598ca1884867130b2cc1c42f Mon Sep 17 00:00:00 2001 From: leafOfTree Date: Mon, 13 Apr 2020 14:53:02 +0800 Subject: [PATCH] Handle folding in script and template/style separately --- ftplugin/vue/fold.vim | 33 ++++++++++++++++++++++----------- indent/vue.vim | 8 ++++++-- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/ftplugin/vue/fold.vim b/ftplugin/vue/fold.vim index 387a27c..0aa8cf6 100644 --- a/ftplugin/vue/fold.vim +++ b/ftplugin/vue/fold.vim @@ -69,24 +69,35 @@ function! GetVueFold(lnum) endif " 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 next_indent = s:IndentLevel(s:NextNonBlankLine(a:lnum)) - if a:lnum > 1 - let prev_indent = s:IndentLevel(a:lnum - 1) - - if this_indent < prev_indent - return prev_indent + if GetVueTag(a:lnum) == 'script' + " Handle closing '}' + if this_line =~ '\v^\s*},?\s*$' + return '<'.prev_indent 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 endif - - if this_indent < next_indent - return '>'.next_indent - endif endfunction function! s:IndentLevel(lnum) diff --git a/indent/vue.vim b/indent/vue.vim index f2d8ee8..179a6d6 100644 --- a/indent/vue.vim +++ b/indent/vue.vim @@ -269,8 +269,12 @@ function! s:PrevNonBlacnkNonComment(lnum) return prevlnum endfunction -function! GetVueTag() - let lnum = getcurpos()[1] +function! GetVueTag(...) + if a:0 > 0 + let lnum = a:1 + else + let lnum = getcurpos()[1] + endif let cursyns = s:SynsEOL(lnum) let syn = get(cursyns, 0, '')