-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_duplicate_line_selector.py
28 lines (21 loc) · 1.18 KB
/
plugin_duplicate_line_selector.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
import sublime, sublime_plugin, re
class DuplicateLineSelectorCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
if region.empty():
line = self.view.line(region)
is_css = self.view.match_selector( self.view.sel()[0].b, 'source.css' )
if is_css:
line_num, column = self.view.rowcol(line.begin())
line_contents = '\n' + self.view.substr(line)
selector = re.sub(r'(.*?)\s*(\{)\s*.*(\s*\}\s*)', r'\1 \2 \3', line_contents)
self.view.insert(edit, line.end(), selector)
pt = self.view.text_point(line_num + 1, len(selector) - 6)
self.view.sel().clear()
self.view.sel().add(sublime.Region(pt))
self.view.show(pt)
test = self.view.extract_scope(pt)
self.view.insert(edit, 0, test[0])
else :
line_contents = self.view.substr(line) + '\n'
self.view.insert(edit, line.begin(), line_contents)