Beispiel #1
0
    def fold_or_unfold_headline_at_point(self, from_point):
        """Smart folding of the current headline.

        Unfold only when it's totally folded. Otherwise fold it.

        """
        _, level = headline.headline_and_level_at_point(self.view, from_point)
        # Not a headline, cancel
        if level is None or not headline.is_scope_headline(
                self.view, from_point):
            return False

        content_region = headline.region_of_content_of_headline_at_point(
            self.view, from_point)
        # If the content is empty, Nothing needs to be done.
        if content_region is None:
            # Return True because there is a headline anyway.
            return True

        # Check if content region is folded to decide the action.
        if self.is_region_totally_folded(content_region):
            self.unfold_yet_fold_subheads(content_region, level)
        else:
            self.view.fold(
                sublime.Region(content_region.a - 1, content_region.b))
        return True
Beispiel #2
0
    def fold_or_unfold_headline_at_point(self, from_point):
        """Smart folding of the current headline.

        Unfold only when it's totally folded. Otherwise fold it.

        """
        _, level = headline.headline_and_level_at_point(self.view,
                                                        from_point)
        # Not a headline, cancel
        if level is None or not headline.is_scope_headline(self.view, from_point):
            return False

        content_region = headline.region_of_content_of_headline_at_point(self.view,
                                                                         from_point)
        # If the content is empty, Nothing needs to be done.
        if content_region is None:
            # Return True because there is a headline anyway.
            return True

        # Check if content region is folded to decide the action.
        if self.is_region_totally_folded(content_region):
            self.unfold_yet_fold_subheads(content_region, level)
        else:
            self.view.fold(sublime.Region(content_region.a - 1, content_region.b))
        return True