Skip to content

Commit

Permalink
Trim whitespace for block comments
Browse files Browse the repository at this point in the history
  • Loading branch information
borela committed Mar 8, 2018
1 parent 5d3a9d2 commit 2a4ae78
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions plugin/ToggleJsxComment.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import sublime_plugin

def comment_block(view, edit, region):
region = trim_whitespace(view, region)
begin = get_non_whitespace_pos(view, region)
end = max(begin, region.end())
empty_region = False
Expand Down Expand Up @@ -262,6 +263,24 @@ def is_jsx_close_brace(view, offset):
scopes = view.scope_name(offset)
return all(x in scopes for x in close_brace_scopes)

def trim_whitespace(view, region):
begin = region.begin()
end = region.end()

# Trim from the left.
char = view.substr(begin)
while char.isspace():
begin += 1
char = view.substr(begin)

# Trim from the right.
char = view.substr(end)
while char.isspace():
end -= 1
char = view.substr(end)

return sublime.Region(begin, end + 1)

def uncomment_lines(view, edit, region):
begin = region.begin()
end = region.end()
Expand Down

0 comments on commit 2a4ae78

Please sign in to comment.