def _update_line_colors(self, line_no, line_color_map):
# Note this function has been optimized quite a bit. Calls to the ST3
# API has been left out on purpose as they are slower than the
# alternative.
view_region_cache = self._sub_buffer.view_region_cache()
view_content_cache = self._sub_buffer.view_content_cache()
for idx, field in line_color_map.items():
length = field["field_length"]
color_scope = "terminalview.%s_%s" % (field["color"][0], field["color"][1])
# Get text point where color should start
line_start, _ = view_content_cache.get_line_start_and_end_points(line_no)
color_start = line_start + idx
# Make region that should be colored
buffer_region = sublime.Region(color_start, color_start + length)
region_key = "%i,%s" % (line_no, idx)
# Add the region
flags = sublime.DRAW_NO_OUTLINE | sublime.PERSISTENT
self.view.add_regions(region_key, [buffer_region], color_scope, flags=flags)
view_region_cache.add(line_no, region_key)
评论列表
文章目录