def index_colors(self): """Index colors in file.""" colors = set() for m in util.COLOR_RE.finditer(self.source): if self.abort: break color, alpha = util.translate_color(m) if color is not None: colors.add(color) for m in self.webcolor_names.finditer(self.source): if self.abort: break colors.add(csscolors.name2hex(m.group(0))) if not self.abort: sublime.set_timeout( lambda view=self.view, colors=list(colors): self.update_index(view, colors), 0 )
def show_color_info(self, update=False): """Show the color under the cursor.""" color = None sels = self.view.sel() if (len(sels) == 1 and sels[0].size() == 0): point = sels[0].begin() visible = self.view.visible_region() start = point - 50 end = point + 50 alpha = None if start < visible.begin(): start = visible.begin() if end > visible.end(): end = visible.end() bfr = self.view.substr(sublime.Region(start, end)) ref = point - start for m in util.COLOR_RE.finditer(bfr): if ref >= m.start(0) and ref < m.end(0): color, alpha = util.translate_color(m) break if color is not None: if alpha is not None: color += "%02X" % int('%.0f' % (float(alpha) * 255.0)) html = [] html.append( self.format_info(color.lower(), alpha) ) if update: mdpopups.update_popup(self.view, ''.join(html), css=ADD_CSS) else: mdpopups.show_popup( self.view, ''.join(html), location=-1, max_width=600, on_navigate=self.on_navigate, flags=sublime.COOPERATE_WITH_AUTO_COMPLETE, css=ADD_CSS ) elif update: self.view.hide_popup()