コード例 #1
0
    def on_hover(self, view, point, hover_zone):
        """Show popup indicating where other offscreen bracket is located."""

        settings = sublime.load_settings('bh_core.sublime-settings')
        if (
            GLOBAL_ENABLE and bh_popup.HOVER_SUPPORT and
            settings.get('show_offscreen_bracket_popup', True) and
            not view.settings().get('bracket_highlighter.ignore', False)
        ):
            # Find other bracket
            region = None
            index = None
            unmatched = False
            if hover_zone == sublime.HOVER_TEXT:
                clone_view = view.id() == view.settings().get('bracket_highlighter.clone', -1)
                locations_key = 'bracket_highlighter.clone_locations' if clone_view else 'bracket_highlighter.locations'
                locations = view.settings().get(locations_key, {})
                for k, v in locations.get('unmatched', {}).items():
                    if v[0] <= point <= v[1]:
                        unmatched = True
                        break
                if not unmatched:
                    for k, v in locations.get('open', {}).items():
                        if v[0] <= point <= v[1]:
                            index = k
                            break
                    if index is None:
                        for k, v in locations.get('close', {}).items():
                            if v[0] <= point <= v[1]:
                                index = k
                                break
                        if index is not None:
                            region = locations.get('open', {}).get(index)
                            icon = locations.get('icon', {}).get(index)
                    else:
                        region = locations.get('close', {}).get(index)
                        icon = locations.get('icon', {}).get(index)

            # Show other bracket text
            if unmatched:
                bh_popup.BhOffscreenPopup().show_unmatched_popup(view, point)
            elif region is not None:
                bh_popup.BhOffscreenPopup().show_popup(view, point, region, icon)
コード例 #2
0
    def run(self, edit, point=None, no_threshold=False):
        """Force popup."""

        # Find other bracket
        region = None
        index = None
        unmatched = False
        between = None

        # Ensure only 1 point is set
        if point is not None:
            sels = self.view.sel()
            sels.clear()
            sels.add(sublime.Region(point))

        # Search with no threshold
        if no_threshold:
            self.view.run_command("bh_key", {"lines": True})

        # Get point if not specified
        if point is None:
            sels = self.view.sel()
            if len(sels) == 1 and sels[0].size() == 0:
                point = sels[0].begin()

        # Get relative bracket regions for point
        if point is not None:
            locations = self.view.settings().get(
                'bracket_highlighter.locations', {})
            for k, v in locations.get('unmatched', {}).items():
                if v[0] <= point <= v[1]:
                    unmatched = True
                    break
            if not unmatched:
                for k, v in locations.get('open', {}).items():
                    if v[0] <= point <= v[1]:
                        index = k
                        between = None
                        break
                    elif v[0] <= point <= locations.get('close', {}).get(k)[1]:
                        between = k

                if index is None:
                    for k, v in locations.get('close', {}).items():
                        if v[0] <= point <= v[1]:
                            index = k
                            between = None
                            break
                    if index is not None:
                        region = locations.get('open', {}).get(index)
                        icon = locations.get('icon', {}).get(index)
                else:
                    region = locations.get('close', {}).get(index)
                    icon = locations.get('icon', {}).get(index)

            if between:
                region = locations.get('open', {}).get(between)
                region2 = locations.get('close', {}).get(between)
                icon = locations.get('icon', {}).get(between)
                bh_popup.BhOffscreenPopup().show_popup_between(
                    self.view, point, region, region2, icon)
            elif region is not None:
                bh_popup.BhOffscreenPopup().show_popup(self.view, point,
                                                       region, icon)
            elif not no_threshold:
                bh_popup.BhOffscreenPopup().show_unmatched_popup(
                    self.view, point)