@@ -76,8 +76,7 @@ let s:var_stmt = '^\s*(const\|let\|var)'
76
76
let s: comma_first = ' ^\s*,'
77
77
let s: comma_last = ' ,\s*$'
78
78
79
- let s: ternary = ' ^\s\+[?|:]'
80
- let s: ternary_q = ' ^\s\+?'
79
+ let s: operator_first = ' ^\s*\%([-*/+.:?]\|||\|&&\)'
81
80
82
81
let s: case_indent = s: sw ()
83
82
let s: case_indent_after = s: sw ()
@@ -146,7 +145,8 @@ function s:GetMSL(lnum, in_one_line_scope)
146
145
" Otherwise, terminate search as we have found our MSL already.
147
146
let line = getline (lnum)
148
147
let col = match (line , s: msl_regex ) + 1
149
- if (col > 0 && ! s: IsInStringOrComment (lnum, col )) || s: IsInString (lnum, strlen (line ))
148
+ let colprev = s: Match (msl, s: operator_first )
149
+ if ((col > 0 && ! s: IsInStringOrComment (lnum, col )) || s: IsInString (lnum, strlen (line )) || colprev)
150
150
let msl = lnum
151
151
else
152
152
" Don't use lines that are part of a one line scope as msl unless the
@@ -378,12 +378,30 @@ function GetJavascriptIndent()
378
378
return indent (prevline) + s: case_indent_after
379
379
endif
380
380
381
- if (line = ~ s: ternary )
382
- if (getline (prevline) = ~ s: ternary_q )
381
+ if (s: Match (v: lnum , s: operator_first ))
382
+ if (s: Match (prevline, s: operator_first ))
383
+ " and so does previous line, don't indent
383
384
return indent (prevline)
384
- else
385
+ end
386
+ let counts = s: LineHasOpeningBrackets (prevline)
387
+ if counts[0 ] == ' 2'
388
+ call cursor (prevline, 1 )
389
+ " Search for the opening tag
390
+ let mnum = searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr )
391
+ if mnum > 0 && s: Match (mnum, s: operator_first )
392
+ return indent (mnum)
393
+ end
394
+ elseif counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
395
+ " otherwise, indent 1 level
385
396
return indent (prevline) + s: sw ()
386
- endif
397
+ end
398
+ " If previous line starts with a operator...
399
+ elseif (s: Match (prevline, s: operator_first ))
400
+ let counts = s: LineHasOpeningBrackets (prevline)
401
+ if counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
402
+ " dedent 1 level
403
+ return indent (prevline) - s: sw ()
404
+ end
387
405
endif
388
406
389
407
" If we are in a multi-line comment, cindent does the right thing.
0 commit comments