Skip to content
Snippets Groups Projects
Commit 5b5976a6 authored by Devin Abbott's avatar Devin Abbott Committed by Marijn Haverbeke
Browse files

[jsx mode] Improve indention of js blocks

Issue #3745
parent 5b4f2241
No related branches found
No related tags found
No related merge requests found
......@@ -53,7 +53,22 @@
if (stream.peek() == "{") {
xmlMode.skipAttribute(cx.state)
state.context = new Context(CodeMirror.startState(jsMode, flatXMLIndent(cx.state)),
var indent = flatXMLIndent(cx.state), xmlContext = cx.state.context
// If JS starts on same line as tag
if (xmlContext && stream.string.slice(0, stream.pos).match(/>\s*$/)) {
while (xmlContext.prev && !xmlContext.startOfLine)
xmlContext = xmlContext.prev
// If tag starts the line, use XML indentation level
if (xmlContext.startOfLine) indent -= config.indentUnit
// Else use JS indentation level
else if (cx.prev.state.lexical) indent = cx.prev.state.lexical.indented
// Else if inside of tag
} else if (cx.depth == 1) {
indent += config.indentUnit
}
state.context = new Context(CodeMirror.startState(jsMode, indent),
jsMode, 0, state.context)
return null
}
......
......@@ -57,8 +57,8 @@
MT("indent_js",
"([bracket&tag <][tag foo][bracket&tag >]",
" [bracket&tag <][tag bar] [attribute baz]={[keyword function]() {",
" [keyword return] [number 10]",
" }}[bracket&tag />]",
" [keyword return] [number 10]",
" }}[bracket&tag />]",
" [bracket&tag </][tag foo][bracket&tag >])")
MT("spread",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment