Skip to content

Commit e9f6a4d

Browse files
committed
Merge pull request #389 from bounceme/patch-15
spanning multiple lines detection
2 parents 48263c8 + a607a7d commit e9f6a4d

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

indent/javascript.vim

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,21 @@ function s:GetMSL(lnum, in_one_line_scope)
153153
" Otherwise, terminate search as we have found our MSL already.
154154
let line = getline(lnum)
155155
let col = match(line, s:msl_regex) + 1
156+
let line2 = getline(msl)
157+
let col2 = matchend(line2, ')')
156158
if (col > 0 && !s:IsInStringOrComment(lnum, col)) || s:IsInString(lnum, strlen(line))
157159
let msl = lnum
160+
161+
" if there are more closing brackets, continue from the line which has the matching opening bracket
162+
elseif col2 > 0 && !s:IsInStringOrComment(msl, col2) && s:LineHasOpeningBrackets(msl)[0] == '2'
163+
call cursor(msl, 1)
164+
if searchpair('(', '', ')', 'bW', s:skip_expr) > 0
165+
let lnum = line('.')
166+
let msl = lnum
167+
endif
168+
158169
else
170+
159171
" Don't use lines that are part of a one line scope as msl unless the
160172
" flag in_one_line_scope is set to 1
161173
"
@@ -166,7 +178,7 @@ function s:GetMSL(lnum, in_one_line_scope)
166178
if msl_one_line == 0
167179
break
168180
endif
169-
endif
181+
end
170182
let lnum = s:PrevNonBlankNonString(lnum - 1)
171183
endwhile
172184
return msl
@@ -404,7 +416,7 @@ function GetJavascriptIndent()
404416
return indent(prevline) + s:sw()
405417
end
406418
" If previous line starts with an operator...
407-
elseif s:Match(prevline, s:operator_first) && !s:Match(prevline, s:comma_last)
419+
elseif s:Match(prevline, s:operator_first) && !s:Match(prevline, s:comma_last) && !s:Match(prevline, '};\=' . s:line_term)
408420
let counts = s:LineHasOpeningBrackets(prevline)
409421
if counts[0] == '2' && counts[1] == '1'
410422
call cursor(prevline, 1)
@@ -488,7 +500,14 @@ function GetJavascriptIndent()
488500
else
489501
call cursor(v:lnum, vcol)
490502
end
491-
elseif line =~ ')' || line =~ s:comma_last
503+
elseif line =~ '.\+};\=' . s:line_term
504+
call cursor(lnum, 1)
505+
" Search for the opening tag
506+
let mnum = searchpair('{', '', '}', 'bW', s:skip_expr)
507+
if mnum > 0
508+
return indent(s:GetMSL(mnum, 0))
509+
end
510+
elseif line =~ '.\+);\=' || line =~ s:comma_last
492511
let counts = s:LineHasOpeningBrackets(lnum)
493512
if counts[0] == '2'
494513
call cursor(lnum, 1)
@@ -497,7 +516,7 @@ function GetJavascriptIndent()
497516
if mnum > 0
498517
return indent(s:GetMSL(mnum, 0))
499518
end
500-
elseif line !~ s:var_stmt
519+
elseif line !~ s:var_stmt
501520
return indent(prevline)
502521
end
503522
end

0 commit comments

Comments
 (0)