@@ -71,14 +71,13 @@ let s:one_line_scope_regex = '\%(\%(\<else\>\|\<\%(if\|for\|while\)\>\s*(.*)\)\|
71
71
" Regex that defines blocks.
72
72
let s: block_regex = ' \%([{([]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s: line_term
73
73
74
+ let s: operator_first = ' ^\s*\%([-*/+.:?]\|||\|&&\)'
75
+
74
76
let s: var_stmt = ' ^\s*\%(const\|let\|var\)'
75
77
76
78
let s: comma_first = ' ^\s*,'
77
79
let s: comma_last = ' ,\s*$'
78
80
79
- let s: ternary = ' ^\s\+[?|:]'
80
- let s: ternary_q = ' ^\s\+?'
81
-
82
81
let s: case_indent = s: sw ()
83
82
let s: case_indent_after = s: sw ()
84
83
let s: m = matchlist (&cinoptions , ' :\(.\)' )
@@ -378,13 +377,38 @@ function GetJavascriptIndent()
378
377
return indent (prevline) + s: case_indent_after
379
378
endif
380
379
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
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
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
388
412
389
413
" If we are in a multi-line comment, cindent does the right thing.
390
414
if s: IsInMultilineComment (v: lnum , 1 ) && ! s: IsLineComment (v: lnum , 1 )
0 commit comments