-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactComments.py
38 lines (27 loc) · 1.03 KB
/
reactComments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sublime, sublime_plugin
class ReactCommentsCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
someUncommented = False
lines = self.view.lines(region)
for line in lines:
if not isCommentLine(self, line):
someUncommented = True
if someUncommented:
for line in reversed(lines):
if not isCommentLine(self, line):
addComments(self, edit, line)
else:
removeComments(self, edit, self.view.line(region))
def isCommentLine(self, line):
if "comment.block.js" in self.view.scope_name(line.begin()):
return True
lineStr = self.view.substr(line)
return "{/*" in lineStr or "*/}" in lineStr
def addComments(self, edit, line):
self.view.insert(edit, line.end(), " */}")
self.view.insert(edit, line.begin(), "{/* ")
def removeComments(self, edit, region):
regionStr = self.view.substr(region)
uncommented = regionStr.replace("{/* ", "").replace(" */}", "")
self.view.replace(edit, region, uncommented)