Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CodeMirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moritz Aurel Pascal Schubotz
CodeMirror
Commits
c96aae3d
Commit
c96aae3d
authored
8 years ago
by
Axel Lewenhaupt
Committed by
Marijn Haverbeke
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[soy mode] Fix indentation and restore previous local states
parent
2f43bccc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mode/soy/soy.js
+34
-13
34 additions, 13 deletions
mode/soy/soy.js
mode/soy/test.js
+12
-0
12 additions, 0 deletions
mode/soy/test.js
with
46 additions
and
13 deletions
mode/soy/soy.js
+
34
−
13
View file @
c96aae3d
...
...
@@ -31,6 +31,12 @@
}
function
tokenUntil
(
stream
,
state
,
untilRegExp
)
{
if
(
stream
.
sol
())
{
for
(
var
indent
=
0
;
indent
<
state
.
indent
;
indent
++
)
{
if
(
!
stream
.
eat
(
/
\s
/
))
break
;
}
if
(
indent
)
return
null
;
}
var
oldString
=
stream
.
string
;
var
match
=
untilRegExp
.
exec
(
oldString
.
substr
(
stream
.
pos
));
if
(
match
)
{
...
...
@@ -39,7 +45,8 @@
stream
.
string
=
oldString
.
substr
(
0
,
stream
.
pos
+
match
.
index
);
}
var
result
=
stream
.
hideFirstChars
(
state
.
indent
,
function
()
{
return
state
.
localMode
.
token
(
stream
,
state
.
localState
);
var
localState
=
last
(
state
.
localStates
);
return
localState
.
mode
.
token
(
stream
,
localState
.
state
);
});
stream
.
string
=
oldString
;
return
result
;
...
...
@@ -83,8 +90,10 @@
variables
:
null
,
scopes
:
null
,
indent
:
0
,
localMode
:
modes
.
html
,
localState
:
CodeMirror
.
startState
(
modes
.
html
)
localStates
:
[{
mode
:
modes
.
html
,
state
:
CodeMirror
.
startState
(
modes
.
html
)
}]
};
},
...
...
@@ -98,8 +107,12 @@
variables
:
state
.
variables
,
scopes
:
state
.
scopes
,
indent
:
state
.
indent
,
// Indentation of the following line.
localMode
:
state
.
localMode
,
localState
:
CodeMirror
.
copyState
(
state
.
localMode
,
state
.
localState
)
localStates
:
state
.
localStates
.
map
(
function
(
localState
)
{
return
{
mode
:
localState
.
mode
,
state
:
CodeMirror
.
copyState
(
localState
.
mode
,
localState
.
state
)
};
})
};
},
...
...
@@ -187,8 +200,13 @@
var
kind
=
match
[
1
];
state
.
kind
.
push
(
kind
);
state
.
kindTag
.
push
(
state
.
tag
);
state
.
localMode
=
modes
[
kind
]
||
modes
.
html
;
state
.
localState
=
CodeMirror
.
startState
(
state
.
localMode
);
var
mode
=
modes
[
kind
]
||
modes
.
html
;
var
localState
=
last
(
state
.
localStates
);
state
.
indent
+=
localState
.
mode
.
indent
(
localState
.
state
,
""
);
state
.
localStates
.
push
({
mode
:
mode
,
state
:
CodeMirror
.
startState
(
mode
)
});
}
return
"
attribute
"
;
}
else
if
(
stream
.
match
(
/^"/
))
{
...
...
@@ -233,14 +251,15 @@
return
"
keyword
"
;
}
else
if
(
match
=
stream
.
match
(
/^
\{([\/
@
\\]?[\w
?
]
*
)
/
))
{
if
(
match
[
1
]
!=
"
/switch
"
)
state
.
indent
+=
(
/^
(\/
|
(
else|elseif|ifempty|case|default
)
$
)
/
.
test
(
match
[
1
])
&&
state
.
tag
!=
"
switch
"
?
1
:
2
)
*
config
.
indentUnit
;
state
.
indent
+=
(
/^
(\/
|
(
else|elseif|ifempty|case|
fallbackmsg|
default
)
$
)
/
.
test
(
match
[
1
])
&&
state
.
tag
!=
"
switch
"
?
1
:
2
)
*
config
.
indentUnit
;
state
.
tag
=
match
[
1
];
if
(
state
.
tag
==
"
/
"
+
last
(
state
.
kindTag
))
{
// We found the tag that opened the current kind="".
state
.
kind
.
pop
();
state
.
kindTag
.
pop
();
state
.
localMode
=
modes
[
last
(
state
.
kind
)]
||
modes
.
html
;
state
.
localState
=
CodeMirror
.
startState
(
state
.
localMode
);
state
.
localStates
.
pop
();
var
localState
=
last
(
state
.
localStates
);
state
.
indent
-=
localState
.
mode
.
indent
(
localState
.
state
,
""
);
}
state
.
soyState
.
push
(
"
tag
"
);
if
(
state
.
tag
==
"
template
"
||
state
.
tag
==
"
deltemplate
"
)
{
...
...
@@ -277,14 +296,16 @@
if
(
state
.
tag
!=
"
switch
"
&&
/^
\{(
case|default
)\b
/
.
test
(
textAfter
))
indent
-=
config
.
indentUnit
;
if
(
/^
\{\/
switch
\b
/
.
test
(
textAfter
))
indent
-=
config
.
indentUnit
;
}
if
(
indent
&&
state
.
localMode
.
indent
)
indent
+=
state
.
localMode
.
indent
(
state
.
localState
,
textAfter
);
var
localState
=
last
(
state
.
localStates
);
if
(
indent
&&
localState
.
mode
.
indent
)
{
indent
+=
localState
.
mode
.
indent
(
localState
.
state
,
textAfter
);
}
return
indent
;
},
innerMode
:
function
(
state
)
{
if
(
state
.
soyState
.
length
&&
last
(
state
.
soyState
)
!=
"
literal
"
)
return
null
;
else
return
{
state
:
state
.
localState
,
mode
:
state
.
localMode
}
;
else
return
last
(
state
.
localState
s
)
;
},
electricInput
:
/^
\s
*
\{(\/
|
\/
template|
\/
deltemplate|
\/
switch|fallbackmsg|elseif|else|case|default|ifempty|
\/
literal
\})
$/
,
...
...
This diff is collapsed.
Click to expand it.
mode/soy/test.js
+
12
−
0
View file @
c96aae3d
...
...
@@ -80,4 +80,16 @@
'
nothing
'
,
'
[keyword {/foreach}]
'
,
''
);
MT
(
'
nested-kind-test
'
,
'
[keyword {template] [def .foo] [attribute kind]=[string "html"][keyword }]
'
,
'
[tag&bracket <][tag div][tag&bracket >]
'
,
'
[keyword {call] [variable .bar][keyword }]
'
,
'
[keyword {param] [attribute kind]=[string "js"][keyword }]
'
,
'
[keyword var] [def bar] [operator =] [number 5];
'
,
'
[keyword {/param}]
'
,
'
[keyword {/call}]
'
,
'
[tag&bracket </][tag div][tag&bracket >]
'
,
'
[keyword {/template}]
'
,
''
);
})();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment