Python sublime.LAYOUT_INLINE Examples

The following are 13 code examples of sublime.LAYOUT_INLINE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sublime , or try the search function .
Example #1
Source File: render.py    From sublime_debugger with MIT License 6 votes vote down vote up
def __init__(self, component: Union[span, div], view: sublime.View, region: sublime.Region, layout: int = sublime.LAYOUT_INLINE) -> None:
		super().__init__(component, view)
		self.cachedPhantom = None #type: Optional[sublime.Phantom]
		self.region = region
		self.layout = layout
		self.view = view

		self.set = sublime.PhantomSet(self.view)

		Phantom.id += 1

		# we use the region to track where we should place the new phantom so if text is inserted the phantom will be redrawn in the correct place
		self.region_id = 'phantom_{}'.format(Phantom.id)
		self.view.add_regions(self.region_id, [self.region], flags=sublime.DRAW_NO_FILL)
		self.update()
		_renderables_add.append(self) 
Example #2
Source File: preview.py    From sublime-text-plugin with MIT License 6 votes vote down vote up
def show(view, marker, as_phantom=False):
    "Displays Emmet abbreviation as a preview for given view"
    content = None
    buffer_id = view.buffer_id()

    try:
        content = format_snippet(marker.preview())
    except Exception as e:
        content = '<div class="error">%s</div>' % format_snippet(str(e))

    if content:
        if as_phantom:
            if buffer_id not in phantom_sets_by_buffer:
                phantom_set = sublime.PhantomSet(view, 'emmet')
                phantom_sets_by_buffer[buffer_id] = phantom_set
            else:
                phantom_set = phantom_sets_by_buffer[buffer_id]

            r = sublime.Region(marker.region.end(), marker.region.end())
            phantoms = [sublime.Phantom(r, phantom_content(content), sublime.LAYOUT_INLINE)]
            phantom_set.update(phantoms)
        elif not view.is_popup_visible() or previews_by_buffer.get(buffer_id, None) != marker.abbreviation:
            previews_by_buffer[buffer_id] = marker.abbreviation
            view.show_popup(popup_content(content), sublime.COOPERATE_WITH_AUTO_COMPLETE, marker.region.begin(), 400, 300) 
Example #3
Source File: color.py    From LSP with MIT License 6 votes vote down vote up
def handle_response(self, response: Optional[List[dict]]) -> None:
        color_infos = response if response else []
        phantoms = []
        for color_info in color_infos:
            color = color_info['color']
            red = color['red'] * 255
            green = color['green'] * 255
            blue = color['blue'] * 255
            alpha = color['alpha']

            content = """
            <style>html {{padding: 0}}</style>
            <div style='padding: 0.4em;
                        margin-top: 0.2em;
                        border: 1px solid color(var(--foreground) alpha(0.25));
                        background-color: rgba({}, {}, {}, {})'>
            </div>""".format(red, green, blue, alpha)

            range = Range.from_lsp(color_info['range'])
            region = range_to_region(range, self.view)

            phantoms.append(sublime.Phantom(region, content, sublime.LAYOUT_INLINE))

        self.phantom_set.update(phantoms) 
Example #4
Source File: selected_line.py    From sublime_debugger with MIT License 5 votes vote down vote up
def __init__(self, view: sublime.View, line: int, text: str):
		# note sublime lines are 0 based not 1 based
		pt_current_line = view.text_point(line - 1, 0)
		pt_prev_line = view.text_point(line - 2, 0)
		pt_next_line = view.text_point(line, 0)
		line_prev = view.line(pt_current_line)
		line_current = view.line(pt_prev_line)

		self.top_line = ui.Phantom(UnderlineComponent(True), view, line_current, sublime.LAYOUT_BLOCK)
		self.text = ui.Phantom(SelectedLineText(text), view, sublime.Region(pt_next_line - 1, pt_next_line - 1), sublime.LAYOUT_INLINE)
		self.bottom_line = ui.Phantom(UnderlineComponent(False), view, line_prev, sublime.LAYOUT_BLOCK) 
Example #5
Source File: changelog.py    From sublime-boxy-theme with MIT License 5 votes vote down vote up
def run(self):
        import mdpopups
        text = sublime.load_resource('Packages/Boxy Theme/CHANGELOG.md')
        view = self.window.new_file()
        view.set_name('Boxy Theme Changelog')
        view.settings().set('gutter', False)
        html = '<div class="boxy-changelog">%s</div>' % mdpopups.md2html(view,
                                                                         text)
        mdpopups.add_phantom(view, 'changelog', sublime.Region(0), html,
                             sublime.LAYOUT_INLINE, css=STYLES,
                             on_navigate=self.on_navigate)
        view.set_read_only(True)
        view.set_scratch(True) 
Example #6
Source File: go_to_tag_pair.py    From sublime-text-plugin with MIT License 5 votes vote down vote up
def show_tag_preview(view: sublime.View, pt: int, text: str, dest: int):
    "Displays given tag preview at `pt` location"
    buffer_id = view.buffer_id()
    if buffer_id not in phantoms_by_buffer:
        phantom_set = sublime.PhantomSet(view, phantom_key)
        phantoms_by_buffer[buffer_id] = phantom_set
    else:
        phantom_set = phantoms_by_buffer[buffer_id]

    r = sublime.Region(pt, pt)
    nav = lambda href: go_to_pos(view, int(href))
    phantoms = [sublime.Phantom(r, phantom_content(text, dest), sublime.LAYOUT_INLINE, on_navigate=nav)]
    phantom_set.update(phantoms) 
Example #7
Source File: tracker.py    From sublime-text-plugin with MIT License 5 votes vote down vote up
def mark(self, view: sublime.View):
        "Marks tracker in given view"
        scope = emmet.get_settings('marker_scope', 'region.accent')
        mark_opt = sublime.DRAW_SOLID_UNDERLINE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
        view.erase_regions(ABBR_REGION_ID)
        view.add_regions(ABBR_REGION_ID, [self.region], scope, '', mark_opt)
        if self.forced:
            phantoms = [sublime.Phantom(self.region, forced_indicator('⋮>'), sublime.LAYOUT_INLINE)]
            if not self.forced_indicator:
                self.forced_indicator = sublime.PhantomSet(view, ABBR_REGION_ID)
            self.forced_indicator.update(phantoms) 
Example #8
Source File: abbreviation.py    From sublime-text-plugin with MIT License 5 votes vote down vote up
def mark(editor: sublime.View, tracker: AbbreviationTracker):
    "Marks tracker in given view"
    scope = get_settings('marker_scope', 'region.accent')
    mark_opt = sublime.DRAW_SOLID_UNDERLINE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
    editor.erase_regions(ABBR_REGION_ID)
    editor.add_regions(ABBR_REGION_ID, [tracker.region], scope, '', mark_opt)
    if isinstance(tracker, AbbreviationTrackerValid) and tracker.forced:
        phantoms = [
            sublime.Phantom(tracker.region, forced_indicator('⋮>'), sublime.LAYOUT_INLINE)
        ]

        key = editor.id()
        if key not in _forced_indicator:
            _forced_indicator[key] = sublime.PhantomSet(editor, ABBR_REGION_ID)
        _forced_indicator[key].update(phantoms) 
Example #9
Source File: support.py    From ColorHelper with MIT License 5 votes vote down vote up
def run(self, page):
        """Open page."""

        try:
            import mdpopups
            has_phantom_support = (mdpopups.version() >= (1, 10, 0)) and (int(sublime.version()) >= 3124)
        except Exception:
            has_phantom_support = False

        if not has_phantom_support:
            sublime.run_command('open_file', {"file": page})
        else:
            text = sublime.load_resource(page.replace('${packages}', 'Packages'))
            view = self.window.new_file()
            view.set_name('ColorHelper - Quick Start')
            view.settings().set('gutter', False)
            view.settings().set('word_wrap', False)
            if has_phantom_support:
                mdpopups.add_phantom(
                    view,
                    'quickstart',
                    sublime.Region(0),
                    text,
                    sublime.LAYOUT_INLINE,
                    css=CSS,
                    wrapper_class="color-helper",
                    on_navigate=self.on_navigate
                )
            else:
                view.run_command('insert', {"characters": text})
            view.set_read_only(True)
            view.set_scratch(True) 
Example #10
Source File: support.py    From ColorHelper with MIT License 5 votes vote down vote up
def run(self):
        """Show the changelog in a new view."""
        try:
            import mdpopups
            has_phantom_support = (mdpopups.version() >= (1, 10, 0)) and (int(sublime.version()) >= 3124)
        except Exception:
            has_phantom_support = False

        text = sublime.load_resource('Packages/ColorHelper/CHANGES.md')
        view = self.window.new_file()
        view.set_name('ColorHelper - Changelog')
        view.settings().set('gutter', False)
        view.settings().set('word_wrap', False)
        if has_phantom_support:
            mdpopups.add_phantom(
                view,
                'changelog',
                sublime.Region(0),
                text,
                sublime.LAYOUT_INLINE,
                wrapper_class="color-helper",
                css=CSS,
                on_navigate=self.on_navigate
            )
        else:
            view.run_command('insert', {"characters": text})
        view.set_read_only(True)
        view.set_scratch(True) 
Example #11
Source File: tracker.py    From sublime-text-plugin with MIT License 4 votes vote down vote up
def show_preview(self, view: sublime.View, as_phantom=None):
        "Displays expanded preview of abbreviation in current tracker in given view"
        if not emmet.get_settings('abbreviation_preview', True):
            return

        content = None

        if as_phantom is None:
            # By default, display preview for CSS abbreviation as phantom to not
            # interfere with default autocomplete popup
            as_phantom = self.config and self.config['type'] == 'stylesheet'

        if not self.abbreviation:
            # No parsed abbreviation: empty region
            pass
        if 'error' in self.abbreviation:
            # Display error snippet
            err = self.abbreviation['error']
            snippet = html.escape( re.sub(r'\s+at\s\d+$', '', err['message']), False)
            content = '<div class="error pointer">%s</div><div class="error message">%s</div>' % (err['pointer'], snippet)
        elif self.forced or as_phantom or not self.abbreviation['simple']:
            snippet = self.abbreviation['preview']
            if self.config['type'] != 'stylesheet':
                if syntax.is_html(self.config['syntax']):
                    snippet = html_highlight.highlight(snippet)
                else:
                    snippet = html.escape(snippet, False)
                content = '<div class="markup-preview">%s</div>' % format_snippet(snippet)
            else:
                content = format_snippet(snippet)

        if not content:
            self.hide_preview(view)
            return

        if as_phantom:
            if not self._phantom_preview:
                self._phantom_preview = sublime.PhantomSet(view, ABBR_PREVIEW_ID)

            r = sublime.Region(self.region.end(), self.region.end())
            phantoms = [sublime.Phantom(r, preview_phantom_html(content), sublime.LAYOUT_INLINE)]
            self._phantom_preview.update(phantoms)
        else:
            self._has_popup_preview = True
            view.show_popup(
                preview_popup_html(content),
                flags=sublime.COOPERATE_WITH_AUTO_COMPLETE,
                location=self.region.begin(),
                max_width=400,
                max_height=300) 
Example #12
Source File: blame_all.py    From st3-gitblame with MIT License 4 votes vote down vote up
def run(self, edit):
        if not view_is_suitable(self.view):
            return

        self.view.erase_phantoms(PHANTOM_KEY_ALL)
        phantoms = []

        # If they are currently shown, toggle them off and return.
        if self.view.settings().get(SETTING_PHANTOM_ALL_DISPLAYED, False):
            self.phantom_set.update(phantoms)
            self.view.settings().set(SETTING_PHANTOM_ALL_DISPLAYED, False)
            return

        try:
            blame_output = self.get_blame(self.view.file_name())
        except Exception as e:
            communicate_error(e)
            return

        for l in blame_output.splitlines():
            parsed = self.parse_blame(l)
            if not parsed:
                continue

            sha, author, date, time, line_number = parsed

            line_point = self.get_line_point(line_number - 1)
            phantom = sublime.Phantom(
                line_point,
                blame_all_phantom_html_template.format(
                    css=blame_all_phantom_css,
                    sha=sha,
                    user=self.format_name(author),
                    date=date,
                    time=time,
                ),
                sublime.LAYOUT_INLINE,
                self.on_phantom_close,
            )
            phantoms.append(phantom)

        self.phantom_set.update(phantoms)
        self.view.settings().set(SETTING_PHANTOM_ALL_DISPLAYED, True)
        # Bring the phantoms into view without the user needing to manually scroll left.
        self.view.set_viewport_position((0.0, self.view.viewport_position()[1])) 
Example #13
Source File: terminal.py    From Terminus with MIT License 4 votes vote down vote up
def show_image(self, data, args, cr=None):
        view = self.view

        if "inline" not in args or not args["inline"]:
            return

        cursor = self.screen.cursor
        pt = view.text_point(self.offset + cursor.y, cursor.x)

        databytes = base64.decodebytes(data.encode())

        image_info = get_image_info(databytes)
        if not image_info:
            logger.error("cannot get image info")
            return

        what, width, height = image_info

        _, image_path = tempfile.mkstemp(suffix="." + what)
        with open(image_path, "wb") as f:
            f.write(databytes)

        width, height = image_resize(
            width,
            height,
            args["width"] if "width" in args else None,
            args["height"] if "height" in args else None,
            view.em_width(),
            view.viewport_extent()[0] - 3 * view.em_width(),
            args["preserveAspectRatio"] if "preserveAspectRatio" in args else 1
        )

        if self.find_image(pt):
            self.view.run_command("terminus_insert", {"point": pt, "character": " "})
            pt += 1

        self.image_count += 1
        p = view.add_phantom(
            "terminus_image#{}".format(self.image_count),
            sublime.Region(pt, pt),
            IMAGE.format(
                what=what,
                data=data,
                width=width,
                height=height,
                count=self.image_count),
            sublime.LAYOUT_INLINE,
        )
        self.images[p] = image_path

        if cr:
            self.screen.index()