forked from netpro2k/SublimeBlockCursor
-
Notifications
You must be signed in to change notification settings - Fork 3
/
SublimeBlockCursor.py
38 lines (31 loc) · 1.32 KB
/
SublimeBlockCursor.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
import sublime_plugin
class BlockCursorEverywhere(sublime_plugin.EventListener):
def view_is_widget(self, view):
settings = view.settings()
return bool(settings.get('is_widget'))
def show_block_cursor(self, view):
validRegions = []
for s in view.sel():
if s.a != s.b:
continue
validRegions.append(sublime.Region(s.a, s.a + 1))
if validRegions.__len__:
view.add_regions('BlockCursorListener', validRegions, 'block_cursor')
else:
view.erase_regions('BlockCursorListener')
def on_selection_modified(self, view):
if view.settings().get('is_widget') or not(view.settings().get('command_mode')):
view.erase_regions('BlockCursorListener')
return
self.show_block_cursor(view)
def on_deactivated(self, view):
view.erase_regions('BlockCursorListener')
view.settings().clear_on_change('command_mode')
self.current_view = None
def on_activated(self, view):
self.on_selection_modified(view)
view.settings().add_on_change('command_mode', self.on_command_mode_change)
self.current_view = view
def on_command_mode_change(self):
self.on_selection_modified(self.current_view)