我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用sublime.LAYOUT_INLINE。
def run(self): view = self.window.new_file() view.set_name("{} – Changelog".format(settings.PACKAGE_NAME)) view.settings().set("gutter", False) view.settings().set("line_numbers", False) view.settings().set("caret_extra_top", 0) view.settings().set("caret_extra_bottom", 0) view.settings().set("caret_extra_width", 0) html = str(sublime.load_resource( "Packages/{}/.sublime/CHANGELOG.html".format(settings.PACKAGE_NAME) )) view.add_phantom( "afi_changelog", sublime.Region(0), html, sublime.LAYOUT_INLINE, on_navigate=self.on_navigate ) view.set_read_only(True) view.set_scratch(True)
def anim_loading(self): if self.loading > 0: self.loading_anim = (self.loading_anim + 1) % 8 char = '????????'[self.loading_anim] html = '''<body id="loader"> <style> .spinner { display: inline; color: var(--redish); } </style> Loading <span class="spinner">%s</span></body>''' % char self.loader = sublime.Phantom(sublime.Region(len(self.server['remote_path'])), html, sublime.LAYOUT_INLINE) self.phantom_set.update([self.loader, self.phantom] if self.phantom else [self.loader]) sublime.set_timeout(self.anim_loading, 100) else: print('removing anim') self.phantom_set.update([self.phantom] if self.phantom else [])
def _render(self): settings = self.view.settings() enabled = settings.get(OPT_ENABLED, True) self._clear() if not enabled: return phantoms = [] current_line = self.view.rowcol(self.view.sel()[0].begin())[0] current_line_char = settings.get(OPT_CURRENT_CHAR, "0") lines = self.view.lines(self.view.visible_region()) for line in lines: line_number = self.view.rowcol(line.a)[0] value = self._value( line_number, current_line, current_line_char) phantoms.append( sublime.Phantom( line, self._tpl(value, line_number == current_line), sublime.LAYOUT_INLINE)) self._phantoms.update(phantoms) self.view.set_viewport_position( (0, self.view.viewport_position()[1]), False) sublime.set_timeout(self._clear, settings.get(OPT_CLEAR_TIMEOUT, 1000))
def run(self, edit): (viewport_x, viewport_y) = self.view.viewport_position() path = gitPath(self.view.window()) current_path = self.view.file_name() if current_path is not None and current_path.startswith(path): remaining_path = current_path[len(path):] command = ("cd '{0}';git blame --show-email '{1}'").format(path, remaining_path) output, _ = run_bash_for_output(command) lines = output.split('\n') line_count = 0 regions = self.view.lines(sublime.Region(0, self.view.size())) phantoms = [] last_hash = None for line in lines: matches = re.search(r'^([0-9a-z]+).*?\(<(.*?)>', line) # print(line, ' ', matches) if matches is not None and line_count < len(regions): hash = matches.group(1) email = matches.group(2) at_position = email.find("@") if at_position != -1: email = email[:at_position] if len(email) > 10: email = email[:10] email = "{:*>10}".format(email) if hash == last_hash: email = "." * 10 html = "<b>{0}</b>".format(email) else: html = "<a href='{0}'>{1}</a>".format(hash, email) last_hash = hash r = regions[line_count] phantom = Phantom(sublime.Region(r.begin(), r.begin()), html, sublime.LAYOUT_INLINE, lambda link: self.click(link) ) phantoms.append(phantom) line_count = line_count + 1 global phantomSet phantomSet = PhantomSet(self.view, 'git_blame') phantomSet.update(phantoms) global viewIdToPhantomSet viewIdToPhantomSet[self.view.id()] = phantomSet self.view.set_viewport_position((0, viewport_y))
def annotate(self, point): self.window = self.view.window() self.roots = self.view.window().folders() self.syntax = self.view.settings().get('syntax') self.lang = self.get_lang(self.syntax) v = self.view line_range = v.line(point) if v.line(line_range.b) == self.current_line: return line_content = v.substr(line_range).strip() matched = self.is_valid_line(line_content) if matched: destination_str = matched.group(1) file_path = HyperClickPathResolver(v, destination_str, self.roots, self.lang, self.settings ) region = sublime.Region(line_range.b, line_range.b) self.current_line = v.line(line_range.b) v.erase_phantoms('hyper_click') resolved_path = file_path.resolve() # print('resolved to => ', resolved_path) if resolved_path: content = """ <span class="label label-success"><a href="{link}">{content}</a></span> """.format( link=resolved_path, content=self.settings.get('annotation_found_text', '?') ) v.add_phantom( 'hyper_click', region, self.html.format(css=self.css, content=content), sublime.LAYOUT_INLINE, self.on_navigate ) else: content = """ <span class="label label-error">{content}</span> """.format(content=self.settings.get('annotation_not_found_text', '?')) v.add_phantom( 'hyper_click', region, self.html.format(css=self.css, content=content), sublime.LAYOUT_INLINE, self.on_navigate ) else: v.erase_phantoms('hyper_click') # ---------------------------------------