Fix template extents not being updated

This commit is contained in:
Kovid Goyal 2015-01-08 08:57:19 +05:30
parent ad0ffcaadd
commit bcaabdfe08

View File

@ -231,17 +231,25 @@ class Template(list):
def __new__(self, tab_stops): def __new__(self, tab_stops):
self = list.__new__(self) self = list.__new__(self)
self.left_most_position = self.right_most_position = None self.left_most_ts = self.right_most_ts = None
self.extend(tab_stops) self.extend(tab_stops)
for c in self: for c in self:
if self.left_most_position is None or self.left_most_position > c.left: if self.left_most_ts is None or self.left_most_ts.left > c.left:
self.left_most_position = c.left self.left_most_ts = c
if self.right_most_position is None or self.right_most_position <= c.right: if self.right_most_ts is None or self.right_most_ts.right <= c.right:
self.right_most_position = c.right self.right_most_ts = c
self.has_tab_stops = self.left_most_position is not None self.has_tab_stops = bool(self)
self.active_tab_stop = None self.active_tab_stop = None
return self return self
@property
def left_most_position(self):
return getattr(self.left_most_ts, 'left', None)
@property
def right_most_position(self):
return getattr(self.right_most_ts, 'right', None)
def contains_cursor(self, cursor): def contains_cursor(self, cursor):
if not self.has_tab_stops: if not self.has_tab_stops:
return False return False