Permalink
Browse files

If something is selected, replace the selection with the closing tag

  • Loading branch information...
1 parent 38b32ad commit 020a2bd1f421d2c9aa6f9ebaf9119eecd712f87a @titoBouzout committed Mar 4, 2012
Showing with 11 additions and 2 deletions.
  1. +11 −2 tag_close_tag_on_slash.py
View
@@ -21,10 +21,19 @@ def run(self, edit):
if '<' == previousCharacter:
tag = self.close_tag(view.substr(sublime.Region(0, cursorPosition)))
- view.insert(edit, cursorPosition, tag);
+ if region.empty():
+ replace = False
+ view.insert(edit, cursorPosition, tag);
+ else:
+ replace = True
+ view.replace(edit, sublime.Region(region.begin(), region.end()), '');
+ view.insert(edit, cursorPosition, tag);
if tag != '/':
closed_some_tag = True
- new_selections_insert.append(sublime.Region(region.end()+len(tag), region.end()+len(tag)))
+ if replace:
+ new_selections_insert.append(sublime.Region(region.begin()+len(tag), region.begin()+len(tag)))
+ else:
+ new_selections_insert.append(sublime.Region(region.end()+len(tag), region.end()+len(tag)))
else:
new_selections.append(sublime.Region(region.end()+len(tag), region.end()+len(tag)))
else:

0 comments on commit 020a2bd

Please sign in to comment.