forked from koroshiya/Sublime-Renpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenpyTextTag.py
32 lines (24 loc) · 975 Bytes
/
RenpyTextTag.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
import sublime, sublime_plugin
# Extends TextCommand so that run() receives a View to modify.
class RenpyTextTagCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
tag = args['tag']
view = self.view
positions = []
selections = view.sel()
for selection in selections:
view.insert(edit, selection.end(), "{/"+tag+"}")
view.insert(edit, selection.begin(), "{"+tag+"}")
lenSel = selection.size()
(row, col) = self.view.rowcol(selection.begin())
col += 3
r1 = sublime.Region(view.text_point(row, col))
if lenSel == 0:
positions.append(r1)
else:
r2 = sublime.Region(view.text_point(row, col+lenSel))
positions.append(r2.cover(r1))
selections.clear()
for position in positions:
self.view.sel().add(position)
self.view.show(position)