-
Notifications
You must be signed in to change notification settings - Fork 4
/
helper_commands.py
62 lines (49 loc) · 2.08 KB
/
helper_commands.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#coding: utf8
#################################### IMPORTS ###################################
# Sublime Libs
import sublime
import sublime_plugin
from .package_resources import norm_path_to_sublime_style
################################ HELPER COMMANDS ###############################
class GotoLineNumber(sublime_plugin.TextCommand):
def run(self, edit, line):
view = self.view
view.sel().clear()
line_region = sublime.Region(view.text_point(line-1, 0))
view.sel().add(
line_region
)
view.show(line_region, True)
class SelectRegions(sublime_plugin.TextCommand):
def run(self, edit, regions, show_surrounds=True):
view = self.view
view.sel().clear()
for r in regions:
view.sel().add(sublime.Region(*r))
if view.sel():
view.show(view.line(view.sel()[0]).begin(), show_surrounds)
view.show_at_center(view.sel()[0])
class OpenFileEnhanced(sublime_plugin.WindowCommand):
def run(self, file, line=None, regions=None, **kw):
fn = norm_path_to_sublime_style(file)
window = self.window
kw['file'] = fn
window.run_command("open_file", kw)
# The pseudo zip file View.file_name() will be this
full_name = (fn.replace("${packages}/",
sublime.packages_path() + '/'))
open_file_view = self.window.find_open_file(full_name)
def do():
if open_file_view.is_loading():
sublime.set_timeout(do, 10)
else:
window.focus_view(open_file_view)
window.focus_group(window.get_view_index(open_file_view)[0])
if line is not None:
open_file_view.run_command (
'goto_line_number', dict(line=line))
elif regions is not None:
open_file_view.run_command (
'select_regions', dict( regions=regions,
show_surrounds=True ))
do()