@@ -205,14 +205,6 @@ function GetJavascriptIndent()
205205
206206 let l: line = substitute (l: line ,' ^\s*\%(\/\*.\{-}\*\/\s*\)*' ,' ' ,' ' )
207207
208- if l: line = ~# ' ^' . s: expr_case
209- let cpo_switch = &cpo
210- set cpo += %
211- let ind = cindent (v: lnum )
212- let &cpo = cpo_switch
213- return ind
214- endif
215-
216208 " the containing paren, bracket, curly. Many hacks for performance
217209 call cursor (v: lnum ,1 )
218210 let idx = strlen (l: line ) ? stridx (' ])}' ,l: line [0 ]) : -1
@@ -243,20 +235,27 @@ function GetJavascriptIndent()
243235 return indent (line (' .' ))
244236 endif
245237
238+ call call (' cursor' ,b: js_cache [1 :])
246239 let s: W = s: sw ()
247240 let pline = s: Trimline (l: lnum )
248- call call (' cursor' ,b: js_cache [1 :])
249241 let bchar = getline (' .' )[col (' .' )-1 ] == ' {'
250- let switch_offset = ! num || ! bchar || ! (search (' )\_s*\%#' ,' bW' ) &&
251- \ s: GetPair (' (' , ' )' , ' bW' , s: skip_expr , 100 ) > 0 && search (' \C\<switch\_s*\%#' ,' bW' )) ? 0 :
252- \ &cino !~ ' :' || ! has (' float' ) ? s: W :
253- \ float2nr (str2float (matchstr (&cino ,' .*:\zs[-0-9.]*' )) * (&cino = ~# ' .*:[^,]*s' ? s: W : 1 ))
242+ let switch_offset = 0
243+ let in_switch = 0
244+ if num && bchar && search (' )\_s*\%#' ,' bW' ) &&
245+ \ s: GetPair (' (' , ' )' , ' bW' , s: skip_expr , 100 ) > 0 && search (' \C\<switch\_s*\%#' ,' bW' )
246+ let in_switch = 1
247+ let switch_offset = &cino !~ ' :' || ! has (' float' ) ? s: W :
248+ \ float2nr (str2float (matchstr (&cino ,' .*:\zs[-0-9.]*' )) * (&cino = ~# ' .*:[^,]*s' ? s: W : 1 ))
249+ if l: line = ~# ' ^' . s: expr_case
250+ return indent (num) + switch_offset
251+ endif
252+ endif
254253
255254 " most significant, find the indent amount
256- let isOp = l: line = ~# s: opfirst || pline ! ~# s: expr_case . ' $' && pline = ~# s: continuation
255+ let isOp = l: line = ~# s: opfirst || (in_switch && pline = ~# s: expr_case . ' $' ? 0 : pline = ~# s: continuation)
257256 let bL = s: iscontOne (l: lnum ,num,isOp)
258257 let bL -= (bL && l: line [0 ] == ' {' ) * s: W
259- if isOp && (! num || bchar && call (' cursor' ,b: js_cache [1 :])+ 1 && s: IsBlock ())
258+ if isOp && (! num || in_switch || bchar && call (' cursor' ,b: js_cache [1 :])+ 1 && s: IsBlock ())
260259 return (num ? indent (num) : - s: W ) + (s: W * 2 ) + switch_offset + bL
261260 elseif num
262261 return indent (num) + s: W + switch_offset + bL
0 commit comments