vendor/assets/javascripts/codemirror/modes/python.js in codemirror-rails-0.3.2 vs vendor/assets/javascripts/codemirror/modes/python.js in codemirror-rails-2.2
- old
+ new
@@ -181,10 +181,14 @@
function indent(stream, state, type) {
type = type || 'py';
var indentUnit = 0;
if (type === 'py') {
+ if (state.scopes[0].type !== 'py') {
+ state.scopes[0].offset = stream.indentation();
+ return;
+ }
for (var i = 0; i < state.scopes.length; ++i) {
if (state.scopes[i].type === 'py') {
indentUnit = state.scopes[i].offset + conf.indentUnit;
break;
}
@@ -196,11 +200,12 @@
offset: indentUnit,
type: type
});
}
- function dedent(stream, state) {
+ function dedent(stream, state, type) {
+ type = type || 'py';
if (state.scopes.length == 1) return;
if (state.scopes[0].type === 'py') {
var _indent = stream.indentation();
var _indent_index = -1;
for (var i = 0; i < state.scopes.length; ++i) {
@@ -215,12 +220,20 @@
while (state.scopes[0].offset !== _indent) {
state.scopes.shift();
}
return false
} else {
- state.scopes.shift();
- return false;
+ if (type === 'py') {
+ state.scopes[0].offset = stream.indentation();
+ return false;
+ } else {
+ if (state.scopes[0].type != type) {
+ return true;
+ }
+ state.scopes.shift();
+ return false;
+ }
}
}
function tokenLexer(stream, state) {
indentInfo = null;
@@ -268,10 +281,10 @@
return ERRORCLASS;
}
}
delimiter_index = '])}'.indexOf(current);
if (delimiter_index !== -1) {
- if (dedent(stream, state)) {
+ if (dedent(stream, state, current)) {
return ERRORCLASS;
}
}
if (state.dedent > 0 && stream.eol() && state.scopes[0].type == 'py') {
if (state.scopes.length > 1) state.scopes.shift();