tidy up autoindent

use voidElements and double quotes.
This commit is contained in:
Adam Jimenez 2014-10-29 09:54:16 +00:00
commit b3d0c62a8d

View file

@ -140,22 +140,22 @@ var XmlBehaviour = function () {
return;
return {
text: '>' + '</' + element + '>',
text: ">" + "</" + element + ">",
selection: [1, 1]
};
}
});
this.add('autoindent', 'insertion', function (state, action, editor, session, text) {
this.add("autoindent", "insertion", function (state, action, editor, session, text) {
if (text == "\n") {
var cursor = editor.getCursorPosition();
var line = session.getLine(cursor.row);
var iterator = new TokenIterator(session, cursor.row, cursor.column);
var token = iterator.getCurrentToken();
if (token && token.type.indexOf('tag-close') !== -1) {
if (token && token.type.indexOf("tag-close") !== -1) {
//get tag name
while (token && token.type.indexOf('tag-name') === -1) {
while (token && token.type.indexOf("tag-name") === -1) {
token = iterator.stepBackward();
}
@ -167,25 +167,23 @@ var XmlBehaviour = function () {
//don't indent after closing tag
token = iterator.stepBackward();
if (token && token.type.indexOf('end-tag') !== -1) {
if (!token || token.type.indexOf("end-tag") !== -1) {
return;
}
var single_tags = ['!doctype','area','base','br','hr','input','img','link','meta'];
if (single_tags.indexOf(tag) === -1) {
if (this.voidElements && !this.voidElements[tag]) {
var nextToken = session.getTokenAt(cursor.row, cursor.column+1);
var next_indent = this.$getIndent(line);
var indent = next_indent + session.getTabString();
if (nextToken && nextToken.value === '</') {
if (nextToken && nextToken.value === "</") {
return {
text: '\n' + indent + '\n' + next_indent,
text: "\n" + indent + "\n" + next_indent,
selection: [1, indent.length, 1, indent.length]
};
} else {
return {
text: '\n' + indent
text: "\n" + indent
};
}
}