Skip to content

Commit 71479da

Browse files
committed
fixing multiline comment indent
1 parent db92bcb commit 71479da

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

indent/javascript.vim

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ function GetJavascriptIndent()
382382

383383

384384
if (line =~ s:dot_first)
385-
return indent(prevline) + s:sw()
385+
if (getline(prevline) !~ s:dot_first && getline(prevline) !~ '^\s*[)} ]*\s*$')
386+
return indent(prevline) + s:sw()
387+
endif
386388
endif
387389
" If the line is comma first, dedent 1 level
388390
if (getline(prevline) =~ s:comma_first)
@@ -392,6 +394,11 @@ function GetJavascriptIndent()
392394
return indent(prevline) + s:case_indent_after
393395
endif
394396

397+
" If we are in a multi-line comment, cindent does the right thing.
398+
if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1)
399+
return cindent(v:lnum)
400+
endif
401+
395402
" If line starts with an operator...
396403
if (s:Match(v:lnum, s:operator_first))
397404
if (s:Match(prevline, s:operator_first))
@@ -433,9 +440,9 @@ function GetJavascriptIndent()
433440
return indent(prevline) - s:sw()
434441
endif
435442

436-
" If we are in a multi-line comment, cindent does the right thing.
437-
if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1)
438-
return cindent(v:lnum)
443+
" If prev line was .then() type construction, shift comment line
444+
if line =~ '^\s*/[/*]' && getline(prevline) =~ s:dot_first
445+
return indent(prevline) - s:sw()
439446
endif
440447

441448
" Check for multiple var assignments
@@ -458,7 +465,7 @@ function GetJavascriptIndent()
458465
let lnum = s:PrevNonBlankNonString(v:lnum - 1)
459466

460467
" If the line is empty and inside a string, use the previous line.
461-
if line =~ '^\s*$' && lnum != prevline
468+
if (line =~ '^\s*[/*]' || line =~ '^\s*$') && lnum != prevline
462469
return indent(prevnonblank(v:lnum))
463470
endif
464471

0 commit comments

Comments
 (0)