Skip to content

Better handling of multiline ternary indents. #329 #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ let s:comma_last = ',\s*$'

let s:ternary = '^\s\+[?|:]'
let s:ternary_q = '^\s\+?'
let s:ternary_s = '^\s\+:'

let s:case_indent = s:sw()
let s:case_indent_after = s:sw()
Expand Down Expand Up @@ -378,13 +379,18 @@ function GetJavascriptIndent()
return indent(prevline) + s:case_indent_after
endif

" If in a multi line ternary, indent the next line
if (line =~ s:ternary)
if (getline(prevline) =~ s:ternary_q)
return indent(prevline)
else
return indent(prevline) + s:sw()
endif
endif
" If the previous line was the last part of a multiline ternary, dedent
if (getline(prevline) =~ s:ternary_s)
return indent(prevline) - &sw
endif

" If we are in a multi-line comment, cindent does the right thing.
if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1)
Expand Down