Skip to content

Commit 85eeb98

Browse files
committed
Adds leading ternary operator indentation support
1 parent 790e095 commit 85eeb98

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

indent/javascript.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ let s:var_stmt = '^\s*var'
6464
let s:comma_first = '^\s*,'
6565
let s:comma_last = ',\s*$'
6666

67+
let s:ternary = '^\s\+[?|:]'
68+
6769
" 2. Auxiliary Functions {{{1
6870
" ======================
6971

@@ -339,6 +341,14 @@ function GetJavascriptIndent()
339341
return indent(prevline) - &sw
340342
endif
341343

344+
if (line =~ s:ternary)
345+
if (getline(prevline) =~ s:ternary)
346+
return indent(prevline)
347+
else
348+
return indent(prevline) + &sw
349+
endif
350+
endif
351+
342352
" If we are in a multi-line comment, cindent does the right thing.
343353
if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1)
344354
return cindent(v:lnum)

0 commit comments

Comments
 (0)