@@ -71,14 +71,13 @@ let s:one_line_scope_regex = '\%(\%(\<else\>\|\<\%(if\|for\|while\)\>\s*(.*)\)\|
7171" Regex that defines blocks.
7272let s: block_regex = ' \%([{([]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s: line_term
7373
74+ let s: operator_first = ' ^\s*\%([-*/+.:?]\|||\|&&\)'
75+
7476let s: var_stmt = ' ^\s*\%(const\|let\|var\)'
7577
7678let s: comma_first = ' ^\s*,'
7779let s: comma_last = ' ,\s*$'
7880
79- let s: ternary = ' ^\s\+[?|:]'
80- let s: ternary_q = ' ^\s\+?'
81-
8281let s: case_indent = s: sw ()
8382let s: case_indent_after = s: sw ()
8483let s: m = matchlist (&cinoptions , ' :\(.\)' )
@@ -378,13 +377,38 @@ function GetJavascriptIndent()
378377 return indent (prevline) + s: case_indent_after
379378 endif
380379
381- if (line = ~ s: ternary )
382- if (getline (prevline) = ~ s: ternary_q )
380+ " If line starts with an operator...
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
383384 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
385396 return indent (prevline) + s: sw ()
386- endif
387- endif
397+ end
398+ " If previous line starts with an operator...
399+ elseif s: Match (prevline, s: operator_first ) && ! s: Match (prevline, s: comma_last )
400+ let counts = s: LineHasOpeningBrackets (prevline)
401+ if counts[0 ] == ' 2' && counts[1 ] == ' 1'
402+ call cursor (prevline, 1 )
403+ " Search for the opening tag
404+ let mnum = searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr )
405+ if mnum > 0 && ! s: Match (mnum, s: operator_first )
406+ return indent (mnum) + s: sw ()
407+ end
408+ elseif counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
409+ return indent (prevline) - s: sw ()
410+ end
411+ end
388412
389413 " If we are in a multi-line comment, cindent does the right thing.
390414 if s: IsInMultilineComment (v: lnum , 1 ) && ! s: IsLineComment (v: lnum , 1 )
0 commit comments