From b3d0c62a8d6c348c9108cd8025af00c80b5897be Mon Sep 17 00:00:00 2001 From: Adam Jimenez Date: Wed, 29 Oct 2014 09:54:16 +0000 Subject: [PATCH] tidy up autoindent use voidElements and double quotes. --- lib/ace/mode/behaviour/xml.js | 36 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/ace/mode/behaviour/xml.js b/lib/ace/mode/behaviour/xml.js index 0f9d3a66..708653ab 100644 --- a/lib/ace/mode/behaviour/xml.js +++ b/lib/ace/mode/behaviour/xml.js @@ -3,7 +3,7 @@ * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * 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 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -140,59 +140,57 @@ var XmlBehaviour = function () { return; return { - text: '>' + '', + text: ">" + "", 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(); } - + if (!token) { return; } - + var tag = token.value; - + //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 === '