mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2026-11-01 18:12:19 +08:00
Support shiftwidth=0 in indent and fold
With shiftwidth=0, Vim uses the value of tabstop, but &sw is 0. So multiline tags and brackets got wrong indent, and fold levels were wrong as indent was divided by 0. Use shiftwidth() instead, which is the same as &sw when it isn't 0.
This commit is contained in:
4 files changed
+50
-15
No files matched your search
@@ -88,7 +88,7 @@ endfunction
|
||||
|
||||
function! s:IndentLevel(lnum)
|
||||
" Add 1 to indentLevel, so start/end tags can fold properly
|
||||
return indent(a:lnum) / &shiftwidth + 1
|
||||
return indent(a:lnum) / shiftwidth() + 1
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
|
||||
+14
-14
@@ -148,7 +148,7 @@ function! s:CheckInitialIndent(tag, syntax, ind)
|
||||
endif
|
||||
if add
|
||||
call vue#LogWithLnum('add initial indent')
|
||||
let ind = &sw
|
||||
let ind = shiftwidth()
|
||||
endif
|
||||
return ind
|
||||
endfunction
|
||||
@@ -183,16 +183,16 @@ function! s:AdjustHTMLIndent(ind)
|
||||
|
||||
if prevline =~? s:empty_tag
|
||||
call vue#LogWithLnum('previous line is an empty tag')
|
||||
let ind = ind - &sw
|
||||
let ind = ind - shiftwidth()
|
||||
endif
|
||||
|
||||
" Align '/>' and '>' with '<'
|
||||
if curline =~? s:tag_end
|
||||
let ind = ind - &sw
|
||||
let ind = ind - shiftwidth()
|
||||
endif
|
||||
" Then correct the indentation of any element following '/>' or '>'.
|
||||
if prevline =~? s:tag_end
|
||||
let ind = ind + &sw
|
||||
let ind = ind + shiftwidth()
|
||||
|
||||
" Decrease indent if prevlines are a multiline empty tag
|
||||
let [start, end] = s:PrevMultilineEmptyTag(v:lnum)
|
||||
@@ -200,7 +200,7 @@ function! s:AdjustHTMLIndent(ind)
|
||||
call vue#LogWithLnum('previous line is a multiline empty tag')
|
||||
let ind = indent(v:lnum - 1)
|
||||
if curline =~? s:full_tag_end
|
||||
let ind = ind - &sw
|
||||
let ind = ind - shiftwidth()
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@@ -210,17 +210,17 @@ function! s:AdjustHTMLIndent(ind)
|
||||
" ]
|
||||
if prevline =~ '[[{]\s*$'
|
||||
call vue#LogWithLnum('previous line is an open bracket')
|
||||
let ind = indent(prevlnum) + &sw
|
||||
let ind = indent(prevlnum) + shiftwidth()
|
||||
endif
|
||||
if curline =~ '^\s*[]}][^"]*"\?\s*$'
|
||||
call vue#LogWithLnum('current line is a closing bracket')
|
||||
let ind = indent(prevlnum) - &sw
|
||||
let ind = indent(prevlnum) - shiftwidth()
|
||||
endif
|
||||
|
||||
" Multiline ternary 'a ? b : c' in attribute
|
||||
if curline =~ s:ternary_q
|
||||
call vue#LogWithLnum('current line is ?...')
|
||||
let ind = indent(prevlnum) + &sw
|
||||
let ind = indent(prevlnum) + shiftwidth()
|
||||
endif
|
||||
if curline =~ s:ternary_e && prevline =~ s:ternary_q
|
||||
call vue#LogWithLnum('current line is :...')
|
||||
@@ -228,13 +228,13 @@ function! s:AdjustHTMLIndent(ind)
|
||||
endif
|
||||
if prevline =~ s:ternary_e
|
||||
call vue#LogWithLnum('prevline line is :...')
|
||||
let ind = indent(prevlnum) - &sw
|
||||
let ind = indent(prevlnum) - shiftwidth()
|
||||
endif
|
||||
|
||||
" Angle bracket in attribute, like v-if="isEnabled('item.<name>')"
|
||||
if prevline =~ '="[^"]*<[^"]*>[^"]*"'
|
||||
call vue#LogWithLnum('prevline line is angle bracket in attribute')
|
||||
let ind = ind - &sw
|
||||
let ind = ind - shiftwidth()
|
||||
endif
|
||||
|
||||
return ind
|
||||
@@ -248,7 +248,7 @@ function! s:AdjustJavaScriptIndent(ind)
|
||||
|
||||
if prevline =~ '^\s*\w.*$' && curline =~ '^\s*\.'
|
||||
call vue#LogWithLnum('current line is the first chain call')
|
||||
let ind = indent(prevlnum) + &sw
|
||||
let ind = indent(prevlnum) + shiftwidth()
|
||||
endif
|
||||
|
||||
if prevline =~ '\s=>\s.*,\s*$' && curline !~ '^\s*[]}])\?,\?\s*$'
|
||||
@@ -257,7 +257,7 @@ function! s:AdjustJavaScriptIndent(ind)
|
||||
endif
|
||||
if prevline =~ '\s||\s*$'
|
||||
call vue#LogWithLnum('previous line ends with "||"')
|
||||
let ind = indent(prevlnum) + &sw
|
||||
let ind = indent(prevlnum) + shiftwidth()
|
||||
endif
|
||||
return ind
|
||||
endfunction
|
||||
@@ -270,11 +270,11 @@ function! s:AdjustCSSIndent(ind)
|
||||
|
||||
if prevline =~ ':\s.*,\s*$'
|
||||
call vue#LogWithLnum('previous line is css function')
|
||||
let ind = indent(prevlnum) + &sw
|
||||
let ind = indent(prevlnum) + shiftwidth()
|
||||
endif
|
||||
if curline =~ '^\s*);\?\s*$'
|
||||
call vue#LogWithLnum('curline is closing round bracket')
|
||||
let ind = indent(prevlnum) - &sw
|
||||
let ind = indent(prevlnum) - shiftwidth()
|
||||
endif
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
" shiftwidth=0 uses the value of tabstop, same as shiftwidth=4 here
|
||||
set shiftwidth=0 tabstop=4
|
||||
let g:vim_vue_plugin_config = {'foldexpr': 1}
|
||||
let g:test_flatten = 1
|
||||
|
||||
function! Check()
|
||||
let levels = [1, 2, 3, 2, 3, 4, 3, 3, 2, 1]
|
||||
for lnum in range(1, len(levels))
|
||||
call ExpectFoldlevel(lnum, levels[lnum - 1])
|
||||
endfor
|
||||
endfunction
|
||||
@@ -0,0 +1,24 @@
|
||||
<template>
|
||||
<div
|
||||
class="a"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
>
|
||||
<p :class="{ a: b }">x</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return { a: 1 }
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
p {
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user