@@ -89,11 +89,6 @@ endfunction
8989
9090" Auxiliary Functions {{{2
9191
92- " strip line of comment
93- function s: StripLine (c )
94- return a: c !~# s: expr_case ? substitute (a: c , ' \%(:\@<!\/\/.*\)$' , ' ' ,' ' ) : a: c
95- endfunction
96-
9792" Find line above 'lnum' that isn't empty, in a comment, or in a string.
9893function s: PrevCodeLine (lnum)
9994 let l: lnum = prevnonblank (a: lnum )
@@ -176,16 +171,17 @@ function GetJavascriptIndent()
176171 return indent (num)
177172 endif
178173
179- let pline = s: StripLine (getline (l: lnum ))
180174 call cursor (b: js_cache [1 ],b: js_cache [2 ])
175+
176+ let swcase = getline (l: lnum ) = ~# s: expr_case
177+ let pline = swcase ? getline (l: lnum ) : substitute (getline (l: lnum ), ' \%(:\@<!\/\/.*\)$' , ' ' ,' ' )
181178 let inb = num == 0 || num < l: lnum && ((l: line !~ s: line_pre . ' ,' && pline !~ ' ,' . s: line_term ) || s: IsBlock ())
182- let switch_offset = num == 0 || s: OneScope (num, s: StripLine ( strpart (getline (num),0 ,b: js_cache [2 ] - 1 ) ),1 ) !=# ' switch' ? 0 :
179+ let switch_offset = num == 0 || s: OneScope (num, strpart (getline (num),0 ,b: js_cache [2 ] - 1 ),1 ) !=# ' switch' ? 0 :
183180 \ &cino !~ ' :' || ! has (' float' ) ? s: sw () :
184181 \ float2nr (str2float (matchstr (&cino ,' .*:\zs[-0-9.]*' )) * (&cino = ~# ' .*:[^,]*s' ? s: sw () : 1 ))
185182
186183 " most significant, find the indent amount
187- if (inb && (l: line = ~# g: javascript_opfirst ||
188- \ (pline = ~# g: javascript_continuation && pline !~# s: expr_case ))) ||
184+ if (inb && (l: line = ~# g: javascript_opfirst || (! swcase && pline = ~# g: javascript_continuation ))) ||
189185 \ (num < l: lnum && s: OneScope (l: lnum ,pline,0 ) = ~# ' \%(for\|each\|if\|let\|no\sb\|w\%(hile\|ith\)\)' &&
190186 \ l: line !~ s: line_pre . ' {' )
191187 return (num > 0 ? indent (num) : - s: sw ()) + (s: sw () * 2 ) + switch_offset
0 commit comments