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

@ -3,7 +3,7 @@
* *
* Copyright (c) 2010, Ajax.org B.V. * Copyright (c) 2010, Ajax.org B.V.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
@ -14,7 +14,7 @@
* * Neither the name of Ajax.org B.V. nor the * * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -140,59 +140,57 @@ var XmlBehaviour = function () {
return; return;
return { return {
text: '>' + '</' + element + '>', text: ">" + "</" + element + ">",
selection: [1, 1] 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") { if (text == "\n") {
var cursor = editor.getCursorPosition(); var cursor = editor.getCursorPosition();
var line = session.getLine(cursor.row); var line = session.getLine(cursor.row);
var iterator = new TokenIterator(session, cursor.row, cursor.column); var iterator = new TokenIterator(session, cursor.row, cursor.column);
var token = iterator.getCurrentToken(); var token = iterator.getCurrentToken();
if (token && token.type.indexOf('tag-close') !== -1) { if (token && token.type.indexOf("tag-close") !== -1) {
//get tag name //get tag name
while (token && token.type.indexOf('tag-name') === -1) { while (token && token.type.indexOf("tag-name") === -1) {
token = iterator.stepBackward(); token = iterator.stepBackward();
} }
if (!token) { if (!token) {
return; return;
} }
var tag = token.value; var tag = token.value;
//don't indent after closing tag //don't indent after closing tag
token = iterator.stepBackward(); token = iterator.stepBackward();
if (token && token.type.indexOf('end-tag') !== -1) { if (!token || token.type.indexOf("end-tag") !== -1) {
return; 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 nextToken = session.getTokenAt(cursor.row, cursor.column+1);
var next_indent = this.$getIndent(line); var next_indent = this.$getIndent(line);
var indent = next_indent + session.getTabString(); var indent = next_indent + session.getTabString();
if (nextToken && nextToken.value === '</') { if (nextToken && nextToken.value === "</") {
return { return {
text: '\n' + indent + '\n' + next_indent, text: "\n" + indent + "\n" + next_indent,
selection: [1, indent.length, 1, indent.length] selection: [1, indent.length, 1, indent.length]
}; };
} else { } else {
return { return {
text: '\n' + indent text: "\n" + indent
}; };
} }
} }
} }
} }
}); });
}; };
oop.inherits(XmlBehaviour, Behaviour); oop.inherits(XmlBehaviour, Behaviour);