improve CSS and JS autoindent
This commit is contained in:
parent
09a09e8ac2
commit
0848743978
4 changed files with 35 additions and 1 deletions
|
|
@ -16,12 +16,23 @@ ace.mode.JavaScript.prototype.toggleCommentLines = function(doc, range, state) {
|
||||||
ace.mode.JavaScript.prototype.getNextLineIndent = function(line, state, tab) {
|
ace.mode.JavaScript.prototype.getNextLineIndent = function(line, state, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
||||||
|
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
|
||||||
|
var tokens = tokenizedLine.tokens;
|
||||||
|
var endState = tokenizedLine.state;
|
||||||
|
|
||||||
|
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
||||||
|
return indent;
|
||||||
|
}
|
||||||
|
|
||||||
if (state == "start") {
|
if (state == "start") {
|
||||||
var match = line.match(/^.*[\{\(\[]\s*$/);
|
var match = line.match(/^.*[\{\(\[]\s*$/);
|
||||||
if (match) {
|
if (match) {
|
||||||
indent += tab;
|
indent += tab;
|
||||||
}
|
}
|
||||||
} else if (state == "doc-comment") {
|
} else if (state == "doc-comment") {
|
||||||
|
if (endState == "start") {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
var match = line.match(/^\s*(\/?)\*/);
|
var match = line.match(/^\s*(\/?)\*/);
|
||||||
if (match) {
|
if (match) {
|
||||||
if (match[1]) {
|
if (match[1]) {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ MockRenderer.prototype.getContainerElement = function() {
|
||||||
return this.container;
|
return this.container;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MockRenderer.prototype.getMouseEventTarget = function() {
|
||||||
|
return this.container;
|
||||||
|
};
|
||||||
|
|
||||||
MockRenderer.prototype.setDocument = function(doc) {
|
MockRenderer.prototype.setDocument = function(doc) {
|
||||||
this.lines = doc.lines;
|
this.lines = doc.lines;
|
||||||
};
|
};
|
||||||
|
|
@ -54,6 +58,9 @@ MockRenderer.prototype.scrollToRow = function(row) {
|
||||||
this.layerConfig.lastVisibleRow = row + this.visibleRowCount;
|
this.layerConfig.lastVisibleRow = row + this.visibleRowCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MockRenderer.prototype.getScrollTopRow = function() {
|
||||||
|
return this.layerConfig.firstVisibleRow;
|
||||||
|
};
|
||||||
|
|
||||||
MockRenderer.prototype.draw = function() {
|
MockRenderer.prototype.draw = function() {
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -29,5 +29,6 @@ var CssTest = new TestCase("mode.CssTest", {
|
||||||
|
|
||||||
"test: no indent increase after { in a comment" : function() {
|
"test: no indent increase after { in a comment" : function() {
|
||||||
assertEquals(" ", this.mode.getNextLineIndent(" /*{", "start", " "));
|
assertEquals(" ", this.mode.getNextLineIndent(" /*{", "start", " "));
|
||||||
|
assertEquals(" ", this.mode.getNextLineIndent(" /*{ ", "start", " "));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -54,7 +54,13 @@ var JavaScriptTest = new TestCase("mode.JavaScriptTest", {
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: no auto indent after opening brace in multi line comment" : function() {
|
"test: no auto indent after opening brace in multi line comment" : function() {
|
||||||
assertEquals("", this.mode.getNextLineIndent("/*if () {", " "));
|
assertEquals("", this.mode.getNextLineIndent("/*if () {", "start", " "));
|
||||||
|
assertEquals(" ", this.mode.getNextLineIndent(" abcd", "comment", " "));
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: no auto indent after opening brace in single line comment" : function() {
|
||||||
|
assertEquals("", this.mode.getNextLineIndent("//if () {", "start", " "));
|
||||||
|
assertEquals(" ", this.mode.getNextLineIndent(" //if () {", "start", " "));
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: no auto indent should add to existing indent" : function() {
|
"test: no auto indent should add to existing indent" : function() {
|
||||||
|
|
@ -68,5 +74,14 @@ var JavaScriptTest = new TestCase("mode.JavaScriptTest", {
|
||||||
assertEquals(" * ", this.mode.getNextLineIndent(" *", "doc-comment", " "));
|
assertEquals(" * ", this.mode.getNextLineIndent(" *", "doc-comment", " "));
|
||||||
assertEquals(" * ", this.mode.getNextLineIndent(" *", "doc-comment", " "));
|
assertEquals(" * ", this.mode.getNextLineIndent(" *", "doc-comment", " "));
|
||||||
assertEquals(" ", this.mode.getNextLineIndent(" abc", "doc-comment", " "));
|
assertEquals(" ", this.mode.getNextLineIndent(" abc", "doc-comment", " "));
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: no indent after doc comments" : function() {
|
||||||
|
assertEquals("", this.mode.getNextLineIndent(" */", "doc-comment", " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "test: outdent if first non WS character in line is a closing brace" : function() {
|
||||||
|
// assertEquals("", this.mode.getNextLineIndent(")", "start", " "));
|
||||||
|
// assertEquals(" ", this.mode.getNextLineIndent(" )", "start", " "));
|
||||||
|
// }
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue