Autoindent doesn't always occur
Currently autoindent only kicks in as so: ``` <div>|</div> ``` This allows it to also work with: ``` <div>| </div> ```
This commit is contained in:
parent
c97858705d
commit
631695a0e4
1 changed files with 26 additions and 8 deletions
|
|
@ -150,15 +150,33 @@ var XmlBehaviour = function () {
|
||||||
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 rightChars = line.substring(cursor.column, cursor.column + 2);
|
var iterator = new TokenIterator(session, cursor.row, cursor.column);
|
||||||
if (rightChars == '</') {
|
var token = iterator.getCurrentToken();
|
||||||
var next_indent = this.$getIndent(line);
|
|
||||||
var indent = next_indent + session.getTabString();
|
if (token && token.type.indexOf('tag-close') !== -1) {
|
||||||
|
//get tag name
|
||||||
|
while (token && token.type.indexOf('tag-name') === -1) {
|
||||||
|
token = iterator.stepBackward();
|
||||||
|
}
|
||||||
|
|
||||||
|
var single_tags = ['!doctype','area','base','br','hr','input','img','link','meta'];
|
||||||
|
|
||||||
return {
|
if (token && token.value && single_tags.indexOf(token.value) === -1) {
|
||||||
text: '\n' + indent + '\n' + next_indent,
|
var nextToken = session.getTokenAt(cursor.row, cursor.column+1);
|
||||||
selection: [1, indent.length, 1, indent.length]
|
var next_indent = this.$getIndent(line);
|
||||||
};
|
var indent = next_indent + session.getTabString();
|
||||||
|
|
||||||
|
if (nextToken && nextToken.value === '</') {
|
||||||
|
return {
|
||||||
|
text: '\n' + indent + '\n' + next_indent,
|
||||||
|
selection: [1, indent.length, 1, indent.length]
|
||||||
|
};
|
||||||
|
}else{
|
||||||
|
return {
|
||||||
|
text: '\n' + indent
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue