Autoindent for XML and HTML modes

This commit is contained in:
Fabian Jakobs 2010-05-18 17:59:19 +02:00
commit e12ff69a4e
4 changed files with 36 additions and 1 deletions

View file

@ -17,8 +17,9 @@ ace.inherits(ace.mode.Html, ace.mode.Text);
};
this.getNextLineIndent = function(state, line, tab) {
var self = this;
return this.$delegate("getNextLineIndent", arguments, function() {
return "";
return self.$getIndent(line);
});
};

View file

@ -4,3 +4,11 @@ ace.mode.Xml = function() {
this.$tokenizer = new ace.Tokenizer(new ace.mode.XmlHighlightRules().getRules());
};
ace.inherits(ace.mode.Xml, ace.mode.Text);
(function() {
this.getNextLineIndent = function(state, line, tab) {
return this.$getIndent(line);
};
}).call(ace.mode.Xml.prototype);

View file

@ -0,0 +1,20 @@
var HtmlTest = new TestCase("mode.HtmlTest", {
setUp : function() {
this.mode = new ace.mode.Html();
},
"test: toggle comment lines should not do anything" : function() {
var doc = new ace.Document([" abc", "cde", "fg"]);
var range = new ace.Range(0, 3, 1, 1);
var comment = this.mode.toggleCommentLines("start", doc, range);
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
},
"test: next line indent should be the same as the current line indent" : function() {
assertEquals(" ", this.mode.getNextLineIndent("start", " abc"));
assertEquals("", this.mode.getNextLineIndent("start", "abc"));
assertEquals("\t", this.mode.getNextLineIndent("start", "\tabc"));
}
});

View file

@ -19,5 +19,11 @@ var XmlTest = new TestCase("mode.XmlTest", {
var range = new ace.Range(0, 3, 1, 1);
var comment = this.mode.toggleCommentLines("start", doc, range);
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
},
"test: next line indent should be the same as the current line indent" : function() {
assertEquals(" ", this.mode.getNextLineIndent("start", " abc"));
assertEquals("", this.mode.getNextLineIndent("start", "abc"));
assertEquals("\t", this.mode.getNextLineIndent("start", "\tabc"));
}
});