Skip to content

Commit

Permalink
Fixed erb block styles and toggling when there is no selection
Browse files Browse the repository at this point in the history
  • Loading branch information
eddorre committed Aug 17, 2011
1 parent f3ff589 commit 0523b79
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions erb_block.py
@@ -1,7 +1,7 @@
import sublime, sublime_plugin
import re

ERB_BLOCKS = ['<%= %>', '<% %>', '<%- -%>', '<% -%>']
ERB_BLOCKS = ['<%= %>', '<%= -%>', '<%# %>', '<% %>', '<% -%>']

class ErbCommand(sublime_plugin.TextCommand):
def run(self, edit):
Expand All @@ -24,8 +24,8 @@ def in_erb_block(self):
region = self.view.sel()[0]

if region.begin() != 0:
selection = self.view.substr(sublime.Region(region.begin() - 4, region.end() + 4))
match = re.match('<%(=?|-?)\s{2}(-?)%>', selection)
selection = self.view.substr(sublime.Region(region.begin() - 4, region.end() + 5))
match = re.match('<%(=?|-?|#?)\s{2}(-?)%>', selection)
if match:
return True
else:
Expand All @@ -35,7 +35,7 @@ def in_erb_block(self):

def last_erb_block(self):
region = self.view.sel()[0]
return self.view.substr(sublime.Region(region.begin() - 4, region.end() + 4))
return self.view.substr(sublime.Region(region.begin() - 4, region.end() + 5))

def get_next_erb_block(self):
current_index = ERB_BLOCKS.index(self.last_erb_block())
Expand All @@ -56,12 +56,8 @@ def replace_erb_block(self, edit):
self.view.replace(edit, self.view.word(region.a), next_erb_block)
self.view.sel().clear()

if ERB_BLOCKS.index(next_erb_block) == 1:
if ERB_BLOCKS.index(next_erb_block) == 3:
self.view.sel().add(sublime.Region(region.begin() - 1))
elif ERB_BLOCKS.index(next_erb_block) == len(ERB_BLOCKS) - 1:
self.view.sel().add(sublime.Region(region.begin() - 1))
elif ERB_BLOCKS.index(next_erb_block) == 2:
self.view.sel().add(sublime.Region(region.begin() + 1))
elif ERB_BLOCKS.index(next_erb_block) == 0:
self.view.sel().add(sublime.Region(region.begin() + 1))
else:
Expand Down

0 comments on commit 0523b79

Please sign in to comment.