Surround With Tag, need to be in new lines (both open and close tag)

I use CTRL-W to select this code:

     <p>
          Sample Text
     </p>


Then, CTRL-ALT-T to surround with a DIV tag.

So, I type "div" and then ENTER and I get this:

     <div><p>
          Sample Text
     </p></div>



But I want this formatiing instead:

     <div>
      <p>
          Sample Text
     </p>
     </div>



I do not want to separate the DIV tag to new lines manually.

Is there a QUICK shortcut to achieve this while entering the TAG?

P.S. I know I can do CTRL-ALT-L afterwards to reformat code, but I wonder if there is an immediate way to achieve the above (I assume common) case.

Thank you.
4 comments
Comment actions Permalink

Please make sure to check 'Reformat according to style' option in Settings | Editor | Live Templates | html/xml, T2.
See attached screenshot



Attachment(s):
T2.png
0
Comment actions Permalink

Thank you Elena,

your suggestion works, still not all the times.

For example:

 
<div class="row">
  <div class="col" ui-sref-active="active" ng-repeat="pCat in pCategories">
    <h3>
      <a ui-sref="tab.p-index2({pCatId: pCat.id[0]})">{{pCat.title}}</a>
    </h3>
    <p>{{pCat.description}}</p>
  </div>
</div>
   
1. If you select (with CTRL-W) the entire 2nd DIV and then CTRL-ALT-T to wrap it with another DIV, then this works PERFECT (the new <DIV> and </DIV> get their own new lines).
 
2. BUT, if you select (with CTRL-W) the entire <h3> and then CTRL-ALT-T to wrap it with another DIV, then this does NOT add new lines for the <DIV></DIV>.
 
Same happens with the <a> tag.
 
I understand that this happens due to the automatic reformatting.
Could you have a way to manually decide if I want new lines for the wrapping element? For example, if i press CTRL-ENTER when selecting the Live Template (instead of just ENTER) and CTRL-click respectively.
Thanks.

0
Comment actions Permalink
could you have a way to manually decide if I want new lines for the wrapping element?

no. it's either formatted according to HTML formatting rules, or not formatted at all. In the latter case you are free to add all new lines manually:)

0

Please sign in to leave a comment.