我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用sublime.PhantomSet()。
def on_modified_async(self): output_id = self.view.settings().get('minihtml_preview_output_view_id') output_view = next(view for view in self.view.window().views() if view.id() == output_id) content = self.view.substr(sublime.Region(0, self.view.size())) buffer_id = output_view.buffer_id() if buffer_id in self.phantom_sets: ps = self.phantom_sets[buffer_id] else: ps = sublime.PhantomSet(output_view, 'minihtml_preview_phantom') self.phantom_sets[buffer_id] = ps p = sublime.Phantom(sublime.Region(0), content, sublime.LAYOUT_BLOCK, _on_navigate) ps.update([p])
def update_diagnostics_phantoms(view: sublime.View, diagnostics: 'List[Diagnostic]'): global phantom_sets_by_buffer buffer_id = view.buffer_id() if not show_diagnostics_phantoms or view.is_dirty(): phantoms = None else: phantoms = list( create_phantom(view, diagnostic) for diagnostic in diagnostics) if phantoms: phantom_set = phantom_sets_by_buffer.get(buffer_id) if not phantom_set: phantom_set = sublime.PhantomSet(view, "lsp_diagnostics") phantom_sets_by_buffer[buffer_id] = phantom_set phantom_set.update(phantoms) else: phantom_sets_by_buffer.pop(buffer_id, None)
def show_html(md_view, preview): global windows_phantom_set html = markdown2html(get_view_content(md_view), os.path.dirname(md_view.file_name()), md_view.settings().get('color_scheme')) phantom_set = windows_phantom_set.setdefault(preview.window().id(), sublime.PhantomSet(preview, 'markdown_live_preview')) phantom_set.update([sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK, lambda href: sublime.run_command('open_url', {'url': href}))]) # lambda href: sublime.run_command('open_url', {'url': href}) # get the "ratio" of the markdown view's position. # 0 < y < 1 y = md_view.text_to_layout(md_view.sel()[0].begin())[1] / md_view.layout_extent()[1] # set the vector (position) for the preview vector = [0, y * preview.layout_extent()[1]] # remove half of the viewport_extent.y to center it on the screen (verticaly) vector[1] -= preview.viewport_extent()[1] / 2 # make sure the minimum is 0 vector[1] = 0 if vector[1] < 0 else vector[1] # the hide the first line vector[1] += preview.line_height() preview.set_viewport_position(vector, animate=False)
def show_phantoms(self, view): """Show phantoms for compilation errors. Args: view (sublime.View): current view """ view.erase_phantoms(PopupErrorVis._TAG) if view.buffer_id() not in self.phantom_sets: phantom_set = sublime.PhantomSet(view, PopupErrorVis._TAG) self.phantom_sets[view.buffer_id()] = phantom_set else: phantom_set = self.phantom_sets[view.buffer_id()] phantoms = [] current_error_dict = self.err_regions[view.buffer_id()] for err in current_error_dict: errors_dict = current_error_dict[err] errors_html = PhantomErrorVis._as_html(errors_dict) pt = view.text_point(err - 1, 1) phantoms.append(sublime.Phantom( sublime.Region(pt, view.line(pt).b), errors_html, sublime.LAYOUT_BELOW, on_navigate=self._on_phantom_navigate)) phantom_set.update(phantoms)
def update_diagnostics_phantoms(view: sublime.View, diagnostics: 'List[Diagnostic]'): global phantom_sets_by_buffer buffer_id = view.buffer_id() if not settings.show_diagnostics_phantoms or view.is_dirty(): phantoms = None else: phantoms = list( create_phantom(view, diagnostic) for diagnostic in diagnostics) if phantoms: phantom_set = phantom_sets_by_buffer.get(buffer_id) if not phantom_set: phantom_set = sublime.PhantomSet(view, "lsp_diagnostics") phantom_sets_by_buffer[buffer_id] = phantom_set phantom_set.update(phantoms) else: phantom_sets_by_buffer.pop(buffer_id, None)
def __init__(self, *args): # self.view = view super(ImagePreviewCommand, self).__init__(*args) # self.phantom_set = sublime.PhantomSet(self.view) self.displayed = False
def __init__(self, *args, **kwargs): super(RelativeLineNumbersCommand, self).__init__(*args, **kwargs) self._visible = False self._phantoms = sublime.PhantomSet(self.view, PACKAGE)
def _draw_phantoms(view, errs, mode, phantom_sets, show_phantoms): buffer_id = view.buffer_id() if buffer_id not in phantom_sets: phantom_set = sublime.PhantomSet(view, PHANTOMS_MARKER) phantom_sets[buffer_id] = phantom_set else: phantom_set = phantom_sets[buffer_id] formatter = formatters.TB_MODES[mode] phantoms = build_phantoms(view, errs, formatter) if show_phantoms else [] phantom_set.update(phantoms)
def initWindow(self, window): if not window.id() in self.data: self.data[window.id()] = {} xref_data = self.data[window.id()]; window.destroy_output_panel("chromium_x_refs"); xref_data['panel'] = window.create_output_panel("chromium_x_refs", False); xref_data['phantom_set'] = sublime.PhantomSet(xref_data['panel'], "phantoms");
def get_phantom_set(self, view): global PHANTOM_SETS_BY_BUFFER buffer_id = view.buffer_id() if buffer_id not in PHANTOM_SETS_BY_BUFFER: phantom_set = sublime.PhantomSet(view, 'linter-inline-errors') PHANTOM_SETS_BY_BUFFER[buffer_id] = phantom_set else: phantom_set = PHANTOM_SETS_BY_BUFFER[buffer_id] return phantom_set
def get_summary_phantom_set(self, view): global SUMMARY_PHANTOM_SETS_BY_BUFFER buffer_id = view.buffer_id() if buffer_id not in SUMMARY_PHANTOM_SETS_BY_BUFFER: phantom_set = sublime.PhantomSet(view, 'linter-inline-errors-summary') SUMMARY_PHANTOM_SETS_BY_BUFFER[buffer_id] = phantom_set else: phantom_set = SUMMARY_PHANTOM_SETS_BY_BUFFER[buffer_id] return phantom_set
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))