Example #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
Example #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
Example #3
0
    def run(self, edit, forward=True, same_level=True):
        """Move between headlines, forward or backward.

        If same_level is true, only move to headline with the same level
        or higher level.

        """
        new_sel = []
        if same_level:
            level_type = headline.MATCH_PARENT
        else:
            level_type = headline.MATCH_ANY

        for region in self.view.sel():
            if same_level:
                _, level = headline.headline_and_level_at_point(self.view, region.a, search_above_and_down=True)
            else:
                level = headline.ANY_LEVEL

            match_region, _ = headline.find_headline(
                self.view, region.a, level, forward, level_type, skip_headline_at_point=True, skip_folded=True
            )
            if forward:
                if not match_region:
                    size = self.view.size()
                    match_region = sublime.Region(size, size)
            else:
                if not match_region:
                    match_region = sublime.Region(0, 0)
            new_sel.append(sublime.Region(match_region.a, match_region.a))

        self.adjust_view(new_sel)
    def run(self, edit, forward=True, same_level=True):
        """Move between headlines, forward or backward.

        If same_level is true, only move to headline with the same level
        or higher level.

        """
        new_sel = []
        if same_level:
            level_type = headline.MATCH_PARENT
        else:
            level_type = headline.MATCH_ANY

        for region in self.view.sel():
            if same_level:
                _, level = headline.headline_and_level_at_point(self.view,\
                                                                region.a,
                                                                search_above_and_down=True)
            else:
                level = headline.ANY_LEVEL

            match_region, _ = headline.find_headline(self.view, \
                                                     region.a, \
                                                     level, \
                                                     forward, \
                                                     level_type, \
                                                     skip_headline_at_point=True,\
                                                     skip_folded=True)
            if forward:
                if not match_region:
                    size = self.view.size()
                    match_region = sublime.Region(size, size)
            else:
                if not match_region:
                    match_region = sublime.Region(0, 0)
            new_sel.append(sublime.Region(match_region.a, match_region.a))

        self.adjust_view(new_sel)
Example #5
0
    def run(self, edit, forward=True, same_level=True):
        """Move between headlines, forward or backward.

        If same_level is true, only move to headline with the same level
        or higher level.

        """
        new_sel = []
        if same_level:
            level_type = headline.MATCH_PARENT
        else:
            level_type = headline.MATCH_ANY

        for region in self.view.sel():
            if same_level:
                _, level = headline.headline_and_level_at_point(self.view,\
                                                                region.a,
                                                                search_above_and_down=True)
                if level is None:
                    return
            else:
                level = headline.ANY_LEVEL

            match_region, _ = headline.find_headline(self.view, \
                                                     region.a, \
                                                     level, \
                                                     forward, \
                                                     level_type, \
                                                     skip_headline_at_point=True,\
                                                     skip_folded=True)

            if is_region_void(match_region):
                return
            new_sel.append(sublime.Region(match_region.a, match_region.a))

        self.adjust_view(new_sel)