def run(self, edit, offset=-1):
        vid = self.view.id()
        HeaderChangeLevelEvent.listen.pop(vid, None)

        cursor_pos = self.view.sel()[0].begin()
        region = sublime.Region(0, self.view.size())
        tree = RstHeaderTree(self.view.substr(region))

        parent = tree.belong_to(cursor_pos)

        is_in_header = parent.start <= cursor_pos <= parent.end
        if not is_in_header:
            return

        idx, levels = HeaderChangeLevelCommand.views.get(vid, (None, None))
        if idx != parent.idx:
            levels = tree.levels()
            HeaderChangeLevelCommand.views[vid] = (parent.idx, levels)

        try:
            level = levels.index(parent.adornment)
            if level + offset < 0:
                return
            adornment = levels[level + offset]
        except __HOLE__:
            return

        new_header = RstHeaderTree.make_header(parent.title, adornment)
        hregion = sublime.Region(parent.start, parent.end + 1)

        try:
            self.view.replace(edit, hregion, new_header)
        finally:
            def callback():
                HeaderChangeLevelEvent.listen[vid] = True
            sublime.set_timeout(callback, 0)
dataset/ETHPy150Open mgaitan/sublime-rst-completion/headers.py/HeaderChangeLevelCommand.run