Skip to content

Commit 7db788e

Browse files
committed
Make the htmlmixed mode keep a 'mode' string in its state
To help external code easily determine which mode a getTokenAt token is in
1 parent 42d06ec commit 7db788e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mode/htmlmixed/htmlmixed.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
99
if (/^script$/i.test(state.htmlState.context.tagName)) {
1010
state.token = javascript;
1111
state.localState = jsMode.startState(htmlMode.indent(state.htmlState, ""));
12+
state.mode = "javascript";
1213
}
1314
else if (/^style$/i.test(state.htmlState.context.tagName)) {
1415
state.token = css;
1516
state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
17+
state.mode = "css";
1618
}
1719
}
1820
return style;
@@ -27,6 +29,7 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
2729
if (stream.match(/^<\/\s*script\s*>/i, false)) {
2830
state.token = html;
2931
state.curState = null;
32+
state.mode = "html";
3033
return html(stream, state);
3134
}
3235
return maybeBackup(stream, /<\/\s*script\s*>/,
@@ -36,6 +39,7 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
3639
if (stream.match(/^<\/\s*style\s*>/i, false)) {
3740
state.token = html;
3841
state.localState = null;
42+
state.mode = "html";
3943
return html(stream, state);
4044
}
4145
return maybeBackup(stream, /<\/\s*style\s*>/,
@@ -45,13 +49,14 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
4549
return {
4650
startState: function() {
4751
var state = htmlMode.startState();
48-
return {token: html, localState: null, htmlState: state};
52+
return {token: html, localState: null, mode: "html", htmlState: state};
4953
},
5054

5155
copyState: function(state) {
5256
if (state.localState)
5357
var local = CodeMirror.copyState(state.token == css ? cssMode : jsMode, state.localState);
54-
return {token: state.token, localState: local, htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
58+
return {token: state.token, localState: local, mode: state.mode,
59+
htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
5560
},
5661

5762
token: function(stream, state) {

0 commit comments

Comments
 (0)