forked from facelessuser/BracketHighlighter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bh_swapping.py
executable file
·59 lines (46 loc) · 1.69 KB
/
bh_swapping.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
import sublime
import sublime_plugin
import BracketHighlighter.bh_wrapping as bh_wrapping
class SwapBrackets(bh_wrapping.WrapBrackets):
def wrap(self, wrap_entry):
if wrap_entry < 0:
return
self._style = ["inline"]
self.brackets = self._brackets[wrap_entry]
self.wrap_brackets(0)
class SwapBracketsCommand(sublime_plugin.WindowCommand):
def finalize(self, callback):
if self.view is not None:
if not self.view.settings().get("BracketHighlighterBusy", False):
callback()
else:
sublime.set_timeout(lambda: self.finalize(callback), 100)
def swap_brackets(self, value):
if value < 0:
return
self.brackets = self.wrap._brackets[value]
self.window.run_command(
"bh_async_key" if self.async else "bh_key",
{
"plugin": {
"type": ["__all__"],
"command": "bh_modules.swapbrackets"
}
}
)
self.view = self.window.active_view()
if self.async:
sublime.set_timeout(lambda: self.finalize(lambda: self.wrap.wrap(value)), 100)
else:
self.finalize(self.wrap.wrap(value))
def run(self, async=False):
self.async = async
view = self.window.active_view()
if view is None:
return
self.wrap = SwapBrackets(view, "bh_swapping.sublime-settings", "swapping")
if len(self.wrap._menu):
self.window.show_quick_panel(
self.wrap._menu,
self.swap_brackets
)