Skip to content

Commit 01021fe

Browse files
committed
Update javascript.vim
1 parent ee5e20a commit 01021fe

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

indent/javascript.vim

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let s:var_stmt = '^\s*(const\|let\|var)'
7676
let s:comma_first = '^\s*,'
7777
let s:comma_last = ',\s*$'
7878

79-
let s:operator_first = '^\s*\%([*+.:?]\|||\|&&\)'
79+
let s:operator_first = '^\s*\%([-*/+.:?]\|||\|&&\)'
8080

8181
let s:case_indent = s:sw()
8282
let s:case_indent_after = s:sw()
@@ -377,9 +377,8 @@ function GetJavascriptIndent()
377377
return indent(prevline) + s:case_indent_after
378378
endif
379379

380-
" If line starts with operator...
381-
if (line =~ s:operator_first)
382-
if (getline(prevline) =~ s:operator_first)
380+
if (s:Match(v:lnum, s:operator_first))
381+
if (s:Match(prevline, s:operator_first))
383382
" and so does previous line, don't indent
384383
return indent(prevline)
385384
end
@@ -388,20 +387,20 @@ function GetJavascriptIndent()
388387
call cursor(prevline, 1)
389388
" Search for the opening tag
390389
let mnum = searchpair('(', '', ')', 'bW', s:skip_expr)
391-
if mnum > 0
392-
if getline(mnum) =~ s:operator_first
393-
return indent(mnum)
394-
end
390+
if mnum > 0 && s:Match(mnum, s:operator_first)
391+
return indent(mnum)
395392
end
396393
else
397394
" otherwise, indent 1 level
398-
return indent(prevline) + &sw
395+
return indent(prevline) + s:sw()
396+
end
397+
" If previous line starts with a operator...
398+
elseif (s:Match(prevline, s:operator_first))
399+
let counts = s:LineHasOpeningBrackets(prevline)
400+
if counts[0] != '1' && counts[1] != '1' && counts[2] != '1'
401+
" dedent 1 level
402+
return indent(prevline) - s:sw()
399403
end
400-
end
401-
" If previous line starts with a dot...
402-
if (getline(prevline) =~ s:operator_first)
403-
" dedent 1 level
404-
return indent(prevline) - &sw
405404
endif
406405

407406
" If we are in a multi-line comment, cindent does the right thing.

0 commit comments

Comments
 (0)