Line breaks and indents for DIV tag wrapping

If the user is wrapping the selected with a DIV tag, add line breaks
were needed and indentation as appropriate.
This commit is contained in:
Matt Pass
2013-02-17 16:26:10 +00:00
parent a5894dfae8
commit 5697625a7d

View File

@@ -350,13 +350,26 @@ var ICEcoder = {
// Wrap our selected text/cursor with tags
tagWrapper: function(tag) {
var cM, tagStart, tagEnd;
var cM, tagStart, tagEnd, startLine, endLine;
cM = ICEcoder.getcMInstance();
tagStart = tag;
tagEnd = tag;
if (tag=='a') {tagStart='a href=""';}
cM.replaceSelection("<"+tagStart+">"+cM.getSelection()+"</"+tagEnd+">");
if (tag=='div') {
startLine = cM.getCursor('start').line;
endLine = cM.getCursor().line;
cM.operation(function() {
cM.replaceSelection("<div>\n"+cM.getSelection()+"\n</div>");
for (var i=startLine+1; i<=endLine+1; i++) {
cM.indentLine(i);
}
cM.indentLine(endLine+2,'prev');
cM.indentLine(endLine+2,'subtract');
});
} else {
if (tag=='a') {tagStart='a href=""';}
cM.replaceSelection("<"+tagStart+">"+cM.getSelection()+"</"+tagEnd+">");
}
if (tag=='a') {cM.setCursor({line:cM.getCursor().line,ch:cM.getCursor('start').ch+9})}
},