@@ -205,14 +205,6 @@ function GetJavascriptIndent()
205
205
206
206
let l: line = substitute (l: line ,' ^\s*\%(\/\*.\{-}\*\/\s*\)*' ,' ' ,' ' )
207
207
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
-
216
208
" the containing paren, bracket, curly. Many hacks for performance
217
209
call cursor (v: lnum ,1 )
218
210
let idx = strlen (l: line ) ? stridx (' ])}' ,l: line [0 ]) : -1
@@ -243,20 +235,27 @@ function GetJavascriptIndent()
243
235
return indent (line (' .' ))
244
236
endif
245
237
238
+ call call (' cursor' ,b: js_cache [1 :])
246
239
let s: W = s: sw ()
247
240
let pline = s: Trimline (l: lnum )
248
- call call (' cursor' ,b: js_cache [1 :])
249
241
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
254
253
255
254
" 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)
257
256
let bL = s: iscontOne (l: lnum ,num,isOp)
258
257
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 ())
260
259
return (num ? indent (num) : - s: W ) + (s: W * 2 ) + switch_offset + bL
261
260
elseif num
262
261
return indent (num) + s: W + switch_offset + bL
0 commit comments