forked from ggordan/GutterColor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.py
33 lines (26 loc) · 880 Bytes
/
file.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
from sublime import Region
from threading import Thread
from .line import Line
class File():
""" A File corresponds to one sublime.View """
def __init__(self, view, action = 'initialize'):
self.view = view # sublime.View
self.id = self.view.buffer_id()
self.action = action
self.scan()
def scan(self):
"""Scan the file for colours and add/remove regions appropriately"""
# Return a list of all the line regions in the current file
if self.action == 'update':
regions = [self.view.line(s) for s in self.view.sel()]
else:
regions = self.view.lines(Region(0, self.view.size()))
for region in regions:
line = Line(self.view, region, self.id)
if line.has_color():
line.add_region()
else:
try:
self.view.erase_regions("gutter_color_%s" % region.a)
except:
pass