From 5697625a7d2f24e2f9e8f6aeadf069fbd0192b40 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Sun, 17 Feb 2013 16:26:10 +0000 Subject: [PATCH] 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. --- lib/ice-coder.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/ice-coder.js b/lib/ice-coder.js index 86dea4e..09a851c 100644 --- a/lib/ice-coder.js +++ b/lib/ice-coder.js @@ -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()+""); + if (tag=='div') { + startLine = cM.getCursor('start').line; + endLine = cM.getCursor().line; + cM.operation(function() { + cM.replaceSelection("
\n"+cM.getSelection()+"\n
"); + 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()+""); + } if (tag=='a') {cM.setCursor({line:cM.getCursor().line,ch:cM.getCursor('start').ch+9})} },