Exemplo n.º 1
0
def next_paragraph_start(view, pt, count=1, skip_empty=True):
    if row_at(view, pt) == last_row(view):
        if not view.line(view.size()).empty():
            return view.size() - 1

        return view.size()

    # skip empty rows before moving for the first time
    current_row = row_at(view, pt)
    if (view.line(view.text_point(current_row + 1, 0)).empty()
            and view.line(pt).empty()):
        pt, _ = _next_non_empty_row(view, pt)

    for i in range(count):
        pt, eof = _next_empty_row(view, pt)
        if eof:
            if view.line(pt).empty():
                return pt

            return pt - 1

        if skip_empty and (i != (count - 1)):
            pt, eof = _next_non_empty_row(view, pt)
            if eof:
                if not view.line(pt).empty():
                    return pt - 1

                return pt

    return pt
Exemplo n.º 2
0
def _next_non_empty_row(view, pt):
    r = row_at(view, pt)
    while True:
        r += 1
        reg = view.line(view.text_point(r, 0))
        if r >= last_row(view):
            return view.size(), True

        if not reg.empty():
            return reg.a, False
Exemplo n.º 3
0
def _next_empty_row(view, pt):
    r = row_at(view, pt)
    while True:
        r += 1
        pt = view.text_point(r, 0)
        if row_at(view, pt) == last_row(view):
            return view.size(), True

        if view.line(pt).empty():
            return pt, False
Exemplo n.º 4
0
def lines(view, s, count=1):
    """
    Return a region spanning @count full lines.

    Assumes we're operating in INTERNAL_NORMAL mode.

    @view
      Target view.
    @s
      Selection in @view taken as starting point.
    @count
      Number of lines to include in returned region.
    """
    # assumes INTERNAL_NORMAL mode.
    a = view.line(s.b).a
    b = view.text_point(row_at(view, s.b) + (count - 1), 0)
    # make sure we remove the last line if needed
    if ((row_at(view, b) == last_row(view)) and (view.substr(a - 1) == '\n')):
        a -= 1

    return Region(a, view.full_line(b).b)