Skip to content

Commit 14198ab

Browse files
authored
copy indent if in same scope only
1 parent 0b6aad4 commit 14198ab

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: indent/javascript.vim

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ function GetJavascriptIndent()
164164

165165
" the containing paren, bracket, curly. Memoize, last lineNr either has the
166166
" same scope or starts a new one, unless if it closed a scope.
167-
let [s:looksyn,s:free] = [v:lnum - 1,1]
167+
let [s:looksyn,s:free,pcounts] = [v:lnum - 1,1,[0]]
168168
call cursor(v:lnum,1)
169169
if b:js_cache[0] < v:lnum && b:js_cache[0] >= l:lnum &&
170-
\ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum) > 0)
170+
\ (b:js_cache[0] > l:lnum || map(pcounts,'s:Balanced(l:lnum)')[0] > 0)
171171
let num = b:js_cache[1]
172172
elseif syns != '' && l:line[0] =~ '\s'
173173
let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] :
@@ -197,7 +197,7 @@ function GetJavascriptIndent()
197197
\ l:line !~ s:line_pre . '{'
198198
return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset
199199
elseif num > 0
200-
return isOp && num < l:lnum ? indent(l:lnum) : indent(num) + s:sw() + switch_offset
200+
return isOp && num < l:lnum && pcounts[0] > 0 ? indent(l:lnum) : indent(num) + s:sw() + switch_offset
201201
endif
202202

203203
endfunction

0 commit comments

Comments
 (0)