@@ -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
@@ -377,13 +377,32 @@ function GetJavascriptIndent()
377
377
if (getline (prevline) = ~ s: expr_case )
378
378
return indent (prevline) + s: case_indent_after
379
379
endif
380
-
381
- if (line = ~ s: ternary )
382
- if (getline (prevline) = ~ s: ternary_q )
380
+
381
+ " if the line starts with an operator
382
+ if (s: Match (v: lnum , s: operator_first ))
383
+ if (s: Match (prevline, s: operator_first ))
384
+ " and so does previous line, don't indent
383
385
return indent (prevline)
384
- else
386
+ end
387
+ let counts = s: LineHasOpeningBrackets (prevline)
388
+ if counts[0 ] == ' 2'
389
+ call cursor (prevline, 1 )
390
+ " Search for the opening tag
391
+ let mnum = searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr )
392
+ if mnum > 0 && s: Match (mnum, s: operator_first )
393
+ return indent (mnum)
394
+ end
395
+ elseif counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
396
+ " otherwise, indent 1 level
385
397
return indent (prevline) + s: sw ()
386
- endif
398
+ end
399
+ " If previous line starts with a operator...
400
+ elseif s: Match (prevline, s: operator_first ) || s: Match (v: lnum , ' ^\s*[])}]' )
401
+ let countscur = s: LineHasOpeningBrackets (v: lnum )
402
+ let counts = s: LineHasOpeningBrackets (prevline)
403
+ if (counts[0 ] != ' 1' && counts[1 ] != ' 1' || counts[2 ] != ' 1' ) && countscur[0 ] != ' 2'
404
+ return indent (prevline) - s: sw ()
405
+ end
387
406
endif
388
407
389
408
" If we are in a multi-line comment, cindent does the right thing.
0 commit comments